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

Last change on this file since 7966 was 7961, checked in by Henrik Bettermann, 13 years ago

Two new screening types: pg_ft and pg_pt

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