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

Last change on this file since 7940 was 5511, checked in by Henrik Bettermann, 14 years ago

second choice pde application - part2

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