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

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

Register pg application layouts and more.

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