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

Last change on this file since 7961 was 7961, checked in by Henrik Bettermann, 13 years ago

Two new screening types: pg_ft and pg_pt

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