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

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

new deadlines

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