1 | ## Script (Python) "apply_admission" |
---|
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_admission.py 5258 2010-07-08 14:03:12Z henrik $ |
---|
11 | """ |
---|
12 | process the 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_admission') |
---|
23 | |
---|
24 | mtool = context.portal_membership |
---|
25 | member = mtool.getAuthenticatedMember() |
---|
26 | |
---|
27 | current = DateTime.DateTime() |
---|
28 | pr = context.portal_registration |
---|
29 | pprops = context.portal_properties |
---|
30 | request = REQUEST |
---|
31 | |
---|
32 | #manage = "manage" in request.keys() |
---|
33 | screening_types = ('prence','pume','pume2','pce','pde','cest','sandwich','dp','ct','pt','sandwich2008') |
---|
34 | if not (traverse_subpath and traverse_subpath[0] in screening_types): |
---|
35 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
36 | configuration = [] |
---|
37 | headings = {} |
---|
38 | headings['pume'] = 'Apply for Post UME Screening Test (2010/2011)! ' |
---|
39 | headings['pume2'] = 'Apply for Post UME Screening Test 2010/2011 (Uniben as 2nd choice)!' |
---|
40 | headings['pde'] = 'Apply for Post UDE Screening Test (2010/2011)! ' |
---|
41 | headings['prence'] = 'Apply for Pre-NCE Programme (2007/2008)! ' |
---|
42 | headings['pce'] = 'Apply for PCE Screening (2009/2010)! ' |
---|
43 | headings['sandwich2008'] = 'Apply for Part Time Degree in Education (2008/2009)! ' |
---|
44 | headings['cest'] = 'Apply for Part-Time Degree Programmes (2009/2010)! ' |
---|
45 | headings['pt'] = 'Apply for Part-Time Degree Programmes (2009/2010)! ' |
---|
46 | headings['dp'] = 'Apply for Diploma Programmes (2009/2010)! ' |
---|
47 | headings['ct'] = 'Apply for Certificate Programmes (2009/2010)! ' |
---|
48 | headings['sandwich'] = 'Apply for Part Time Degree in Education (2009/2010)! ' |
---|
49 | configuration += ('heading',headings), |
---|
50 | |
---|
51 | headings_slip = {} |
---|
52 | headings_slip['pume'] = 'Post UME Screening (2010/2011) Acknowledgement Slip!' |
---|
53 | headings_slip['pume2'] = 'Post UME Screening (2010/2011) Acknowledgement Slip (Uniben 2nd choice)!' |
---|
54 | headings_slip['pde'] = 'Post UDE Screening (2010/2011) Acknowledgement Slip' |
---|
55 | headings_slip['prence'] = 'Pre-NCE Application (2007/2008) Acknowledgement Slip' |
---|
56 | headings_slip['pce'] = 'PCE Screening (2009/2010) Acknowledgement Slip' |
---|
57 | headings_slip['sandwich2008'] = 'Application for Part Time Degree in Education (2008/2009) Acknowledgement Slip' |
---|
58 | headings_slip['cest'] = 'CEST Application (2009/2010) Acknowledgement Slip' |
---|
59 | headings_slip['pt'] = 'Part-Time Degree Application (2009/2010) Acknowledgement Slip' |
---|
60 | headings_slip['dp'] = 'Diploma Programme Application (2009/2010) Acknowledgement Slip' |
---|
61 | headings_slip['ct'] = 'Certificate Programme Application (2009/2010) Acknowledgement Slip' |
---|
62 | headings_slip['sandwich'] = 'Application for Part Time Degree in Education (2009/2010) Acknowledgement Slip' |
---|
63 | configuration += ('heading_slip',headings_slip), |
---|
64 | |
---|
65 | deaddates = {} |
---|
66 | |
---|
67 | #config_params = context.getConfigParams() |
---|
68 | #deaddates['pume'] = config_params['dead_pume'] |
---|
69 | |
---|
70 | deaddates['pume'] = DateTime.DateTime(pprops.date1) |
---|
71 | deaddates['pume2'] = DateTime.DateTime(pprops.date1) |
---|
72 | deaddates['pde'] = DateTime.DateTime(pprops.date2) |
---|
73 | deaddates['prence'] = DateTime.DateTime(pprops.date1) |
---|
74 | deaddates['pce'] = DateTime.DateTime(pprops.date5) |
---|
75 | deaddates['sandwich2008'] = DateTime.DateTime(pprops.date1) #is expired like pume |
---|
76 | deaddates['cest'] = DateTime.DateTime(pprops.date3) |
---|
77 | deaddates['sandwich'] = DateTime.DateTime(pprops.date4) |
---|
78 | deaddates['pt'] = DateTime.DateTime(pprops.date5) |
---|
79 | deaddates['dp'] = DateTime.DateTime(pprops.date5) |
---|
80 | deaddates['ct'] = DateTime.DateTime(pprops.date5) |
---|
81 | configuration += ('deaddate',deaddates), |
---|
82 | |
---|
83 | deadline = {} |
---|
84 | for sct in screening_types: |
---|
85 | deadline[sct] = deaddates[sct].strftime('%A, %d. %B %Y at %I:%M %p') |
---|
86 | configuration += ('deadline',deadline), |
---|
87 | |
---|
88 | confirm = {} |
---|
89 | confirm['pume'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me." |
---|
90 | confirm['pume2'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me." |
---|
91 | confirm['pde'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me." |
---|
92 | confirm['prence'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me." |
---|
93 | confirm['pce'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me." |
---|
94 | confirm['cest'] = confirm['sandwich'] = confirm['pt'] = confirm['dp'] = confirm['ct'] = confirm['sandwich2008'] = """I hereby acknowledge |
---|
95 | by ticking this check box that if it is discovered |
---|
96 | at any time, that I do not possess any of the qualifications, which I have obtained, I will be |
---|
97 | expelled from the University and shall not be readmitted for the same or any other programme, |
---|
98 | even if I have upgraded my previous qualification or posses additional qualifications.""" |
---|
99 | configuration += ('confirm',confirm), |
---|
100 | |
---|
101 | #type_name = 'StudentApplication' |
---|
102 | #ti = context.portal_types[type_name] |
---|
103 | #REQUEST.set('type_name',type_name) |
---|
104 | create = "create" in request.keys() |
---|
105 | apply_admission = "apply" in request.keys() |
---|
106 | edit = "edit" in request.keys() or "cpsdocument_edit_button" in request.form.keys() |
---|
107 | slip = "slip" in request.keys() |
---|
108 | submitted = False |
---|
109 | mode = request.get('mode','') |
---|
110 | if not mode: |
---|
111 | if apply_admission or edit: |
---|
112 | mode = "edit" |
---|
113 | elif slip: |
---|
114 | mode = "view_slip" |
---|
115 | else: |
---|
116 | mode = "create" |
---|
117 | validate = create or edit or apply_admission |
---|
118 | |
---|
119 | without_reg_no = False |
---|
120 | |
---|
121 | |
---|
122 | lt = context.portal_layouts |
---|
123 | object = {} |
---|
124 | pin = request.form.get('pin','') |
---|
125 | # reg_no = request.get('widget__reg_no','').upper() |
---|
126 | # if not reg_no: |
---|
127 | # reg_no = request.form.get('reg_no','').upper() |
---|
128 | info = {} |
---|
129 | screening_type = 'pume' |
---|
130 | if traverse_subpath and traverse_subpath[0] in screening_types: |
---|
131 | screening_type = traverse_subpath[0] |
---|
132 | without_reg_no = screening_type in ('prence','cest','sandwich','sandwich2008','dp','pt','ct') |
---|
133 | info['expired'] = current.greaterThan(deaddates[screening_type]) |
---|
134 | info['expiration_date'] = deaddates[screening_type] |
---|
135 | info['status'] = object.get('status','') |
---|
136 | info['screening_type'] = screening_type |
---|
137 | layout = "application_%s" % screening_type |
---|
138 | for co_name,co_dict in configuration: |
---|
139 | info[co_name] = co_dict[screening_type] |
---|
140 | # the reg_no is a hidden field in the form |
---|
141 | reg_no = request.form.get('reg_no','').upper() |
---|
142 | |
---|
143 | if not reg_no: |
---|
144 | # validate form if no reg_no specified |
---|
145 | res,psm,ds = lt.renderLayout(layout_id= layout, |
---|
146 | schema_id= 'import_application', |
---|
147 | layout_mode = mode, |
---|
148 | context=context, |
---|
149 | mapping=validate and REQUEST, |
---|
150 | ob={}, |
---|
151 | commit = False, |
---|
152 | ) |
---|
153 | if psm == 'invalid': |
---|
154 | return context.apply_admission_form(rendered = res, |
---|
155 | psm = "Please correct your input!", |
---|
156 | mode = mode, |
---|
157 | ds = ds, |
---|
158 | info = info, |
---|
159 | ) |
---|
160 | elif psm == '': |
---|
161 | return context.apply_admission_form(rendered = res, |
---|
162 | psm = psm, |
---|
163 | ds = ds, |
---|
164 | mode = mode, |
---|
165 | info = info, |
---|
166 | ) |
---|
167 | if without_reg_no: |
---|
168 | ## see fceokene #147 |
---|
169 | if screening_type == 'sandwich2008': |
---|
170 | reg_no = ds.get('pin_n','').upper() |
---|
171 | else: |
---|
172 | reg_no = ds.get('pin_p') + ds.get('pin_b') + ds.get('pin_n') |
---|
173 | else: |
---|
174 | reg_no = ds.get('reg_no') |
---|
175 | info['reg_no'] = reg_no |
---|
176 | |
---|
177 | brains = context.applicants_catalog(reg_no = reg_no.upper()) |
---|
178 | if len(brains) == 1: |
---|
179 | for field in context.applicants_catalog.schema(): |
---|
180 | object[field] = getattr(brains[0],field,None) |
---|
181 | screening_type = info['screening_type'] = object['screening_type'] |
---|
182 | for co_name,co_dict in configuration: |
---|
183 | info[co_name] = co_dict[screening_type] |
---|
184 | if not object['passport']: |
---|
185 | object['passport'] = '' |
---|
186 | if object['status'] and ('submitted' in object['status'] or 'admitted' in object['status'] or 'created' in object['status']): |
---|
187 | submitted = True |
---|
188 | # cannot happen anymore but anyway |
---|
189 | #if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()): |
---|
190 | # logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin)) |
---|
191 | # return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
192 | |
---|
193 | #rerender with current object = application-record |
---|
194 | |
---|
195 | if slip: |
---|
196 | mode = "view_slip" |
---|
197 | logger.info('%s/%s views application slip' % (member,reg_no)) |
---|
198 | |
---|
199 | res,psm,ds = lt.renderLayout(layout_id= layout, |
---|
200 | schema_id= 'import_application', |
---|
201 | layout_mode = mode, |
---|
202 | context=context, |
---|
203 | mapping=validate and REQUEST, |
---|
204 | ob=object, |
---|
205 | commit = False, |
---|
206 | ) |
---|
207 | if slip: |
---|
208 | return context.apply_admission_slip(rendered = res, |
---|
209 | psm = "", |
---|
210 | mode = mode, |
---|
211 | ds = ds, |
---|
212 | info = info, |
---|
213 | ) |
---|
214 | |
---|
215 | if psm == 'invalid': |
---|
216 | return context.apply_admission_form(rendered = res, |
---|
217 | psm = "Please correct your input!", |
---|
218 | mode = mode, |
---|
219 | ds = ds, |
---|
220 | info = info, |
---|
221 | ) |
---|
222 | # For the next application session it should be reverted to |
---|
223 | # (see comment 09/06/07 16:40:52 in ticket #328): |
---|
224 | |
---|
225 | #if not create and (pin != object['pin'] and not context.isSectionOfficer()): |
---|
226 | #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin)) |
---|
227 | #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
228 | info['status'] = object.get('status','') |
---|
229 | |
---|
230 | data = {} |
---|
231 | dm = ds.getDataModel() |
---|
232 | for field in context.applicants_catalog.schema(): |
---|
233 | if dm.has_key("%s" % field): |
---|
234 | data[field] = dm.get(field) |
---|
235 | data['reg_no'] = reg_no |
---|
236 | |
---|
237 | if apply_admission: |
---|
238 | if submitted: |
---|
239 | mode = "view" |
---|
240 | psm = "The form has already been submitted and you are not allowed to resubmit the data!" |
---|
241 | logger.info('%s/%s tried to resubmit application record' % (member,reg_no)) |
---|
242 | # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout, |
---|
243 | # schema_id= 'import_application', |
---|
244 | # layout_mode = mode, |
---|
245 | # context=context, |
---|
246 | # mapping={}, |
---|
247 | # ob=object, |
---|
248 | # commit = False, |
---|
249 | # ) |
---|
250 | elif not request.has_key('confirm'): |
---|
251 | mode = "edit" |
---|
252 | psm = "Please confirm Passport Photograph!" |
---|
253 | logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no)) |
---|
254 | else: |
---|
255 | mode = "view" |
---|
256 | psm = "You successfully applied for admission!" |
---|
257 | if object['status'] == 'edited': |
---|
258 | data['status'] = "submitted" |
---|
259 | data['application_date'] = current |
---|
260 | logger.info('%s/%s modified and submitted application record' % (member,reg_no)) |
---|
261 | elif object['status'] == 'reset': |
---|
262 | data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y') |
---|
263 | logger.info('%s/%s modified and resubmitted application record' % (member,reg_no)) |
---|
264 | object['status'] = data['status'] |
---|
265 | context.applicants_catalog.modifyRecord(**data) |
---|
266 | # rerendering neccessary since object changed |
---|
267 | res,psm_dummy,ds = lt.renderLayout(layout_id= layout, |
---|
268 | schema_id= 'import_application', |
---|
269 | layout_mode = mode, |
---|
270 | context=context, |
---|
271 | mapping=validate and REQUEST, |
---|
272 | ob=object, |
---|
273 | commit = False, |
---|
274 | ) |
---|
275 | elif create: |
---|
276 | if submitted: |
---|
277 | mode = "view" |
---|
278 | logger.info('%s/%s is viewing application record' % (member,reg_no)) |
---|
279 | else: |
---|
280 | mode = "edit" |
---|
281 | logger.info('%s/%s started editing application record' % (member,reg_no)) |
---|
282 | psm = "" |
---|
283 | if without_reg_no: |
---|
284 | object['reg_no'] = reg_no |
---|
285 | object['pin'] = str(ds.get('pin')) |
---|
286 | # rerendering neccessary since object changed |
---|
287 | res,psm,ds_dummy = lt.renderLayout(layout_id= layout, |
---|
288 | schema_id= 'import_application', |
---|
289 | layout_mode = mode, |
---|
290 | context=context, |
---|
291 | mapping={}, |
---|
292 | ob=object, |
---|
293 | commit = False, |
---|
294 | ) |
---|
295 | elif edit: |
---|
296 | if submitted: |
---|
297 | mode = "view" |
---|
298 | psm = "The form has already been submitted and you are not allowed to modify the data!" |
---|
299 | logger.info('%s/%s tried to edit submitted application record' % (member,reg_no)) |
---|
300 | # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout, |
---|
301 | # schema_id= 'import_application', |
---|
302 | # layout_mode = mode, |
---|
303 | # context=context, |
---|
304 | # mapping={}, |
---|
305 | # ob=object, |
---|
306 | # commit = False, |
---|
307 | # ) |
---|
308 | else: |
---|
309 | mode = "edit" |
---|
310 | psm = "Content changed!" |
---|
311 | data['status'] = "edited" |
---|
312 | #set_trace() |
---|
313 | context.applicants_catalog.modifyRecord(**data) |
---|
314 | logger.info('%s/%s modified application record' % (member,reg_no)) |
---|
315 | |
---|
316 | try: |
---|
317 | passport_uploaded = bool(data['passport']) |
---|
318 | except: |
---|
319 | passport_uploaded = False |
---|
320 | |
---|
321 | return context.apply_admission_form(rendered = res, |
---|
322 | psm = psm, |
---|
323 | mode = mode, |
---|
324 | show_submit = passport_uploaded, |
---|
325 | ds = ds, |
---|
326 | info = info, |
---|
327 | ) |
---|