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

Last change on this file since 3409 was 3409, checked in by joachim, 17 years ago

dont show pin, if invalid input

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