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

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

Register pg application layouts and more.

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