source: WAeUP_SRP/base/skins/waeup_student/apply_admission.py @ 3434

Last change on this file since 3434 was 3434, checked in by Henrik Bettermann, 17 years ago

deadline extended

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