1 | ##parameters=REQUEST,matric_no=None |
---|
2 | # $Id: set_access_data.py 1794 2007-05-17 16:40:34Z henrik $ |
---|
3 | """ |
---|
4 | process the Application Form |
---|
5 | return html renderer + psm |
---|
6 | """ |
---|
7 | import DateTime,logging |
---|
8 | current = DateTime.DateTime() |
---|
9 | pr = context.portal_registration |
---|
10 | logger = logging.getLogger('Skins.set_access_data') |
---|
11 | validate = REQUEST.has_key("cpsdocument_edit_button") |
---|
12 | |
---|
13 | if matric_no is None: |
---|
14 | logger.info('No matric_no in request') |
---|
15 | return REQUEST.RESPONSE.redirect("%s" % context.portal_url()) |
---|
16 | lt = context.portal_layouts |
---|
17 | #pr = context.portal_registration |
---|
18 | default = {'matric_no':matric_no} |
---|
19 | st_res = context.students_catalog(matric_no = matric_no) |
---|
20 | if st_res: |
---|
21 | sid = st_res[0].id |
---|
22 | else: |
---|
23 | st_res = context.returning_import(matric_no = matric_no) |
---|
24 | if st_res: |
---|
25 | sid = st_res[0].id |
---|
26 | logger.info('Student object with matric_no %s does not exist in students_catalog. Id taken from returning_import.' % matric_no) |
---|
27 | else: |
---|
28 | logger.info('Student object with matric_no %s neither exists in students_catalog nor in returning_import.' % matric_no) |
---|
29 | return |
---|
30 | res,psm,ds = lt.renderLayout(layout_id= 'student_session_results_search', |
---|
31 | schema_id= 'student_returning', |
---|
32 | context=context, |
---|
33 | mapping=validate and REQUEST, |
---|
34 | ob=default, |
---|
35 | layout_mode='edit', |
---|
36 | formaction = "set_access_data", |
---|
37 | button = "Search", |
---|
38 | matric_no = matric_no, |
---|
39 | commit = False, |
---|
40 | ) |
---|
41 | if psm == '': |
---|
42 | return context.set_access_data_form(rendered = res, |
---|
43 | psm = None, |
---|
44 | firstlayout = True, |
---|
45 | lastlayout = True, |
---|
46 | ds = ds, |
---|
47 | name = "%(name)s" % REQUEST.form |
---|
48 | ) |
---|
49 | elif psm == 'invalid': |
---|
50 | psm = "Please correct your input!" |
---|
51 | elif psm == 'valid' and not REQUEST.form.has_key('acknowledge'): |
---|
52 | psm = "You did not check the ackkowledge box!" |
---|
53 | else: |
---|
54 | password = REQUEST.get('widget__password') |
---|
55 | try: |
---|
56 | context.waeup_tool.makeStudentMember(sid,password=password) |
---|
57 | psm = '' |
---|
58 | except KeyError: |
---|
59 | #psm = "You are already registered please log in with your UserId %s" % sid |
---|
60 | psm = "" |
---|
61 | logger.info('%s repeatedly tried to set password' % sid) |
---|
62 | except: |
---|
63 | psm = "The system encountered an error. Please try again." |
---|
64 | logger.info('%s, makeStudentMember error, password = %s' % (sid,password)) |
---|
65 | if psm != '': |
---|
66 | return context.set_access_data_form(rendered = res, |
---|
67 | #psm = "%s, %s" % (psm,ds), |
---|
68 | psm = psm, |
---|
69 | firstlayout = True, |
---|
70 | lastlayout = True, |
---|
71 | ds = ds, |
---|
72 | name = "%(name)s" % REQUEST.form |
---|
73 | ) |
---|
74 | email = ds.get('email') |
---|
75 | args = {} |
---|
76 | args['__ac_name'] = sid |
---|
77 | args['__ac_password'] = password |
---|
78 | args['returning'] = '1' |
---|
79 | args['email'] = email |
---|
80 | args['phone_nr'] = ds.get('phone_nr') |
---|
81 | from urllib import urlencode |
---|
82 | url = "%s/logged_in?%s" % (context.absolute_url(),urlencode(args)) |
---|
83 | return REQUEST.RESPONSE.redirect(url) |
---|