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

Last change on this file since 3816 was 3794, checked in by Henrik Bettermann, 16 years ago

new deadlines

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