comparison pages/association/membership/page_meta.py @ 6:9ce41ef66dfa

python 3 port
author Goffi <goffi@goffi.org>
date Sat, 05 Oct 2019 01:26:51 +0200
parents 09d66acc7c73
children 67487063f421
comparison
equal deleted inserted replaced
5:9ab2f5b872c7 6:9ce41ef66dfa
10 from sat.core import exceptions 10 from sat.core import exceptions
11 from sat.core.log import getLogger 11 from sat.core.log import getLogger
12 12
13 log = getLogger(__name__) 13 log = getLogger(__name__)
14 14
15 name = u"association_membership" 15 name = "association_membership"
16 template = u"association/membership.html" 16 template = "association/membership.html"
17 17
18 FIELDS = ( 18 FIELDS = (
19 'name', 19 'name',
20 'firstname', 20 'firstname',
21 'address', 21 'address',
28 'documents_read', 28 'documents_read',
29 ) 29 )
30 REQUIRED = ('name', 'firstname', 'address', 'email', 'subscription') 30 REQUIRED = ('name', 'firstname', 'address', 'email', 'subscription')
31 FormData = namedtuple("FormData", FIELDS) 31 FormData = namedtuple("FormData", FIELDS)
32 32
33 SUBJECT_ADMIN = D_(u"New subscription to the association") 33 SUBJECT_ADMIN = D_("New subscription to the association")
34 BODY_ADMIN = D_(u"""\ 34 BODY_ADMIN = D_("""\
35 New subscription received: 35 New subscription received:
36 36
37 {fields_list}""").format( 37 {fields_list}""").format(
38 fields_list=u"\n".join(u"- {0}: {{{0}}}".format(f) for f in FIELDS) 38 fields_list="\n".join("- {0}: {{{0}}}".format(f) for f in FIELDS)
39 ) 39 )
40 40
41 SUBJECT = D_(u"Your association membership request") 41 SUBJECT = D_("Your association membership request")
42 BODY = D_(u"""\ 42 BODY = D_("""\
43 Hello {firstname}, 43 Hello {firstname},
44 44
45 you request to join the "Salut à Toi" association has been well received. 45 you request to join the "Salut à Toi" association has been well received.
46 Thank you and welcome to the SàT community. 46 Thank you and welcome to the SàT community.
47 47
48 You can contact us at contact""" 48 You can contact us at contact"""
49 # we split the address to avoid 49 # we split the address to avoid
50 # it being recognized too easily by spam bots 50 # it being recognized too easily by spam bots
51 + u'@' + u'salut-a-toi' + u'.org' 51 + '@' + 'salut-a-toi' + '.org'
52 u""" 52 """
53 or on the official XMPP chat room: 53 or on the official XMPP chat room:
54 xmpp: sat@chat.jabberfr.org 54 xmpp: sat@chat.jabberfr.org
55 web: https://chat.jabberfr.org/converse.js/sat@chat.jabberfr.org 55 web: https://chat.jabberfr.org/converse.js/sat@chat.jabberfr.org
56 56
57 The Salut à Toi team 57 The Salut à Toi team
58 """) 58 """)
59 59
60 WARNING_MSG_NOT_READ = D_( 60 WARNING_MSG_NOT_READ = D_(
61 u"You must have read the documents to validate your membership request") 61 "You must have read the documents to validate your membership request")
62 WARNING_MSG_MISSING_FIELDS = D_( 62 WARNING_MSG_MISSING_FIELDS = D_(
63 u"The form you posted is not complete, we can't validate this membership request.\n" 63 "The form you posted is not complete, we can't validate this membership request.\n"
64 u"Please fill all the required fields, thank you!") 64 "Please fill all the required fields, thank you!")
65 65
66 @defer.inlineCallbacks 66 @defer.inlineCallbacks
67 def on_data_post(self, request): 67 def on_data_post(self, request):
68 data = FormData(*self.getPostedData(request, FIELDS, raise_on_missing=False)) 68 data = FormData(*self.getPostedData(request, FIELDS, raise_on_missing=False))
69 if any(not getattr(data, f) for f in REQUIRED): 69 if any(not getattr(data, f) for f in REQUIRED):
70 log.warning(u"missing data fields:\n{data}".format(data=data)) 70 log.warning("missing data fields:\n{data}".format(data=data))
71 raise exceptions.DataError(WARNING_MSG_MISSING_FIELDS) 71 raise exceptions.DataError(WARNING_MSG_MISSING_FIELDS)
72 if not C.bool(data.documents_read or C.BOOL_FALSE): 72 if not C.bool(data.documents_read or C.BOOL_FALSE):
73 log.warning(u"documents_read has not been checked:\n{data}".format(data=data)) 73 log.warning("documents_read has not been checked:\n{data}".format(data=data))
74 raise exceptions.DataError(WARNING_MSG_NOT_READ) 74 raise exceptions.DataError(WARNING_MSG_NOT_READ)
75 addresses = config.getConfig( 75 addresses = config.getConfig(
76 self.host.main_conf, 76 self.host.main_conf,
77 None, 77 None,
78 "email_admins_list", 78 "email_admins_list",