source: WAeUP_SRP/trunk/skins/waeup_uniben/apply_admission.py @ 3787

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

enable CEST application 2008/2009 (add sex field)

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