Mise à jour fonction utilitaire « translate ».
[photoprint.git] / skins / customer_add_control.py
1 ##parameters=**kw
2 from Products.CMFCore.utils import getToolByName
3 from Products.realis.utils import translate
4 from Products.CMFDefault.utils import translate as cmf_translate
5 rtool = getToolByName(context, 'portal_registration')
6 ptool = getToolByName(context, 'portal_properties')
7 _ = lambda msg : translate(msg, context)
8
9 kg = lambda name : kw.get(name, '').strip()
10
11 cmfprops = {'username' : kg('member_id')
12 ,'email' : kg('member_email')}
13
14 failMessage = rtool.testPropertiesValidity(cmfprops)
15 if failMessage is not None :
16 return context.setStatus(False, cmf_translate(failMessage, context))
17
18 mandatoryFields = [
19 ('given_name', _('Please enter a given name.'))
20 , ('name', _('Please enter a name.'))
21 , ('member_email', _('Please enter an email.'))
22 , ('member_id', _('Please enter a member id.'))
23 , ('billing_address', _('Please enter a billing address.'))
24 , ('billing_city', _('Please enter a city.'))
25 , ('billing_zipcode', _('Please enter zip code.'))
26 , ('country', _('Please enter a country.'))
27 , ('phone', _('Please enter a phone.'))
28 , ('accept_gcs', _('Please accept general conditions of sales.'))
29 ]
30
31 for name, failMessage in mandatoryFields :
32 value = kg(name)
33 if not value :
34 return context.setStatus(False, failMessage)
35
36
37 try:
38 rtool.addMember( id=kg('member_id'),
39 password=kg('password'),
40 properties={'username' : kg('member_id')
41 ,'given_name' : kg('given_name')
42 ,'name' : kg('name')
43 ,'email' : kg('member_email')
44 ,'billing_address' : kg('billing_address')
45 ,'billing_city' : kg('billing_city')
46 ,'billing_zipcode' : kg('billing_zipcode')
47 ,'country' : kg('country')
48 ,'phone' : kg('phone')
49 ,'accept_gcs' : kg('accep_gcs')} )
50 except ValueError, errmsg:
51 return context.setStatus(False, _(errmsg))
52
53
54 if kg('send_password') or ptool.getProperty('validate_email') :
55 rtool.registeredNotify(kg('member_id'))
56
57 return context.setStatus(True, 'Success!')