1 | ##parameters=REQUEST=None |
---|
2 | # $Id: create_jamb.py 57 2005-10-19 09:42:03Z joachim $ |
---|
3 | """ |
---|
4 | Create an the Jamb-Record for a Student |
---|
5 | |
---|
6 | """ |
---|
7 | |
---|
8 | type_name = 'Jamb' |
---|
9 | ti = context.portal_types[type_name] |
---|
10 | pr = context.portal_registration |
---|
11 | pm = context.portal_membership |
---|
12 | |
---|
13 | REQUEST.set('type_name',type_name) |
---|
14 | |
---|
15 | validate = REQUEST.has_key("cpsdocument_edit_button") |
---|
16 | |
---|
17 | lt = context.portal_layouts |
---|
18 | |
---|
19 | res,psm,ds = lt.renderLayout(layout_id= 'jambcreate', |
---|
20 | schema_id= 'jamb', |
---|
21 | context=context, |
---|
22 | mapping=validate and REQUEST, |
---|
23 | ob={}, |
---|
24 | layout_mode='create', |
---|
25 | ) |
---|
26 | if psm == 'invalid' or psm == '': |
---|
27 | return context.create_jamb_form(rendered = res, |
---|
28 | psm = 'Please correct your errors', |
---|
29 | ds = ds, |
---|
30 | ) |
---|
31 | elif psm == '': |
---|
32 | return context.create_jamb_form(rendered = res, |
---|
33 | psm = psm, |
---|
34 | ds = ds, |
---|
35 | ) |
---|
36 | |
---|
37 | elif psm == 'valid': |
---|
38 | s_id = "s%s" % ds.get('reg_nr') |
---|
39 | name = ds.get('name') |
---|
40 | skw = {'title': name} |
---|
41 | context.invokeFactory('Student',s_id) |
---|
42 | student = getattr(context,s_id) |
---|
43 | student.edit(mapping=skw) |
---|
44 | context.notifyCPSDocumentCreation(ob=student) |
---|
45 | jamb_id = 'JAMB' |
---|
46 | student.invokeFactory('Jamb',jamb_id) |
---|
47 | jamb = getattr(student,jamb_id) |
---|
48 | ds.set('title', name) |
---|
49 | jamb.edit(mapping=ds) |
---|
50 | context.notifyCPSDocumentCreation(ob=jamb) |
---|
51 | psm = 'Student created' |
---|
52 | noCPSMember = False |
---|
53 | try: |
---|
54 | pr.addMember(s_id, 'UnSeT',roles=('Member','CPSMember')) |
---|
55 | except: |
---|
56 | noCPSMember = True |
---|
57 | if noCPSMember: |
---|
58 | pr.addMember(s_id, 'UnSeT',roles=('Member',)) |
---|
59 | groups = context.portal_directories.groups |
---|
60 | gm = list(groups.getEntry('Students')['members']) |
---|
61 | gm.extend((s_id,)) |
---|
62 | groups.editEntry({'group': 'Students', |
---|
63 | 'members': gm}) |
---|
64 | return context.students_folder_view_manager(psm=psm) |
---|
65 | ## return context.create_jamb_form(rendered = res, |
---|
66 | ## psm = psm, |
---|
67 | ## ds = ds, |
---|
68 | ## ) |
---|
69 | |
---|
70 | return res,psm,ds |
---|
71 | |
---|