[1207] | 1 | ##parameters=REQUEST,matric_no=None |
---|
[1179] | 2 | # $Id: set_access_data.py 1582 2007-03-19 10:58:13Z 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 |
---|
[1571] | 10 | logger = logging.getLogger('Skins.set_access_data') |
---|
[1179] | 11 | validate = REQUEST.has_key("cpsdocument_edit_button") |
---|
| 12 | |
---|
[1207] | 13 | if matric_no is None: |
---|
[1582] | 14 | logger.info('No matric_no in request') |
---|
[1207] | 15 | return REQUEST.RESPONSE.redirect("%s" % context.portal_url()) |
---|
[1179] | 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: |
---|
[1571] | 23 | logger.info('Student object with matric_no does not exist' % matric_no) |
---|
[1179] | 24 | res,psm,ds = lt.renderLayout(layout_id= 'student_session_results_search', |
---|
| 25 | schema_id= 'student_returning', |
---|
| 26 | context=context, |
---|
| 27 | mapping=validate and REQUEST, |
---|
| 28 | ob=default, |
---|
| 29 | layout_mode='edit', |
---|
| 30 | formaction = "set_access_data", |
---|
| 31 | button = "Search", |
---|
| 32 | matric_no = matric_no, |
---|
| 33 | commit = False, |
---|
| 34 | ) |
---|
| 35 | if psm == '': |
---|
| 36 | return context.set_access_data_form(rendered = res, |
---|
| 37 | psm = None, |
---|
| 38 | firstlayout = True, |
---|
| 39 | lastlayout = True, |
---|
| 40 | ds = ds, |
---|
| 41 | name = "%(name)s" % REQUEST.form |
---|
| 42 | ) |
---|
| 43 | elif psm == 'invalid': |
---|
| 44 | psm = "Please correct your input!" |
---|
| 45 | elif psm == 'valid' and not REQUEST.form.has_key('acknowledge'): |
---|
| 46 | psm = "You did not check the ackkowledge box!" |
---|
| 47 | else: |
---|
[1207] | 48 | password = REQUEST.get('widget__password') |
---|
[1202] | 49 | try: |
---|
| 50 | context.waeup_tool.makeStudentMember(sid,password=password) |
---|
| 51 | psm = '' |
---|
| 52 | except KeyError: |
---|
[1215] | 53 | #psm = "You are already registered please log in with your UserId %s" % sid |
---|
| 54 | psm = "" |
---|
[1571] | 55 | logger.info('%s repeatedly tried to set password' % sid) |
---|
[1265] | 56 | except: |
---|
[1267] | 57 | psm = "The system encountered an error. Please try again." |
---|
[1571] | 58 | logger.info('%s, makeStudentMember error, password = %s' % (sid,password)) |
---|
[1179] | 59 | if psm != '': |
---|
| 60 | return context.set_access_data_form(rendered = res, |
---|
| 61 | #psm = "%s, %s" % (psm,ds), |
---|
| 62 | psm = psm, |
---|
| 63 | firstlayout = True, |
---|
| 64 | lastlayout = True, |
---|
| 65 | ds = ds, |
---|
| 66 | name = "%(name)s" % REQUEST.form |
---|
| 67 | ) |
---|
| 68 | email = ds.get('email') |
---|
| 69 | args = {} |
---|
| 70 | args['__ac_name'] = sid |
---|
| 71 | args['__ac_password'] = password |
---|
| 72 | args['returning'] = '1' |
---|
| 73 | args['email'] = email |
---|
| 74 | args['phone_nr'] = ds.get('phone_nr') |
---|
| 75 | from urllib import urlencode |
---|
| 76 | url = "%s/logged_in?%s" % (context.absolute_url(),urlencode(args)) |
---|
| 77 | return REQUEST.RESPONSE.redirect(url) |
---|