1 | ##parameters=REQUEST |
---|
2 | # $Id: add_student.py 2538 2007-11-05 16:19:18Z joachim $ |
---|
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 |
---|
15 | logger = logging.getLogger('Skins.add_student') |
---|
16 | |
---|
17 | if mtool.isAnonymousUser() or not context.isSectionOfficer(): |
---|
18 | return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
19 | |
---|
20 | validate = REQUEST.has_key("cpsdocument_edit_button") and\ |
---|
21 | REQUEST.get("cpsdocument_edit_button").startswith('Add') |
---|
22 | d = {} |
---|
23 | mode = 'edit' |
---|
24 | rendered,psm,ds = lt.renderLayout(layout_id= 'add_student', |
---|
25 | schema_id= 'add_student', |
---|
26 | context=context, |
---|
27 | mapping=validate and REQUEST, |
---|
28 | ob=d, |
---|
29 | layout_mode=mode, |
---|
30 | commit = False |
---|
31 | ) |
---|
32 | if psm == 'invalid': |
---|
33 | psm = "Please correct your input." |
---|
34 | return context.add_student_form(rendered = rendered, |
---|
35 | psm = psm, |
---|
36 | #psm = "%s, %s" % (psm,ds), |
---|
37 | mode = mode, |
---|
38 | formaction = "add_student", |
---|
39 | button = "Add", |
---|
40 | ds = ds, |
---|
41 | ) |
---|
42 | elif psm == '': |
---|
43 | return context.add_student_form(rendered = rendered, |
---|
44 | psm = psm, |
---|
45 | mode = mode, |
---|
46 | formaction = "add_student", |
---|
47 | button = "Add", |
---|
48 | ds = ds, |
---|
49 | ) |
---|
50 | elif psm == 'valid': |
---|
51 | pass |
---|
52 | matric_no = ds.get('matric_no') |
---|
53 | if matric_no: |
---|
54 | res = context.students_catalog(matric_no = matric_no) |
---|
55 | if res: |
---|
56 | psm = "Student with matric_no %s exists with Id: %s" % (matric_no,res[0].id) |
---|
57 | return context.add_student_form(rendered = rendered, |
---|
58 | psm = psm, |
---|
59 | #psm = "%s, %s" % (psm,ds), |
---|
60 | mode = mode, |
---|
61 | formaction = "add_student", |
---|
62 | button = "Add", |
---|
63 | ds = ds, |
---|
64 | ) |
---|
65 | dict = {} |
---|
66 | dict.update(ds) |
---|
67 | sid,password = context.waeup_tool.addStudent(dict) |
---|
68 | dict['sid'] = sid |
---|
69 | dict['password'] = password |
---|
70 | student_rec = context.getFormattedStudentEntry(context.students_catalog(id = sid)[0]) |
---|
71 | psm = "Student record with Id %s and Password %s has been created." % (sid,password) |
---|
72 | logger.info('%s created student %s' % (member,sid)) |
---|
73 | return context.add_student_form(rendered = rendered, |
---|
74 | mode = 'view', |
---|
75 | psm = psm, |
---|
76 | ds = dict, |
---|
77 | student = student_rec, |
---|
78 | ) |
---|
79 | |
---|
80 | |
---|