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

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

implement 2nd choice application (part 1) - completely untested !!!

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