D├ęsactivation d'options obsol├Ętes.
[photoprint.git] / skins / customer_add_control.py
1 ##parameters=**kw
2 from Products.CMFCore.utils import getToolByName
3 from Products.photoprint.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 ]
29
30 for name, failMessage in mandatoryFields :
31 value = kg(name)
32 if not value :
33 return context.setStatus(False, failMessage)
34
35
36 try:
37 rtool.addMember( id=kg('member_id'),
38 password=kg('password'),
39 properties={'username' : kg('member_id')
40 ,'given_name' : kg('given_name')
41 ,'name' : kg('name')
42 ,'email' : kg('member_email')
43 ,'billing_address' : kg('billing_address')
44 ,'billing_city' : kg('billing_city')
45 ,'billing_zipcode' : kg('billing_zipcode')
46 ,'country' : kg('country')
47 ,'phone' : kg('phone')} )
48 except ValueError, errmsg:
49 return context.setStatus(False, _(errmsg))
50
51
52 if kg('send_password') or ptool.getProperty('validate_email') :
53 rtool.registeredNotify(kg('member_id'))
54
55 return context.setStatus(True, 'Success!')