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 2146 2007-08-22 13:05:07Z 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 | import logging |
---|
22 | logger = logging.getLogger('Skins.apply_pume') |
---|
23 | |
---|
24 | current = DateTime.DateTime() |
---|
25 | pr = context.portal_registration |
---|
26 | request = REQUEST |
---|
27 | |
---|
28 | #type_name = 'StudentApplication' |
---|
29 | #ti = context.portal_types[type_name] |
---|
30 | #REQUEST.set('type_name',type_name) |
---|
31 | create = "create" in request.keys() |
---|
32 | apply_pume = "apply" in request.keys() |
---|
33 | edit = "edit" in request.keys() |
---|
34 | slip = "slip" in request.keys() |
---|
35 | submitted = False |
---|
36 | mode = request.get('mode','') |
---|
37 | if not mode: |
---|
38 | if apply_pume or edit: |
---|
39 | mode = "edit" |
---|
40 | else: |
---|
41 | mode = "create" |
---|
42 | validate = create or edit or apply_pume |
---|
43 | |
---|
44 | lt = context.portal_layouts |
---|
45 | reg_no = request.get('widget__reg_no','').upper() |
---|
46 | if not reg_no: |
---|
47 | reg_no = request.form.get('reg_no','').upper() |
---|
48 | pin = request.form.get('pin','') |
---|
49 | object = {} |
---|
50 | if reg_no: |
---|
51 | brains = context.applicants_catalog(reg_no = reg_no) |
---|
52 | if len(brains) == 1: |
---|
53 | for field in context.applicants_catalog.schema(): |
---|
54 | object[field] = getattr(brains[0],field,None) |
---|
55 | if not object['passport']: |
---|
56 | object['passport'] = '' |
---|
57 | if object['status'] == "submitted": |
---|
58 | submitted = True |
---|
59 | if not create and pin != object['pin']: |
---|
60 | logger.info('%s entered wrong pin %s' % (reg_no,pin)) |
---|
61 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
62 | if slip: |
---|
63 | mode = "view_slip" |
---|
64 | logger.info('%s views application slip' % (reg_no)) |
---|
65 | res,psm,ds = lt.renderLayout(layout_id= 'application', |
---|
66 | schema_id= 'application', |
---|
67 | layout_mode = mode, |
---|
68 | context=context, |
---|
69 | mapping=validate and REQUEST, |
---|
70 | ob=object, |
---|
71 | commit = False, |
---|
72 | ) |
---|
73 | |
---|
74 | if slip: |
---|
75 | return context.apply_pume_slip(rendered = res, |
---|
76 | psm = "", |
---|
77 | #psm = "%s, %s" % (psm,ds), |
---|
78 | mode = mode, |
---|
79 | ds = ds, |
---|
80 | ) |
---|
81 | |
---|
82 | if psm == 'invalid': |
---|
83 | return context.apply_pume_form(rendered = res, |
---|
84 | psm = "Please correct your input!", |
---|
85 | #psm = "%s, %s" % (psm,ds), |
---|
86 | mode = mode, |
---|
87 | ds = ds, |
---|
88 | ) |
---|
89 | elif psm == '': |
---|
90 | return context.apply_pume_form(rendered = res, |
---|
91 | psm = None, |
---|
92 | ds = ds, |
---|
93 | mode = mode, |
---|
94 | ) |
---|
95 | elif psm == 'valid': |
---|
96 | pass |
---|
97 | data = {} |
---|
98 | dm = ds.getDataModel() |
---|
99 | for field in context.applicants_catalog.schema(): |
---|
100 | if dm.has_key("%s" % field): |
---|
101 | data[field] = dm.get(field) |
---|
102 | data['reg_no'] = reg_no |
---|
103 | if apply_pume: |
---|
104 | if submitted: |
---|
105 | mode = "view" |
---|
106 | psm = "The form has already been submitted and you are not allowed to resubmit the data!" |
---|
107 | logger.info('%s tried to resubmit application record' % (reg_no)) |
---|
108 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
109 | schema_id= 'application', |
---|
110 | layout_mode = mode, |
---|
111 | context=context, |
---|
112 | mapping={}, |
---|
113 | ob=object, |
---|
114 | commit = False, |
---|
115 | ) |
---|
116 | # elif not dm.get('passport'): |
---|
117 | # mode = "edit" |
---|
118 | # psm = "Please upload Passport Photograph!" |
---|
119 | # logger.info('%s tried to submit without uploading a passport foto' % (reg_no)) |
---|
120 | elif not request.has_key('confirm'): |
---|
121 | mode = "edit" |
---|
122 | psm = "Please confirm Passport Photograph!" |
---|
123 | logger.info('%s tried to submit without ticking confirmation check box' % (reg_no)) |
---|
124 | else: |
---|
125 | mode = "view" |
---|
126 | psm = "You successfully applied for PUME!" |
---|
127 | data['application_date'] = current |
---|
128 | data['status'] = "submitted" |
---|
129 | context.applicants_catalog.modifyRecord(**data) |
---|
130 | logger.info('%s modified and submitted application record' % (reg_no)) |
---|
131 | res,psm_dummy,ds = lt.renderLayout(layout_id= 'application', |
---|
132 | schema_id= 'application', |
---|
133 | layout_mode = mode, |
---|
134 | context=context, |
---|
135 | mapping=validate and REQUEST, |
---|
136 | ob=object, |
---|
137 | commit = False, |
---|
138 | ) |
---|
139 | elif create: |
---|
140 | if submitted: |
---|
141 | mode = "view" |
---|
142 | logger.info('%s views application record' % (reg_no)) |
---|
143 | else: |
---|
144 | mode = "edit" |
---|
145 | logger.info('%s edits application record' % (reg_no)) |
---|
146 | psm = "" |
---|
147 | #set_trace() |
---|
148 | object['pin'] = str(ds.get('pin')) |
---|
149 | res,psm,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
150 | schema_id= 'application', |
---|
151 | layout_mode = mode, |
---|
152 | context=context, |
---|
153 | mapping={}, |
---|
154 | ob=object, |
---|
155 | commit = False, |
---|
156 | ) |
---|
157 | elif edit: |
---|
158 | if submitted: |
---|
159 | mode = "view" |
---|
160 | psm = "The form has already been submitted and you are not allowed to modify the data!" |
---|
161 | logger.info('%s tried to edit submitted application record' % (reg_no)) |
---|
162 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
163 | schema_id= 'application', |
---|
164 | layout_mode = mode, |
---|
165 | context=context, |
---|
166 | mapping={}, |
---|
167 | ob=object, |
---|
168 | commit = False, |
---|
169 | ) |
---|
170 | else: |
---|
171 | mode = "edit" |
---|
172 | psm = "Content changed" |
---|
173 | data['status'] = "edited" |
---|
174 | context.applicants_catalog.modifyRecord(**data) |
---|
175 | logger.info('%s modified application record' % (reg_no)) |
---|
176 | |
---|
177 | |
---|
178 | return context.apply_pume_form(rendered = res, |
---|
179 | psm = psm, |
---|
180 | #psm = "%s, %s" % (psm,ds), |
---|
181 | mode = mode, |
---|
182 | show_submit = bool(data['passport']), |
---|
183 | ds = ds, |
---|
184 | ) |
---|
185 | |
---|
186 | |
---|