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