[1415] | 1 | ##parameters=REQUEST |
---|
| 2 | # $Id: add_student.py 2503 2007-11-02 18:16:19Z henrik $ |
---|
| 3 | """ |
---|
| 4 | process the the accommodation reservation |
---|
| 5 | """ |
---|
| 6 | import DateTime |
---|
| 7 | current = DateTime.DateTime() |
---|
| 8 | pr = context.portal_registration |
---|
| 9 | wftool = context.portal_workflow |
---|
| 10 | lt = context.portal_layouts |
---|
| 11 | mtool = context.portal_membership |
---|
| 12 | member = mtool.getAuthenticatedMember() |
---|
| 13 | acco_cat = context.portal_accommodation |
---|
| 14 | import logging |
---|
[1571] | 15 | logger = logging.getLogger('Skins.add_student') |
---|
[1415] | 16 | |
---|
| 17 | validate = REQUEST.has_key("cpsdocument_edit_button") and\ |
---|
[1421] | 18 | REQUEST.get("cpsdocument_edit_button").startswith('Add') |
---|
[1415] | 19 | d = {} |
---|
| 20 | mode = 'edit' |
---|
[2503] | 21 | rendered,psm,ds = lt.renderLayout(layout_id= 'add_student', |
---|
| 22 | schema_id= 'add_student', |
---|
[1415] | 23 | context=context, |
---|
| 24 | mapping=validate and REQUEST, |
---|
| 25 | ob=d, |
---|
| 26 | layout_mode=mode, |
---|
| 27 | commit = False |
---|
| 28 | ) |
---|
| 29 | if psm == 'invalid': |
---|
| 30 | psm = "Please correct your input." |
---|
| 31 | return context.add_student_form(rendered = rendered, |
---|
| 32 | psm = psm, |
---|
| 33 | #psm = "%s, %s" % (psm,ds), |
---|
| 34 | mode = mode, |
---|
| 35 | formaction = "add_student", |
---|
[1420] | 36 | button = "Add", |
---|
[1415] | 37 | ds = ds, |
---|
| 38 | ) |
---|
| 39 | elif psm == '': |
---|
| 40 | return context.add_student_form(rendered = rendered, |
---|
| 41 | psm = psm, |
---|
| 42 | mode = mode, |
---|
| 43 | formaction = "add_student", |
---|
[1420] | 44 | button = "Add", |
---|
[1415] | 45 | ds = ds, |
---|
| 46 | ) |
---|
| 47 | elif psm == 'valid': |
---|
| 48 | pass |
---|
[1416] | 49 | matric_no = ds.get('matric_no') |
---|
[1419] | 50 | if matric_no: |
---|
| 51 | res = context.students_catalog(matric_no = matric_no) |
---|
| 52 | if res: |
---|
| 53 | psm = "Student with matric_no %s exists with Id: %s" % (matric_no,res[0].id) |
---|
| 54 | return context.add_student_form(rendered = rendered, |
---|
[1416] | 55 | psm = psm, |
---|
| 56 | #psm = "%s, %s" % (psm,ds), |
---|
| 57 | mode = mode, |
---|
| 58 | formaction = "add_student", |
---|
[1420] | 59 | button = "Add", |
---|
[1416] | 60 | ds = ds, |
---|
| 61 | ) |
---|
[1415] | 62 | dict = {} |
---|
| 63 | dict.update(ds) |
---|
[1752] | 64 | sid,password = context.waeup_tool.addStudent(dict) |
---|
[1415] | 65 | dict['sid'] = sid |
---|
| 66 | dict['password'] = password |
---|
| 67 | student_rec = context.getFormattedStudentEntry(context.students_catalog(id = sid)[0]) |
---|
[1422] | 68 | psm = "Student record with Id %s and Password %s has been created." % (sid,password) |
---|
[1571] | 69 | logger.info('%s created student %s' % (member,sid)) |
---|
[1415] | 70 | return context.add_student_form(rendered = rendered, |
---|
| 71 | mode = 'view', |
---|
| 72 | psm = psm, |
---|
| 73 | ds = dict, |
---|
| 74 | student = student_rec, |
---|
| 75 | ) |
---|
| 76 | |
---|
| 77 | |
---|