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

Last change on this file since 4097 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
Line 
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
7##parameters=REQUEST
8##title=
9##
10# $Id: apply_admission.py 3836 2009-01-05 09:30:00Z henrik $
11"""
12process the Application Form
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
20import DateTime
21import logging
22logger = logging.getLogger('Skins.apply_admission')
23
24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
26
27current = DateTime.DateTime()
28pr = context.portal_registration
29request = REQUEST
30
31#manage = "manage" in request.keys()
32screening_types = ('prence','pume','pce','pde','cest','sandwich')
33if not (traverse_subpath and traverse_subpath[0] in screening_types):
34    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
35configuration = []
36headings = {}
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)! '
40headings['pce'] = 'Apply for PCE Screening (2007/2008)! '
41headings['cest'] = 'Apply for Part-Time Degree Programmes (2008/2009)! '
42#headings['cest'] = 'Apply for Certificate in Early Child Health (2008/2009)! '
43headings['sandwich'] = 'Apply for Part Time Degree in Education (2007/2008)! '
44#headings['pt'] = 'Apply for Local/Part-Time Programmes (2007/2008)'
45
46configuration += ('heading',headings),
47headings_slip = {}
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'
51headings_slip['pce'] = 'PCE Screening (2007/2008) Aknowledgement Slip'
52#headings_slip['cest'] = 'Common Entrance Screening (2007/2008) Aknowledgement Slip'
53headings_slip['cest'] = 'CEST Application (2008/2009) Aknowledgement Slip'
54headings_slip['sandwich'] = 'Application for Part Time Degree in Education (2007/2008) Aknowledgement Slip'
55#headings_slip['pt'] = 'Part Time (2007/2008) Aknowledgement Slip'
56configuration += ('heading_slip',headings_slip),
57
58deaddates = {}
59
60#config_params = context.getConfigParams()
61#deaddates['pume'] = config_params['dead_pume']
62
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')
66deaddates['pce'] = DateTime.DateTime('2007/08/12 23:59')
67deaddates['cest'] = DateTime.DateTime('2009/01/26 23:59')
68deaddates['sandwich'] = DateTime.DateTime('2008/09/12 23:59')
69#deaddates['pt'] = DateTime.DateTime('2007/12/24 23:59')
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."
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
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."""
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."""
97configuration += ('confirm',confirm),
98
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()
104edit = "edit" in request.keys() or "cpsdocument_edit_button" in request.form.keys()
105slip = "slip" in request.keys()
106submitted = False
107mode = request.get('mode','')
108if not mode:
109    if apply_admission or edit:
110        mode = "edit"
111    elif slip:
112        mode = "view_slip"
113    else:
114        mode = "create"
115validate = create or edit or apply_admission
116
117without_reg_no = False
118
119
120lt = context.portal_layouts
121object = {}
122pin = request.form.get('pin','')
123# reg_no = request.get('widget__reg_no','').upper()
124# if not reg_no:
125#     reg_no = request.form.get('reg_no','').upper()
126info = {}
127screening_type = 'pume'
128if traverse_subpath and traverse_subpath[0] in screening_types:
129    screening_type = traverse_subpath[0]
130without_reg_no = screening_type in ('prence','cest','sandwich')
131info['expired'] = current.greaterThan(deaddates[screening_type])
132info['expiration_date'] = deaddates[screening_type]
133info['status'] = object.get('status','')
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]
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
170brains = context.applicants_catalog(reg_no = reg_no.upper())
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
181    # cannot happen anymore but anyway
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())
185
186    #rerender with current object = application-record
187
188    if slip:
189        mode = "view_slip"
190        logger.info('%s/%s views application slip' % (member,reg_no))
191
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                                )
200    if slip:
201        return context.apply_admission_slip(rendered = res,
202                                            psm = "",
203                                            mode = mode,
204                                            ds = ds,
205                                            info = info,
206                                           )
207
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                                        )
215    # For the next application session it should be reverted to
216    # (see comment 09/06/07 16:40:52 in ticket #328):
217
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
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
229
230if apply_admission:
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))
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        #                         )
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)
259        # rerendering neccessary since object changed
260        res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
261                                schema_id= 'import_application',
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'))
279    # rerendering neccessary since object changed
280    res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
281                                schema_id= 'import_application',
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))
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        #                         )
301    else:
302        mode = "edit"
303        psm = "Content changed!"
304        data['status'] = "edited"
305        #set_trace()
306        context.applicants_catalog.modifyRecord(**data)
307        logger.info('%s/%s modified application record' % (member,reg_no))
308
309try:
310    passport_uploaded = bool(data['passport'])
311except:
312    passport_uploaded = False
313
314return context.apply_admission_form(rendered = res,
315                                    psm = psm,
316                                    mode = mode,
317                                    show_submit = passport_uploaded,
318                                    ds = ds,
319                                    info = info,
320                              )
Note: See TracBrowser for help on using the repository browser.