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