source: WAeUP_SRP/trunk/skins/waeup_student/apply_admission.py @ 4596

Last change on this file since 4596 was 4542, checked in by Henrik Bettermann, 15 years ago

enable FCEOkene PCE application

  • Property svn:keywords set to Id
File size: 13.4 KB
Line 
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 4542 2009-11-02 14:04:18Z henrik $
11"""
12process the Application Form
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
20import DateTime
21import logging
22logger = logging.getLogger('Skins.apply_admission')
23
24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
26
27current = DateTime.DateTime()
28pr = context.portal_registration
29pprops = context.portal_properties
30request = REQUEST
31
32#manage = "manage" in request.keys()
33screening_types = ('prence','pume','pce','pde','cest','sandwich','dp','ct','pt')
34if not (traverse_subpath and traverse_subpath[0] in screening_types):
35    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
36configuration = []
37headings = {}
38headings['pume'] = 'Apply for Post UME Screening Test (2009/2010)! '
39headings['pde'] = 'Apply for Post UDE Screening Test (2009/2010)! '
40headings['prence'] = 'Apply for Pre-NCE Programme (2007/2008)! '
41headings['pce'] = 'Apply for PCE Screening (2009/2010)! '
42headings['cest'] = 'Apply for Part-Time Degree or Diploma Programmes (2008/2009)! '
43headings['pt'] = 'Apply for Part-Time Degree (2009/2010)! '
44headings['dp'] = 'Apply for Diploma Programmes (2009/2010)! '
45headings['ct'] = 'Apply for Certificate Programmes (2009/2010)! '
46headings['sandwich'] = 'Apply for Part Time Degree in Education (2008/2009)! '
47configuration += ('heading',headings),
48
49headings_slip = {}
50headings_slip['pume'] = 'Post UME Screening (2009/2010) Acknowledgement Slip!'
51headings_slip['pde'] = 'Post UDE Screening (2009/2010) Acknowledgement Slip'
52headings_slip['prence'] = 'Pre-NCE Application (2007/2008) Acknowledgement Slip'
53headings_slip['pce'] = 'PCE Screening (2009/2010) Acknowledgement Slip'
54headings_slip['cest'] = 'CEST Application (2008/2009) Acknowledgement Slip'
55headings_slip['pt'] = 'Part-Time Degree Application (2009/2010) Acknowledgement Slip'
56headings_slip['dp'] = 'Diploma Programme Application (2009/2010) Acknowledgement Slip'
57headings_slip['ct'] = 'Certificate Programme Application (2009/2010) Acknowledgement Slip'
58headings_slip['sandwich'] = 'Application for Part Time Degree in Education (2008/2009) Acknowledgement Slip'
59configuration += ('heading_slip',headings_slip),
60
61deaddates = {}
62
63#config_params = context.getConfigParams()
64#deaddates['pume'] = config_params['dead_pume']
65
66deaddates['pume'] = DateTime.DateTime(pprops.date1)
67deaddates['pde'] = DateTime.DateTime(pprops.date2)
68deaddates['prence'] = DateTime.DateTime(pprops.date1)
69deaddates['pce'] = DateTime.DateTime(pprops.date5)
70deaddates['cest'] = DateTime.DateTime(pprops.date3)
71deaddates['sandwich'] = DateTime.DateTime(pprops.date4)
72deaddates['pt'] = DateTime.DateTime(pprops.date5)
73deaddates['dp'] = DateTime.DateTime(pprops.date5)
74deaddates['ct'] = DateTime.DateTime(pprops.date5)
75configuration += ('deaddate',deaddates),
76
77deadline = {}
78for sct in screening_types:
79    deadline[sct] = deaddates[sct].strftime('%A, %d. %B %Y at %I:%M %p')
80configuration += ('deadline',deadline),
81
82confirm = {}
83confirm['pume'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me."
84confirm['pde'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me."
85confirm['prence'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me."
86confirm['pce'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me."
87confirm['cest'] = confirm['sandwich'] = confirm['pt'] = confirm['dp'] = confirm['ct'] = """I hereby acknowledge
88by ticking this check box that if it is discovered
89at any time, that I do not possess any of the qualifications, which I have obtained, I will be
90expelled from the University and shall not be readmitted for the same or any other programme,
91even if I have upgraded my previous qualification or posses additional qualifications."""
92configuration += ('confirm',confirm),
93
94#type_name = 'StudentApplication'
95#ti = context.portal_types[type_name]
96#REQUEST.set('type_name',type_name)
97create = "create" in request.keys()
98apply_admission = "apply" in request.keys()
99edit = "edit" in request.keys() or "cpsdocument_edit_button" in request.form.keys()
100slip = "slip" in request.keys()
101submitted = False
102mode = request.get('mode','')
103if not mode:
104    if apply_admission or edit:
105        mode = "edit"
106    elif slip:
107        mode = "view_slip"
108    else:
109        mode = "create"
110validate = create or edit or apply_admission
111
112without_reg_no = False
113
114
115lt = context.portal_layouts
116object = {}
117pin = 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()
121info = {}
122screening_type = 'pume'
123if traverse_subpath and traverse_subpath[0] in screening_types:
124    screening_type = traverse_subpath[0]
125without_reg_no = screening_type in ('prence','cest','sandwich')
126info['expired'] = current.greaterThan(deaddates[screening_type])
127info['expiration_date'] = deaddates[screening_type]
128info['status'] = object.get('status','')
129info['screening_type'] = screening_type
130layout = "application_%s" % screening_type
131for 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
134reg_no = request.form.get('reg_no','').upper()
135
136if 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')
166info['reg_no'] = reg_no
167
168brains = context.applicants_catalog(reg_no = reg_no.upper())
169if 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())
219info['status'] = object.get('status','')
220
221data = {}
222dm = ds.getDataModel()
223for field in context.applicants_catalog.schema():
224    if dm.has_key("%s" % field):
225        data[field] = dm.get(field)
226data['reg_no'] = reg_no
227
228if 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                                )
266elif 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                                )
286elif 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
307try:
308    passport_uploaded = bool(data['passport'])
309except:
310    passport_uploaded = False
311
312return context.apply_admission_form(rendered = res,
313                                    psm = psm,
314                                    mode = mode,
315                                    show_submit = passport_uploaded,
316                                    ds = ds,
317                                    info = info,
318                              )
Note: See TracBrowser for help on using the repository browser.