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 3342 2008-03-16 21:26:39Z 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 | request = REQUEST |
---|
30 | |
---|
31 | manage = "manage" in request.keys() |
---|
32 | screening_types = ('prence','pume','pce','pde','cest','sandwich') |
---|
33 | if not (traverse_subpath and traverse_subpath[0] in screening_types) and not manage: |
---|
34 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
35 | configuration = [] |
---|
36 | headings = {} |
---|
37 | headings['pume'] = 'Apply for Post UME Screening Test (2007/2008)! ' |
---|
38 | headings['pde'] = 'Apply for Post UDE Screening Test (2007/2008)! ' |
---|
39 | headings['prence'] = 'Apply for Pre-NCE Programme (2007/2008)! ' |
---|
40 | headings['pce'] = 'Apply for PCE Screening (2007/2008)! ' |
---|
41 | #headings['cest'] = 'Apply for Part-Time Degree and Diploma Programmes (2007/2008)! ' |
---|
42 | headings['cest'] = 'Apply for Diploma Programmes (2007/2008)! ' |
---|
43 | headings['sandwich'] = 'Apply for Part Time Degree in Education (2007/2008)! ' |
---|
44 | #headings['pt'] = 'Apply for Local/Part-Time Programmes (2007/2008)' |
---|
45 | |
---|
46 | configuration += ('heading',headings), |
---|
47 | headings_slip = {} |
---|
48 | headings_slip['pume'] = 'Post UME Screening (2007/2008) Aknowledgement Slip!' |
---|
49 | headings_slip['pde'] = 'Post UDE Screening (2007/2008) Aknowledgement Slip' |
---|
50 | headings_slip['prence'] = 'Pre-NCE Application (2007/2008) Aknowledgement Slip' |
---|
51 | headings_slip['pce'] = 'PCE Screening (2007/2008) Aknowledgement Slip' |
---|
52 | headings_slip['cest'] = 'Common Entrance Screening (2007/2008) Aknowledgement Slip' |
---|
53 | headings_slip['sandwich'] = 'Application for Part Time Degree in Education (2007/2008) Aknowledgement Slip' |
---|
54 | #headings_slip['pt'] = 'Part Time (2007/2008) Aknowledgement Slip' |
---|
55 | configuration += ('heading_slip',headings_slip), |
---|
56 | |
---|
57 | deaddates = {} |
---|
58 | deaddates['pume'] = DateTime.DateTime('2007/08/12 23:59') |
---|
59 | deaddates['pde'] = DateTime.DateTime('2007/11/04 23:59') |
---|
60 | deaddates['prence'] = DateTime.DateTime('2007/12/4 23:59') |
---|
61 | deaddates['pce'] = DateTime.DateTime('2007/08/12 23:59') |
---|
62 | deaddates['cest'] = DateTime.DateTime('2008/02/15 23:59') |
---|
63 | deaddates['sandwich'] = DateTime.DateTime('2008/04/09 23:59') |
---|
64 | #deaddates['pt'] = DateTime.DateTime('2007/12/24 23:59') |
---|
65 | configuration += ('deaddate',deaddates), |
---|
66 | |
---|
67 | deadline = {} |
---|
68 | #deadline['pume'] = '[Date of PUME Deadline]' |
---|
69 | for sct in screening_types: |
---|
70 | deadline[sct] = deaddates[sct].strftime('%A, %d. %B %Y') |
---|
71 | # deadline['pde'] = 'Sunday, 4th November 2007' |
---|
72 | # deadline['prence'] = '[Date of PRENCE Deadline]' |
---|
73 | # deadline['pce'] = '[Date of PCE Deadline]' |
---|
74 | # deadline['cest'] = '[Date of CEST Deadline]' |
---|
75 | # deadline['pt'] = '[Date of PT Deadline]' |
---|
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 or manage: |
---|
105 | mode = "edit" |
---|
106 | else: |
---|
107 | mode = "create" |
---|
108 | validate = create or edit or apply_admission |
---|
109 | |
---|
110 | if manage: |
---|
111 | validate = False |
---|
112 | without_reg_no = False |
---|
113 | |
---|
114 | |
---|
115 | lt = context.portal_layouts |
---|
116 | |
---|
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 | if not reg_no: |
---|
122 | reg_no = request.get('widget__pin_n','').upper() |
---|
123 | |
---|
124 | object = {} |
---|
125 | if reg_no: |
---|
126 | brains = context.applicants_catalog(reg_no = reg_no) |
---|
127 | if len(brains) == 1: |
---|
128 | for field in context.applicants_catalog.schema(): |
---|
129 | object[field] = getattr(brains[0],field,None) |
---|
130 | if not object['passport']: |
---|
131 | object['passport'] = '' |
---|
132 | if object['status'] and ('submitted' in object['status'] or 'admitted' in object['status'] or 'created' in object['status']): |
---|
133 | submitted = True |
---|
134 | |
---|
135 | if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()): |
---|
136 | logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin)) |
---|
137 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
138 | |
---|
139 | # For the next application session it should be reverted to |
---|
140 | # (see comment 09/06/07 16:40:52 in ticket #328): |
---|
141 | |
---|
142 | #if not create and (pin != object['pin'] and not context.isSectionOfficer()): |
---|
143 | #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin)) |
---|
144 | #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | info = {} |
---|
149 | |
---|
150 | info['status'] = object.get('status','') |
---|
151 | if traverse_subpath and traverse_subpath[0] in screening_types: |
---|
152 | screening_type = info['screening_type'] = traverse_subpath[0] |
---|
153 | elif manage: |
---|
154 | if object['screening_type']: |
---|
155 | st = object['screening_type'] |
---|
156 | else: |
---|
157 | st = 'pume' |
---|
158 | screening_type = info['screening_type'] = st |
---|
159 | |
---|
160 | for co_name,co_dict in configuration: |
---|
161 | info[co_name] = co_dict[screening_type] |
---|
162 | layout = "application_%s" % screening_type |
---|
163 | without_reg_no = screening_type in ('prence','cest','sandwich') |
---|
164 | info['expired'] = current.greaterThan(deaddates[screening_type]) |
---|
165 | |
---|
166 | |
---|
167 | if slip: |
---|
168 | mode = "view_slip" |
---|
169 | logger.info('%s/%s views application slip' % (member,reg_no)) |
---|
170 | |
---|
171 | res,psm,ds = lt.renderLayout(layout_id= layout, |
---|
172 | schema_id= 'import_application', |
---|
173 | layout_mode = mode, |
---|
174 | context=context, |
---|
175 | mapping=validate and REQUEST, |
---|
176 | ob=object, |
---|
177 | commit = False, |
---|
178 | ) |
---|
179 | if slip: |
---|
180 | return context.apply_admission_slip(rendered = res, |
---|
181 | psm = "", |
---|
182 | mode = mode, |
---|
183 | ds = ds, |
---|
184 | info = info, |
---|
185 | ) |
---|
186 | if psm == 'invalid': |
---|
187 | return context.apply_admission_form(rendered = res, |
---|
188 | psm = "Please correct your input!", |
---|
189 | mode = mode, |
---|
190 | ds = ds, |
---|
191 | info = info, |
---|
192 | ) |
---|
193 | elif psm == '' and not manage: |
---|
194 | return context.apply_admission_form(rendered = res, |
---|
195 | psm = psm, |
---|
196 | ds = ds, |
---|
197 | mode = mode, |
---|
198 | info = info, |
---|
199 | ) |
---|
200 | # elif psm == 'valid' or (psm == '' and manage): |
---|
201 | # pass |
---|
202 | if without_reg_no: |
---|
203 | reg_no = ds.get('reg_no') |
---|
204 | data = {} |
---|
205 | dm = ds.getDataModel() |
---|
206 | for field in context.applicants_catalog.schema(): |
---|
207 | if dm.has_key("%s" % field): |
---|
208 | data[field] = dm.get(field) |
---|
209 | data['reg_no'] = reg_no |
---|
210 | if apply_admission: |
---|
211 | if submitted: |
---|
212 | mode = "view" |
---|
213 | psm = "The form has already been submitted and you are not allowed to resubmit the data!" |
---|
214 | logger.info('%s/%s tried to resubmit application record' % (member,reg_no)) |
---|
215 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout, |
---|
216 | schema_id= 'import_application', |
---|
217 | layout_mode = mode, |
---|
218 | context=context, |
---|
219 | mapping={}, |
---|
220 | ob=object, |
---|
221 | commit = False, |
---|
222 | ) |
---|
223 | elif not request.has_key('confirm'): |
---|
224 | mode = "edit" |
---|
225 | psm = "Please confirm Passport Photograph!" |
---|
226 | logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no)) |
---|
227 | else: |
---|
228 | mode = "view" |
---|
229 | psm = "You successfully applied for admission!" |
---|
230 | if object['status'] == 'edited': |
---|
231 | data['status'] = "submitted" |
---|
232 | data['application_date'] = current |
---|
233 | logger.info('%s/%s modified and submitted application record' % (member,reg_no)) |
---|
234 | elif object['status'] == 'reset': |
---|
235 | data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y') |
---|
236 | logger.info('%s/%s modified and resubmitted application record' % (member,reg_no)) |
---|
237 | object['status'] = data['status'] |
---|
238 | context.applicants_catalog.modifyRecord(**data) |
---|
239 | |
---|
240 | res,psm_dummy,ds = lt.renderLayout(layout_id= layout, |
---|
241 | schema_id= 'import_application', |
---|
242 | layout_mode = mode, |
---|
243 | context=context, |
---|
244 | mapping=validate and REQUEST, |
---|
245 | ob=object, |
---|
246 | commit = False, |
---|
247 | ) |
---|
248 | elif create: |
---|
249 | if submitted: |
---|
250 | mode = "view" |
---|
251 | logger.info('%s/%s views application record' % (member,reg_no)) |
---|
252 | else: |
---|
253 | mode = "edit" |
---|
254 | logger.info('%s/%s edits application record' % (member,reg_no)) |
---|
255 | psm = "" |
---|
256 | if without_reg_no: |
---|
257 | object['reg_no'] = reg_no |
---|
258 | object['pin'] = str(ds.get('pin')) |
---|
259 | res,psm,ds_dummy = lt.renderLayout(layout_id= layout, |
---|
260 | schema_id= 'import_application', |
---|
261 | layout_mode = mode, |
---|
262 | context=context, |
---|
263 | mapping={}, |
---|
264 | ob=object, |
---|
265 | commit = False, |
---|
266 | ) |
---|
267 | elif edit: |
---|
268 | #set_trace() |
---|
269 | if submitted: |
---|
270 | mode = "view" |
---|
271 | psm = "The form has already been submitted and you are not allowed to modify the data!" |
---|
272 | logger.info('%s/%s tried to edit submitted application record' % (member,reg_no)) |
---|
273 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout, |
---|
274 | schema_id= 'import_application', |
---|
275 | layout_mode = mode, |
---|
276 | context=context, |
---|
277 | mapping={}, |
---|
278 | ob=object, |
---|
279 | commit = False, |
---|
280 | ) |
---|
281 | else: |
---|
282 | mode = "edit" |
---|
283 | psm = "Content changed!" |
---|
284 | data['status'] = "edited" |
---|
285 | #set_trace() |
---|
286 | context.applicants_catalog.modifyRecord(**data) |
---|
287 | logger.info('%s/%s modified application record' % (member,reg_no)) |
---|
288 | |
---|
289 | elif manage: |
---|
290 | if submitted: |
---|
291 | mode = "view" |
---|
292 | psm = "You are now assuming the applicant's role!" |
---|
293 | logger.info('%s/%s entered application record' % (member,reg_no)) |
---|
294 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout, |
---|
295 | schema_id= 'import_application', |
---|
296 | layout_mode = mode, |
---|
297 | context=context, |
---|
298 | mapping={}, |
---|
299 | ob=object, |
---|
300 | commit = False, |
---|
301 | ) |
---|
302 | else: |
---|
303 | mode = "edit" |
---|
304 | psm = "You are now assuming the applicant's role!" |
---|
305 | logger.info('%s/%s entered application record' % (member,reg_no)) |
---|
306 | |
---|
307 | |
---|
308 | try: |
---|
309 | passport_uploaded = bool(data['passport']) |
---|
310 | except: |
---|
311 | passport_uploaded = False |
---|
312 | |
---|
313 | return context.apply_admission_form(rendered = res, |
---|
314 | psm = psm, |
---|
315 | mode = mode, |
---|
316 | show_submit = passport_uploaded, |
---|
317 | ds = ds, |
---|
318 | info = info, |
---|
319 | ) |
---|