1 | ## Script (Python) "apply_pume" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=REQUEST |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: apply_pume.py 2098 2007-08-15 16:22:25Z joachim $ |
---|
11 | """ |
---|
12 | process the Pume Application Form |
---|
13 | """ |
---|
14 | try: |
---|
15 | from Products.zdb import set_trace |
---|
16 | except: |
---|
17 | def set_trace(): |
---|
18 | pass |
---|
19 | |
---|
20 | import DateTime |
---|
21 | current = DateTime.DateTime() |
---|
22 | pr = context.portal_registration |
---|
23 | request = REQUEST |
---|
24 | |
---|
25 | #type_name = 'StudentApplication' |
---|
26 | #ti = context.portal_types[type_name] |
---|
27 | #REQUEST.set('type_name',type_name) |
---|
28 | create = "create" in request.keys() |
---|
29 | apply_pume = "apply" in request.keys() |
---|
30 | edit = "edit" in request.keys() |
---|
31 | mode = request.get('mode','') |
---|
32 | if not mode: |
---|
33 | if apply_pume or edit: |
---|
34 | mode = "edit" |
---|
35 | else: |
---|
36 | mode = "create" |
---|
37 | validate = create or edit or apply_pume |
---|
38 | |
---|
39 | lt = context.portal_layouts |
---|
40 | reg_no = request.get('widget__reg_no','').upper() |
---|
41 | if not reg_no: |
---|
42 | reg_no = request.get('reg_no','').upper() |
---|
43 | |
---|
44 | object = {} |
---|
45 | #set_trace() |
---|
46 | if reg_no: |
---|
47 | brains = context.applicants_catalog(reg_no = reg_no) |
---|
48 | if len(brains) == 1: |
---|
49 | for field in context.applicants_catalog.schema(): |
---|
50 | object[field] = getattr(brains[0],field,None) |
---|
51 | |
---|
52 | res,psm,ds = lt.renderLayout(layout_id= 'application', |
---|
53 | schema_id= 'application', |
---|
54 | layout_mode = mode, |
---|
55 | context=context, |
---|
56 | mapping=validate and REQUEST, |
---|
57 | ob=object, |
---|
58 | commit = False, |
---|
59 | ) |
---|
60 | |
---|
61 | if psm == 'invalid': |
---|
62 | return context.apply_pume_form(rendered = res, |
---|
63 | psm = "Please correct your input!", |
---|
64 | #psm = "%s, %s" % (psm,ds), |
---|
65 | mode = mode, |
---|
66 | ds = ds, |
---|
67 | ) |
---|
68 | elif psm == '': |
---|
69 | return context.apply_pume_form(rendered = res, |
---|
70 | psm = None, |
---|
71 | ds = ds, |
---|
72 | mode = mode, |
---|
73 | ) |
---|
74 | elif psm == 'valid': |
---|
75 | pass |
---|
76 | if create or edit or apply_pume: |
---|
77 | data = {} |
---|
78 | for field in context.applicants_catalog.schema(): |
---|
79 | if ds.has_key(field) and request.has_key("widget__%s" % field): |
---|
80 | data[field] = ds.get(field) |
---|
81 | data['reg_no'] = reg_no |
---|
82 | if apply_pume: |
---|
83 | data['registration_date'] = current |
---|
84 | data['status'] = "submitted" |
---|
85 | context.applicants_catalog.modifyRecord(**data) |
---|
86 | if apply_pume: |
---|
87 | if not request.has_key('confirm'): |
---|
88 | return context.apply_pume_form(rendered = res, |
---|
89 | psm = "Please confirm Passport Photograph", |
---|
90 | #psm = "%s, %s" % (psm,ds), |
---|
91 | mode = mode, |
---|
92 | ds = ds, |
---|
93 | ) |
---|
94 | |
---|
95 | return request.RESPONSE.redirect("%s/apply_pume?mode=view®_no=%s" % |
---|
96 | (context.absolute_url(),ds.get('reg_no'))) |
---|
97 | elif edit or create: |
---|
98 | return request.RESPONSE.redirect("%s/apply_pume?mode=edit®_no=%s" % |
---|
99 | (context.absolute_url(),ds.get('reg_no'))) |
---|
100 | |
---|
101 | |
---|