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

Last change on this file since 3748 was 3533, checked in by Henrik Bettermann, 17 years ago

open 2008/2009 application

  • Property svn:keywords set to Id
File size: 13.5 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 3533 2008-06-30 18:56:27Z 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 (2007/2008)! '
38headings['pde'] = 'Apply for Post UDE Screening Test (2007/2008)! '
39headings['prence'] = 'Apply for Pre-NCE Programme (2008/2009)! '
40headings['pce'] = 'Apply for PCE Screening (2007/2008)! '
41#headings['cest'] = 'Apply for Part-Time Degree and Diploma Programmes (2007/2008)! '
42headings['cest'] = 'Apply for Diploma Programmes (2007/2008)! '
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 (2007/2008) Aknowledgement Slip!'
49headings_slip['pde'] = 'Post UDE Screening (2007/2008) Aknowledgement Slip'
50headings_slip['prence'] = 'Pre-NCE Application (2008/2009) Aknowledgement Slip'
51headings_slip['pce'] = 'PCE Screening (2007/2008) Aknowledgement Slip'
52headings_slip['cest'] = 'Common Entrance Screening (2007/2008) Aknowledgement Slip'
53headings_slip['sandwich'] = 'Application for Part Time Degree in Education (2007/2008) Aknowledgement Slip'
54#headings_slip['pt'] = 'Part Time (2007/2008) Aknowledgement Slip'
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')
60deaddates['prence'] = DateTime.DateTime('2008/09/30 23:59')
61deaddates['pce'] = DateTime.DateTime('2007/08/12 23:59')
62deaddates['cest'] = DateTime.DateTime('2008/02/15 23:59')
63deaddates['sandwich'] = DateTime.DateTime('2008/06/30 23:59')
64#deaddates['pt'] = DateTime.DateTime('2007/12/24 23:59')
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."
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
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."""
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."""
92configuration += ('confirm',confirm),
93
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()
99edit = "edit" in request.keys() or "cpsdocument_edit_button" in request.form.keys()
100slip = "slip" in request.keys()
101submitted = False
102mode = request.get('mode','')
103if not mode:
104    if apply_admission or edit:
105        mode = "edit"
106    elif slip:
107        mode = "view_slip"
108    else:
109        mode = "create"
110validate = create or edit or apply_admission
111
112without_reg_no = False
113
114
115lt = context.portal_layouts
116object = {}
117pin = request.form.get('pin','')
118# reg_no = request.get('widget__reg_no','').upper()
119# if not reg_no:
120#     reg_no = request.form.get('reg_no','').upper()
121info = {}
122screening_type = 'pume'
123if traverse_subpath and traverse_subpath[0] in screening_types:
124    screening_type = traverse_subpath[0]
125without_reg_no = screening_type in ('prence','cest','sandwich')
126info['expired'] = current.greaterThan(deaddates[screening_type])
127info['expiration_date'] = deaddates[screening_type]
128info['status'] = object.get('status','')
129info['screening_type'] = screening_type
130layout = "application_%s" % screening_type
131for co_name,co_dict in configuration:
132    info[co_name] = co_dict[screening_type]
133#set_trace()
134# the reg_no is a hidden field in the form
135reg_no = request.form.get('reg_no','').upper()
136if not reg_no:
137    # validate form if no reg_no specified
138    res,psm,ds = lt.renderLayout(layout_id= layout,
139                                schema_id= 'import_application',
140                                layout_mode = mode,
141                                context=context,
142                                mapping=validate and REQUEST,
143                                ob={},
144                                commit = False,
145                                )
146    if psm == 'invalid':
147        return context.apply_admission_form(rendered = res,
148                                            psm = "Please correct your input!",
149                                            mode = mode,
150                                            ds = ds,
151                                            info = info,
152                                        )
153    elif psm == '':
154        return context.apply_admission_form(rendered = res,
155                                            psm = psm,
156                                            ds = ds,
157                                            mode = mode,
158                                            info = info,
159                                           )
160    if without_reg_no:
161        reg_no = ds.get('pin_n','').upper()
162    else:
163        reg_no = ds.get('reg_no')
164info['reg_no'] = reg_no
165brains = context.applicants_catalog(reg_no = reg_no.upper())
166if len(brains) == 1:
167    for field in context.applicants_catalog.schema():
168        object[field] = getattr(brains[0],field,None)
169    screening_type = info['screening_type'] = object['screening_type']
170    for co_name,co_dict in configuration:
171        info[co_name] = co_dict[screening_type]
172    if not object['passport']:
173            object['passport'] = ''
174    if object['status'] and ('submitted' in object['status'] or 'admitted' in object['status'] or 'created' in object['status']):
175        submitted = True
176    # cannot happen anymore but anyway
177    #if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()):
178    #    logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
179    #    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
180
181    #rerender with current object = application-record
182
183    if slip:
184        mode = "view_slip"
185        logger.info('%s/%s views application slip' % (member,reg_no))
186
187    res,psm,ds = lt.renderLayout(layout_id= layout,
188                                schema_id= 'import_application',
189                                layout_mode = mode,
190                                context=context,
191                                mapping=validate and REQUEST,
192                                ob=object,
193                                commit = False,
194                                )
195    if slip:
196        return context.apply_admission_slip(rendered = res,
197                                            psm = "",
198                                            mode = mode,
199                                            ds = ds,
200                                            info = info,
201                                           )
202
203    if psm == 'invalid':
204        return context.apply_admission_form(rendered = res,
205                                            psm = "Please correct your input!",
206                                            mode = mode,
207                                            ds = ds,
208                                            info = info,
209                                        )
210    # For the next application session it should be reverted to
211    # (see comment 09/06/07 16:40:52 in ticket #328):
212
213    #if not create and (pin != object['pin'] and not context.isSectionOfficer()):
214        #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
215        #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
216info['status'] = object.get('status','')
217
218data = {}
219dm = ds.getDataModel()
220for field in context.applicants_catalog.schema():
221    if dm.has_key("%s" % field):
222        data[field] = dm.get(field)
223data['reg_no'] = reg_no
224
225if apply_admission:
226    if submitted:
227        mode = "view"
228        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
229        logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
230        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
231        #                         schema_id= 'import_application',
232        #                         layout_mode = mode,
233        #                         context=context,
234        #                         mapping={},
235        #                         ob=object,
236        #                         commit = False,
237        #                         )
238    elif not request.has_key('confirm'):
239        mode = "edit"
240        psm = "Please confirm Passport Photograph!"
241        logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no))
242    else:
243        mode = "view"
244        psm = "You successfully applied for admission!"
245        if object['status'] == 'edited':
246            data['status'] = "submitted"
247            data['application_date'] = current
248            logger.info('%s/%s modified and submitted application record' % (member,reg_no))
249        elif object['status'] == 'reset':
250            data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y')
251            logger.info('%s/%s modified and resubmitted application record' % (member,reg_no))
252        object['status'] = data['status']
253        context.applicants_catalog.modifyRecord(**data)
254        # rerendering neccessary since object changed
255        res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
256                                schema_id= 'import_application',
257                                layout_mode = mode,
258                                context=context,
259                                mapping=validate and REQUEST,
260                                ob=object,
261                                commit = False,
262                                )
263elif create:
264    if submitted:
265        mode = "view"
266        logger.info('%s/%s views application record' % (member,reg_no))
267    else:
268        mode = "edit"
269        logger.info('%s/%s edits application record' % (member,reg_no))
270    psm = ""
271    if without_reg_no:
272        object['reg_no'] = reg_no
273    object['pin'] = str(ds.get('pin'))
274    # rerendering neccessary since object changed
275    res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
276                                schema_id= 'import_application',
277                                layout_mode = mode,
278                                context=context,
279                                mapping={},
280                                ob=object,
281                                commit = False,
282                                )
283elif edit:
284    if submitted:
285        mode = "view"
286        psm = "The form has already been submitted and you are not allowed to modify the data!"
287        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
288        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
289        #                         schema_id= 'import_application',
290        #                         layout_mode = mode,
291        #                         context=context,
292        #                         mapping={},
293        #                         ob=object,
294        #                         commit = False,
295        #                         )
296    else:
297        mode = "edit"
298        psm = "Content changed!"
299        data['status'] = "edited"
300        #set_trace()
301        context.applicants_catalog.modifyRecord(**data)
302        logger.info('%s/%s modified application record' % (member,reg_no))
303
304try:
305    passport_uploaded = bool(data['passport'])
306except:
307    passport_uploaded = False
308
309return context.apply_admission_form(rendered = res,
310                                    psm = psm,
311                                    mode = mode,
312                                    show_submit = passport_uploaded,
313                                    ds = ds,
314                                    info = info,
315                              )
316
Note: See TracBrowser for help on using the repository browser.