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
RevLine 
[2310]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
[477]7##parameters=REQUEST
[2310]8##title=
9##
[486]10# $Id: apply_admission.py 5186 2010-05-10 16:12:04Z henrik $
[477]11"""
12process the Application Form
13"""
[2310]14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
[482]20import DateTime
[2310]21import logging
22logger = logging.getLogger('Skins.apply_admission')
23
24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
26
[482]27current = DateTime.DateTime()
[502]28pr = context.portal_registration
[4099]29pprops = context.portal_properties
[2310]30request = REQUEST
[482]31
[3426]32#manage = "manage" in request.keys()
[5165]33screening_types = ('prence','pume','pce','pde','cest','sandwich','dp','ct','pt','sandwich2008')
[3426]34if not (traverse_subpath and traverse_subpath[0] in screening_types):
[2739]35    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
36configuration = []
37headings = {}
[4240]38headings['pume'] = 'Apply for Post UME Screening Test (2009/2010)! '
39headings['pde'] = 'Apply for Post UDE Screening Test (2009/2010)! '
[3791]40headings['prence'] = 'Apply for Pre-NCE Programme (2007/2008)! '
[4542]41headings['pce'] = 'Apply for PCE Screening (2009/2010)! '
[5165]42headings['sandwich2008'] = 'Apply for Part Time Degree in Education (2008/2009)! '
[5186]43headings['cest'] = 'Apply for Part-Time Degree Programmes (2009/2010)! '
44headings['pt'] = 'Apply for Part-Time Degree Programmes (2009/2010)! '
[4240]45headings['dp'] = 'Apply for Diploma Programmes (2009/2010)! '
46headings['ct'] = 'Apply for Certificate Programmes (2009/2010)! '
[5165]47headings['sandwich'] = 'Apply for Part Time Degree in Education (2009/2010)! '
[4240]48configuration += ('heading',headings),
[2739]49
50headings_slip = {}
[4524]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'
[4542]54headings_slip['pce'] = 'PCE Screening (2009/2010) Acknowledgement Slip'
[5165]55headings_slip['sandwich2008'] = 'Application for Part Time Degree in Education (2008/2009) Acknowledgement Slip'
56headings_slip['cest'] = 'CEST Application (2009/2010) Acknowledgement Slip'
[4524]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'
[5165]60headings_slip['sandwich'] = 'Application for Part Time Degree in Education (2009/2010) Acknowledgement Slip'
[2739]61configuration += ('heading_slip',headings_slip),
62
63deaddates = {}
[3824]64
65#config_params = context.getConfigParams()
66#deaddates['pume'] = config_params['dead_pume']
67
[4099]68deaddates['pume'] = DateTime.DateTime(pprops.date1)
69deaddates['pde'] = DateTime.DateTime(pprops.date2)
[4121]70deaddates['prence'] = DateTime.DateTime(pprops.date1)
[4542]71deaddates['pce'] = DateTime.DateTime(pprops.date5)
[5165]72deaddates['sandwich2008'] = DateTime.DateTime(pprops.date1)  #is expired like pume
[4099]73deaddates['cest'] = DateTime.DateTime(pprops.date3)
74deaddates['sandwich'] = DateTime.DateTime(pprops.date4)
[4240]75deaddates['pt'] = DateTime.DateTime(pprops.date5)
76deaddates['dp'] = DateTime.DateTime(pprops.date5)
[4241]77deaddates['ct'] = DateTime.DateTime(pprops.date5)
[2739]78configuration += ('deaddate',deaddates),
79
80deadline = {}
81for sct in screening_types:
[4388]82    deadline[sct] = deaddates[sct].strftime('%A, %d. %B %Y at %I:%M %p')
[2739]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."
[5165]90confirm['cest'] = confirm['sandwich'] = confirm['pt'] = confirm['dp'] = confirm['ct'] = confirm['sandwich2008'] = """I hereby acknowledge
[4240]91by ticking this check box that if it is discovered
[2739]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
[2310]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()
[2739]102edit = "edit" in request.keys() or "cpsdocument_edit_button" in request.form.keys()
[2310]103slip = "slip" in request.keys()
104submitted = False
105mode = request.get('mode','')
106if not mode:
[3426]107    if apply_admission or edit:
[2310]108        mode = "edit"
[3411]109    elif slip:
110        mode = "view_slip"
[2310]111    else:
112        mode = "create"
113validate = create or edit or apply_admission
[482]114
[2310]115without_reg_no = False
[2323]116
[2324]117
[2310]118lt = context.portal_layouts
[3411]119object = {}
[2316]120pin = request.form.get('pin','')
[3409]121# reg_no = request.get('widget__reg_no','').upper()
122# if not reg_no:
123#     reg_no = request.form.get('reg_no','').upper()
[3414]124info = {}
[3411]125screening_type = 'pume'
[2328]126if traverse_subpath and traverse_subpath[0] in screening_types:
[3411]127    screening_type = traverse_subpath[0]
[5186]128without_reg_no = screening_type in ('prence','cest','sandwich','sandwich2008','dp','pt','ct')
[2739]129info['expired'] = current.greaterThan(deaddates[screening_type])
[3392]130info['expiration_date'] = deaddates[screening_type]
[3411]131info['status'] = object.get('status','')
[3414]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]
[3411]136# the reg_no is a hidden field in the form
137reg_no = request.form.get('reg_no','').upper()
[4121]138
[3411]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:
[4121]164        ## see fceokene #147
[5165]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')
[3411]169    else:
170        reg_no = ds.get('reg_no')
171info['reg_no'] = reg_no
[4121]172
[3472]173brains = context.applicants_catalog(reg_no = reg_no.upper())
[3411]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
[3416]184    # cannot happen anymore but anyway
[3426]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())
[2739]188
[3411]189    #rerender with current object = application-record
[3426]190
[3416]191    if slip:
192        mode = "view_slip"
193        logger.info('%s/%s views application slip' % (member,reg_no))
[3426]194
[3411]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                                )
[3416]203    if slip:
204        return context.apply_admission_slip(rendered = res,
205                                            psm = "",
206                                            mode = mode,
207                                            ds = ds,
208                                            info = info,
[3426]209                                           )
210
[3412]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                                        )
[3411]218    # For the next application session it should be reverted to
219    # (see comment 09/06/07 16:40:52 in ticket #328):
[2310]220
[3411]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
[2310]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
[3426]232
233if apply_admission:
[2310]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))
[3411]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        #                         )
[2310]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)
[3411]262        # rerendering neccessary since object changed
[2310]263        res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
[2518]264                                schema_id= 'import_application',
[2310]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"
[5186]274        logger.info('%s/%s is viewing application record' % (member,reg_no))
[2310]275    else:
276        mode = "edit"
[5186]277        logger.info('%s/%s started editing application record' % (member,reg_no))
[2310]278    psm = ""
279    if without_reg_no:
280        object['reg_no'] = reg_no
281    object['pin'] = str(ds.get('pin'))
[3411]282    # rerendering neccessary since object changed
[2310]283    res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]284                                schema_id= 'import_application',
[2310]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))
[3411]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        #                         )
[2310]304    else:
305        mode = "edit"
306        psm = "Content changed!"
307        data['status'] = "edited"
[2322]308        #set_trace()
[2310]309        context.applicants_catalog.modifyRecord(**data)
310        logger.info('%s/%s modified application record' % (member,reg_no))
[543]311
[2310]312try:
313    passport_uploaded = bool(data['passport'])
314except:
315    passport_uploaded = False
316
317return context.apply_admission_form(rendered = res,
[2323]318                                    psm = psm,
319                                    mode = mode,
320                                    show_submit = passport_uploaded,
321                                    ds = ds,
322                                    info = info,
[2310]323                              )
Note: See TracBrowser for help on using the repository browser.