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