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

Last change on this file since 3157 was 3130, checked in by Henrik Bettermann, 17 years ago

extend CEST deadline

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