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

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