source: WAeUP_SRP/base/skins/waeup_student/apply_admission.py @ 3412

Last change on this file since 3412 was 3412, checked in by joachim, 16 years ago

catch errors in edit mode

  • Property svn:keywords set to Id
File size: 13.8 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 3412 2008-04-03 12:54:05Z joachim $
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
31manage = "manage" in request.keys()
32screening_types = ('prence','pume','pce','pde','cest','sandwich')
33if not (traverse_subpath and traverse_subpath[0] in screening_types) and not manage:
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 (2007/2008)! '
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 (2007/2008) 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('2007/12/4 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/04/09 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 or manage:
105        mode = "edit"
106    elif slip:
107        mode = "view_slip"
108    else:
109        mode = "create"
110validate = create or edit or apply_admission
111
112if manage:
113    validate = False
114without_reg_no = False
115
116
117lt = context.portal_layouts
118object = {}
119pin = request.form.get('pin','')
120# reg_no = request.get('widget__reg_no','').upper()
121# if not reg_no:
122#     reg_no = request.form.get('reg_no','').upper()
123
124
125screening_type = 'pume'
126if traverse_subpath and traverse_subpath[0] in screening_types:
127    screening_type = traverse_subpath[0]
128layout = "application_%s" % screening_type
129info = {}
130without_reg_no = screening_type in ('prence','cest','sandwich')
131info['expired'] = current.greaterThan(deaddates[screening_type])
132info['expiration_date'] = deaddates[screening_type]
133info['status'] = object.get('status','')
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)
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    res,psm,ds = lt.renderLayout(layout_id= layout,
184                                schema_id= 'import_application',
185                                layout_mode = mode,
186                                context=context,
187                                mapping=validate and REQUEST,
188                                ob=object,
189                                commit = False,
190                                )
191    if psm == 'invalid':
192        return context.apply_admission_form(rendered = res,
193                                            psm = "Please correct your input!",
194                                            mode = mode,
195                                            ds = ds,
196                                            info = info,
197                                        )
198    # For the next application session it should be reverted to
199    # (see comment 09/06/07 16:40:52 in ticket #328):
200
201    #if not create and (pin != object['pin'] and not context.isSectionOfficer()):
202        #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
203        #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
204info['status'] = object.get('status','')
205
206data = {}
207dm = ds.getDataModel()
208for field in context.applicants_catalog.schema():
209    if dm.has_key("%s" % field):
210        data[field] = dm.get(field)
211data['reg_no'] = reg_no
212if manage:
213    if submitted:
214        mode = "view"
215        psm = "You are now assuming the applicant's role!"
216        logger.info('%s/%s entered application record' % (member,reg_no))
217        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
218        #                         schema_id= 'import_application',
219        #                         layout_mode = mode,
220        #                         context=context,
221        #                         mapping={},
222        #                         ob=object,
223        #                         commit = False,
224        #                         )
225    else:
226        mode = "edit"
227        psm = "You are now assuming the applicant's role!"
228        logger.info('%s/%s entered application record' % (member,reg_no))
229elif apply_admission:
230    if submitted:
231        mode = "view"
232        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
233        logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
234        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
235        #                         schema_id= 'import_application',
236        #                         layout_mode = mode,
237        #                         context=context,
238        #                         mapping={},
239        #                         ob=object,
240        #                         commit = False,
241        #                         )
242    elif not request.has_key('confirm'):
243        mode = "edit"
244        psm = "Please confirm Passport Photograph!"
245        logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no))
246    else:
247        mode = "view"
248        psm = "You successfully applied for admission!"
249        if object['status'] == 'edited':
250            data['status'] = "submitted"
251            data['application_date'] = current
252            logger.info('%s/%s modified and submitted application record' % (member,reg_no))
253        elif object['status'] == 'reset':
254            data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y')
255            logger.info('%s/%s modified and resubmitted application record' % (member,reg_no))
256        object['status'] = data['status']
257        context.applicants_catalog.modifyRecord(**data)
258        # rerendering neccessary since object changed
259        res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
260                                schema_id= 'import_application',
261                                layout_mode = mode,
262                                context=context,
263                                mapping=validate and REQUEST,
264                                ob=object,
265                                commit = False,
266                                )
267elif create:
268    if submitted:
269        mode = "view"
270        logger.info('%s/%s views application record' % (member,reg_no))
271    else:
272        mode = "edit"
273        logger.info('%s/%s edits application record' % (member,reg_no))
274    psm = ""
275    if without_reg_no:
276        object['reg_no'] = reg_no
277    object['pin'] = str(ds.get('pin'))
278    # rerendering neccessary since object changed
279    res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
280                                schema_id= 'import_application',
281                                layout_mode = mode,
282                                context=context,
283                                mapping={},
284                                ob=object,
285                                commit = False,
286                                )
287elif edit:
288    if submitted:
289        mode = "view"
290        psm = "The form has already been submitted and you are not allowed to modify the data!"
291        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
292        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
293        #                         schema_id= 'import_application',
294        #                         layout_mode = mode,
295        #                         context=context,
296        #                         mapping={},
297        #                         ob=object,
298        #                         commit = False,
299        #                         )
300    else:
301        mode = "edit"
302        psm = "Content changed!"
303        data['status'] = "edited"
304        #set_trace()
305        context.applicants_catalog.modifyRecord(**data)
306        logger.info('%s/%s modified application record' % (member,reg_no))
307
308try:
309    passport_uploaded = bool(data['passport'])
310except:
311    passport_uploaded = False
312
313return context.apply_admission_form(rendered = res,
314                                    psm = psm,
315                                    mode = mode,
316                                    show_submit = passport_uploaded,
317                                    ds = ds,
318                                    info = info,
319                              )
Note: See TracBrowser for help on using the repository browser.