Changeset 11814
- Timestamp:
- 24 Sep 2014, 13:26:30 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/utils/utils.py
r11804 r11814 29 29 from waeup.kofa.utils.helpers import get_sorted_preferred 30 30 31 def send_mail(from_name,from_addr,rcpt_name,rcpt_addr,subject,body,config): 31 32 def send_mail(from_name, from_addr, 33 rcpt_name, rcpt_addr, 34 subject, body, config): 32 35 """Wrapper for the real SMTP functionality in :mod:`waeup.kofa.smtp`. 33 36 … … 39 42 return True 40 43 44 41 45 #: A list of phone prefixes (order num, country, prefix). 42 46 #: Items with same order num will be sorted alphabetically. … … 44 48 INT_PHONE_PREFIXES = [ 45 49 (99, _('Germany'), '49'), 46 ( 50 (1, _('Nigeria'), '234'), 47 51 (99, _('U.S.'), '1'), 48 52 ] 49 53 50 def sorted_phone_prefixes(data = INT_PHONE_PREFIXES, request=None): 54 55 def sorted_phone_prefixes(data=INT_PHONE_PREFIXES, request=None): 51 56 """Sorted tuples of phone prefixes. 52 57 … … 67 72 for x, y, z in data] 68 73 return tuple([ 69 ('%s (+%s)' % (x[1], x[2]), '+%s' % x[2])74 ('%s (+%s)' % (x[1], x[2]), '+%s' % x[2]) 70 75 for x in sorted(data) 71 76 ]) 77 72 78 73 79 class KofaUtils(grok.GlobalUtility): … … 82 88 83 89 PREFERRED_LANGUAGES_DICT = { 84 'en': (1, u'English'),85 'fr': (2, u'Français'),86 'de': (3, u'Deutsch'),87 'ha': (4, u'Hausa'),88 'yo': (5, u'Yoruba'),89 'ig': (6, u'Igbo'),90 'en': (1, u'English'), 91 'fr': (2, u'Français'), 92 'de': (3, u'Deutsch'), 93 'ha': (4, u'Hausa'), 94 'yo': (5, u'Yoruba'), 95 'ig': (6, u'Igbo'), 90 96 } 91 97 … … 179 185 180 186 MODE_GROUPS = { 181 'All': ('all',),182 'Undergraduate Full-Time': ('ug_ft',),183 'Undergraduate Part-Time': ('ug_pt',),184 'Postgraduate Full-Time': ('pg_ft',),185 'Postgraduate Part-Time': ('pg_pt',),187 'All': ('all',), 188 'Undergraduate Full-Time': ('ug_ft',), 189 'Undergraduate Part-Time': ('ug_pt',), 190 'Postgraduate Full-Time': ('pg_ft',), 191 'Postgraduate Part-Time': ('pg_pt',), 186 192 } 187 193 … … 200 206 } 201 207 202 def sendContactForm(self, from_name,from_addr,rcpt_name,rcpt_addr,203 from_username,usertype,portal,body,subject):208 def sendContactForm(self, from_name, from_addr, rcpt_name, rcpt_addr, 209 from_username, usertype, portal, body, subject): 204 210 """Send an email with data provided by forms. 205 211 """ … … 212 218 ${e} 213 219 """) 214 text = _(text, 215 mapping = { 216 'a':from_name, 217 'b':from_username, 218 'c':usertype, 219 'd':portal, 220 'e':body}) 220 text = _(text, mapping={ 221 'a': from_name, 222 'b': from_username, 223 'c': usertype, 224 'd': portal, 225 'e': body}) 221 226 body = translate(text, 'waeup.kofa', 222 227 target_language=self.PORTAL_LANGUAGE) … … 224 229 return False 225 230 return send_mail( 226 from_name,from_addr,rcpt_name,rcpt_addr,subject,body,config) 231 from_name, from_addr, rcpt_name, rcpt_addr, 232 subject, body, config) 227 233 228 234 @property … … 232 238 return pytz.utc 233 239 234 def fullname(self, firstname,lastname,middlename=None):240 def fullname(self, firstname, lastname, middlename=None): 235 241 """Full name constructor. 236 242 """ … … 240 246 else: 241 247 name = '%s %s' % (firstname, lastname) 242 return string.capwords( name.replace('-',' - ')).replace(' - ','-')243 248 return string.capwords( 249 name.replace('-', ' - ')).replace(' - ', '-') 244 250 245 251 def genPassword(self, length=8, chars=string.letters + string.digits): … … 247 253 """ 248 254 return ''.join([r().choice(chars) for i in range(length)]) 249 250 255 251 256 def sendCredentials(self, user, password=None, url_info=None, msg=None): … … 280 285 rcpt_name = user.title 281 286 rcpt_addr = user.email 282 text = _(text, 283 mapping = { 284 'a':rcpt_name, 285 'b':msg, 286 'c':config.name, 287 'd':user.name, 288 'e':password, 289 'f':url_info}) 287 text = _(text, mapping={ 288 'a': rcpt_name, 289 'b': msg, 290 'c': config.name, 291 'd': user.name, 292 'e': password, 293 'f': url_info}) 290 294 291 295 body = translate(text, 'waeup.kofa', 292 296 target_language=self.PORTAL_LANGUAGE) 293 297 return send_mail( 294 from_name,from_addr,rcpt_name,rcpt_addr,subject,body,config) 298 from_name, from_addr, rcpt_name, rcpt_addr, 299 subject, body, config) 295 300 296 301 def getPaymentItem(self, payment):
Note: See TracChangeset for help on using the changeset viewer.