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

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

fix dp, pt and ct application, improve logging

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