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

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

new cest application layout beautified

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