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 2106 2007-08-16 14:43:53Z henrik $ |
---|
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 | slip = "slip" in request.keys() |
---|
32 | submitted = False |
---|
33 | mode = request.get('mode','') |
---|
34 | if not mode: |
---|
35 | if apply_pume or edit: |
---|
36 | mode = "edit" |
---|
37 | else: |
---|
38 | mode = "create" |
---|
39 | validate = create or edit or apply_pume |
---|
40 | |
---|
41 | lt = context.portal_layouts |
---|
42 | reg_no = request.get('widget__reg_no','').upper() |
---|
43 | if not reg_no: |
---|
44 | reg_no = request.form.get('reg_no','').upper() |
---|
45 | pin = request.form.get('pin','') |
---|
46 | object = {} |
---|
47 | if reg_no: |
---|
48 | brains = context.applicants_catalog(reg_no = reg_no) |
---|
49 | if len(brains) == 1: |
---|
50 | for field in context.applicants_catalog.schema(): |
---|
51 | object[field] = getattr(brains[0],field,None) |
---|
52 | if object['status'] == "submitted": |
---|
53 | submitted = True |
---|
54 | #set_trace() |
---|
55 | if not create and pin != object['pin']: |
---|
56 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
57 | if slip: |
---|
58 | mode = "view_slip" |
---|
59 | |
---|
60 | res,psm,ds = lt.renderLayout(layout_id= 'application', |
---|
61 | schema_id= 'application', |
---|
62 | layout_mode = mode, |
---|
63 | context=context, |
---|
64 | mapping=validate and REQUEST, |
---|
65 | ob=object, |
---|
66 | commit = False, |
---|
67 | ) |
---|
68 | |
---|
69 | if slip: |
---|
70 | return context.apply_pume_slip(rendered = res, |
---|
71 | psm = "", |
---|
72 | #psm = "%s, %s" % (psm,ds), |
---|
73 | mode = mode, |
---|
74 | ds = ds, |
---|
75 | ) |
---|
76 | |
---|
77 | if psm == 'invalid': |
---|
78 | return context.apply_pume_form(rendered = res, |
---|
79 | psm = "Please correct your input!", |
---|
80 | #psm = "%s, %s" % (psm,ds), |
---|
81 | mode = mode, |
---|
82 | ds = ds, |
---|
83 | ) |
---|
84 | elif psm == '': |
---|
85 | return context.apply_pume_form(rendered = res, |
---|
86 | psm = None, |
---|
87 | ds = ds, |
---|
88 | mode = mode, |
---|
89 | ) |
---|
90 | elif psm == 'valid': |
---|
91 | pass |
---|
92 | data = {} |
---|
93 | for field in context.applicants_catalog.schema(): |
---|
94 | if ds.has_key(field) and request.has_key("widget__%s" % field): |
---|
95 | data[field] = ds.get(field) |
---|
96 | data['reg_no'] = reg_no |
---|
97 | |
---|
98 | if apply_pume: |
---|
99 | if not request.has_key('confirm'): |
---|
100 | mode = "edit" |
---|
101 | psm = "Please confirm Passport Photograph" |
---|
102 | else: |
---|
103 | mode = "view" |
---|
104 | psm = "You successfully applied for PUME" |
---|
105 | data['application_date'] = current |
---|
106 | data['status'] = "submitted" |
---|
107 | context.applicants_catalog.modifyRecord(**data) |
---|
108 | elif create: |
---|
109 | if submitted: |
---|
110 | mode = "view" |
---|
111 | else: |
---|
112 | mode = "edit" |
---|
113 | psm = "" |
---|
114 | #set_trace() |
---|
115 | object['pin'] = str(ds.get('pin')) |
---|
116 | res,psm,dummy = lt.renderLayout(layout_id= 'application', |
---|
117 | schema_id= 'application', |
---|
118 | layout_mode = mode, |
---|
119 | context=context, |
---|
120 | mapping={}, |
---|
121 | ob=object, |
---|
122 | commit = False, |
---|
123 | ) |
---|
124 | elif edit: |
---|
125 | mode = "edit" |
---|
126 | psm = "Content changed" |
---|
127 | |
---|
128 | res,psm_dummy,ds = lt.renderLayout(layout_id= 'application', |
---|
129 | schema_id= 'application', |
---|
130 | layout_mode = mode, |
---|
131 | context=context, |
---|
132 | mapping=validate and REQUEST, |
---|
133 | ob=object, |
---|
134 | commit = False, |
---|
135 | ) |
---|
136 | |
---|
137 | return context.apply_pume_form(rendered = res, |
---|
138 | psm = psm, |
---|
139 | #psm = "%s, %s" % (psm,ds), |
---|
140 | mode = mode, |
---|
141 | ds = ds, |
---|
142 | ) |
---|
143 | |
---|
144 | |
---|