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

Last change on this file since 5786 was 5511, checked in by Henrik Bettermann, 14 years ago

second choice pde application - part2

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