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

Last change on this file since 3394 was 3394, checked in by joachim, 16 years ago

remove expiration-date parameter (not used)

  • Property svn:keywords set to Id
File size: 13.1 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 3394 2008-03-28 10:11:45Z joachim $
[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
[2739]31manage = "manage" in request.keys()
[3196]32screening_types = ('prence','pume','pce','pde','cest','sandwich')
[2739]33if not (traverse_subpath and traverse_subpath[0] in screening_types) and not manage:
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')
[3342]63deaddates['sandwich'] = DateTime.DateTime('2008/04/09 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:
104    if apply_admission or edit or manage:
105        mode = "edit"
106    else:
107        mode = "create"
108validate = create or edit or apply_admission
[482]109
[2310]110if manage:
111    validate = False
112without_reg_no = False
[2323]113
[2324]114
[2310]115lt = context.portal_layouts
[2316]116
117pin = request.form.get('pin','')
[2310]118reg_no = request.get('widget__reg_no','').upper()
119if not reg_no:
120    reg_no = request.form.get('reg_no','').upper()
[2322]121if not reg_no:
122    reg_no = request.get('widget__pin_n','').upper()
[2316]123
[2310]124object = {}
125if reg_no:
126    brains = context.applicants_catalog(reg_no = reg_no)
127    if len(brains) == 1:
128        for field in context.applicants_catalog.schema():
129            object[field] = getattr(brains[0],field,None)
130        if not object['passport']:
131                object['passport'] = ''
[2670]132        if object['status'] and ('submitted' in object['status'] or 'admitted' in object['status'] or 'created' in object['status']):
[2310]133            submitted = True
[477]134
[2310]135        if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()):
136            logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
137            return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
[477]138
[2310]139        # For the next application session it should be reverted to
140        # (see comment 09/06/07 16:40:52 in ticket #328):
141
142        #if not create and (pin != object['pin'] and not context.isSectionOfficer()):
143            #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
144            #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
145
[2328]146
[2374]147
[2328]148info = {}
[2374]149
[2598]150info['status'] = object.get('status','')
[2328]151if traverse_subpath and traverse_subpath[0] in screening_types:
152    screening_type = info['screening_type'] = traverse_subpath[0]
153elif manage:
154    if object['screening_type']:
155        st = object['screening_type']
156    else:
157        st = 'pume'
158    screening_type = info['screening_type'] = st
159
[2739]160for co_name,co_dict in configuration:
161    info[co_name] = co_dict[screening_type]
162layout = "application_%s" % screening_type
[3196]163without_reg_no = screening_type in ('prence','cest','sandwich')
[2739]164info['expired'] = current.greaterThan(deaddates[screening_type])
[3392]165info['expiration_date'] = deaddates[screening_type]
[2328]166
[2739]167
[2310]168if slip:
169    mode = "view_slip"
170    logger.info('%s/%s views application slip' % (member,reg_no))
171
172res,psm,ds = lt.renderLayout(layout_id= layout,
[2518]173                             schema_id= 'import_application',
[2310]174                             layout_mode = mode,
175                             context=context,
176                             mapping=validate and REQUEST,
177                             ob=object,
178                             commit = False,
179                            )
180if slip:
181    return context.apply_admission_slip(rendered = res,
[2323]182                                        psm = "",
183                                        mode = mode,
184                                        ds = ds,
185                                        info = info,
186                                       )
[477]187if psm == 'invalid':
[2310]188    return context.apply_admission_form(rendered = res,
[2323]189                                        psm = "Please correct your input!",
190                                        mode = mode,
191                                        ds = ds,
192                                        info = info,
193                                       )
[2310]194elif psm == '' and not manage:
195    return context.apply_admission_form(rendered = res,
[2323]196                                        psm = psm,
197                                        ds = ds,
198                                        mode = mode,
199                                        info = info,
200                                       )
201# elif psm == 'valid' or (psm == '' and manage):
202#     pass
[2310]203if without_reg_no:
204    reg_no = ds.get('reg_no')
205data = {}
206dm = ds.getDataModel()
207for field in context.applicants_catalog.schema():
208    if dm.has_key("%s" % field):
209        data[field] = dm.get(field)
210data['reg_no'] = reg_no
211if apply_admission:
212    if submitted:
213        mode = "view"
214        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
215        logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
216        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]217                                schema_id= 'import_application',
[2310]218                                layout_mode = mode,
219                                context=context,
220                                mapping={},
221                                ob=object,
222                                commit = False,
223                                )
224    elif not request.has_key('confirm'):
225        mode = "edit"
226        psm = "Please confirm Passport Photograph!"
227        logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no))
228    else:
229        mode = "view"
230        psm = "You successfully applied for admission!"
231        if object['status'] == 'edited':
232            data['status'] = "submitted"
233            data['application_date'] = current
234            logger.info('%s/%s modified and submitted application record' % (member,reg_no))
235        elif object['status'] == 'reset':
236            data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y')
237            logger.info('%s/%s modified and resubmitted application record' % (member,reg_no))
238        object['status'] = data['status']
239        context.applicants_catalog.modifyRecord(**data)
[477]240
[2310]241        res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
[2518]242                                schema_id= 'import_application',
[2310]243                                layout_mode = mode,
244                                context=context,
245                                mapping=validate and REQUEST,
246                                ob=object,
247                                commit = False,
248                                )
249elif create:
250    if submitted:
251        mode = "view"
252        logger.info('%s/%s views application record' % (member,reg_no))
253    else:
254        mode = "edit"
255        logger.info('%s/%s edits application record' % (member,reg_no))
256    psm = ""
257    if without_reg_no:
258        object['reg_no'] = reg_no
259    object['pin'] = str(ds.get('pin'))
260    res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]261                                schema_id= 'import_application',
[2310]262                                layout_mode = mode,
263                                context=context,
264                                mapping={},
265                                ob=object,
266                                commit = False,
267                                )
268elif edit:
[2739]269    #set_trace()
[2310]270    if submitted:
271        mode = "view"
272        psm = "The form has already been submitted and you are not allowed to modify the data!"
273        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
274        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]275                                schema_id= 'import_application',
[2310]276                                layout_mode = mode,
277                                context=context,
278                                mapping={},
279                                ob=object,
280                                commit = False,
281                                )
282    else:
283        mode = "edit"
284        psm = "Content changed!"
285        data['status'] = "edited"
[2322]286        #set_trace()
[2310]287        context.applicants_catalog.modifyRecord(**data)
288        logger.info('%s/%s modified application record' % (member,reg_no))
[543]289
[2310]290elif manage:
291    if submitted:
292        mode = "view"
293        psm = "You are now assuming the applicant's role!"
294        logger.info('%s/%s entered application record' % (member,reg_no))
295        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]296                                schema_id= 'import_application',
[2310]297                                layout_mode = mode,
298                                context=context,
299                                mapping={},
300                                ob=object,
301                                commit = False,
302                                )
303    else:
304        mode = "edit"
305        psm = "You are now assuming the applicant's role!"
306        logger.info('%s/%s entered application record' % (member,reg_no))
307
308
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.