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

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

further modifications for session change

  • Property svn:keywords set to Id
File size: 10.7 KB
RevLine 
[2310]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
[477]7##parameters=REQUEST
[2310]8##title=
9##
[486]10# $Id: apply_admission.py 2670 2007-11-15 22:07:14Z henrik $
[477]11"""
12process the Application Form
13"""
[2310]14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
[482]20import DateTime
[2310]21import logging
22logger = logging.getLogger('Skins.apply_admission')
23
24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
26
[482]27current = DateTime.DateTime()
[502]28pr = context.portal_registration
[2310]29request = REQUEST
[482]30
[2310]31#type_name = 'StudentApplication'
32#ti = context.portal_types[type_name]
33#REQUEST.set('type_name',type_name)
34create = "create" in request.keys()
35apply_admission = "apply" in request.keys()
36edit = "edit" in request.keys()
37slip = "slip" in request.keys()
38manage = "manage" in request.keys()
39submitted = False
40mode = request.get('mode','')
41if not mode:
42    if apply_admission or edit or manage:
43        mode = "edit"
44    else:
45        mode = "create"
46validate = create or edit or apply_admission
[482]47
[2310]48if manage:
49    validate = False
50without_reg_no = False
[2323]51
[2324]52
[2310]53lt = context.portal_layouts
[2316]54
55pin = request.form.get('pin','')
[2310]56reg_no = request.get('widget__reg_no','').upper()
57if not reg_no:
58    reg_no = request.form.get('reg_no','').upper()
[2322]59if not reg_no:
60    reg_no = request.get('widget__pin_n','').upper()
[2316]61
[2310]62object = {}
63if reg_no:
64    brains = context.applicants_catalog(reg_no = reg_no)
65    if len(brains) == 1:
66        for field in context.applicants_catalog.schema():
67            object[field] = getattr(brains[0],field,None)
68        if not object['passport']:
69                object['passport'] = ''
[2670]70        if object['status'] and ('submitted' in object['status'] or 'admitted' in object['status'] or 'created' in object['status']):
[2310]71            submitted = True
[477]72
[2310]73        if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()):
74            logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
75            return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
[477]76
[2310]77        # For the next application session it should be reverted to
78        # (see comment 09/06/07 16:40:52 in ticket #328):
79
80        #if not create and (pin != object['pin'] and not context.isSectionOfficer()):
81            #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
82            #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
83
[2328]84
85screening_types = ('prence','pume','pce','pde','cest')
86headings = {}
87headings['pume'] = 'Apply for Post UME Screening Test (2007/2008)! '
[2374]88headings['pde'] = 'Apply for Post UDE Screening Test (2007/2008)! '
[2328]89headings['prence'] = 'Apply for Pre-NCE Programme (2007/2008)! '
90headings['pce'] = 'Apply for PCE Screening (2007/2008)! '
91headings['cest'] = 'Apply for Common Entrance Screening Test (2007/2008)! '
92headings_slip = {}
93headings_slip['pume'] = 'Post UME Screening (2007/2008) Aknowledgement Slip!'
[2374]94headings_slip['pde'] = 'Post UDE Screening (2007/2008) Aknowledgement Slip'
[2328]95headings_slip['prence'] = 'Pre-NCE Application (2007/2008) Aknowledgement Slip'
96headings_slip['pce'] = 'PCE Screening (2007/2008) Aknowledgement Slip'
97headings_slip['cest'] = 'Common Entrance Screening (2007/2008) Aknowledgement Slip'
[2374]98
99deadline = {}
100deadline['pume'] = '[Date of PUME Deadline]'
[2516]101deadline['pde'] = 'Sunday, 4th November 2007'
[2374]102deadline['prence'] = '[Date of PRENCE Deadline]'
103deadline['pce'] = '[Date of PCE Deadline]'
104deadline['cest'] = '[Date of CEST Deadline]'
105
[2328]106info = {}
[2374]107
[2598]108info['status'] = object.get('status','')
[2586]109
[2328]110if traverse_subpath and traverse_subpath[0] in screening_types:
111    screening_type = info['screening_type'] = traverse_subpath[0]
112    info['heading'] = headings[screening_type]
113    info['heading_slip'] = headings_slip[screening_type]
[2374]114    info['deadline'] = deadline[screening_type]
[2328]115    layout = "application_%s" % screening_type
116    without_reg_no = screening_type in ('prence',)
117elif manage:
118    if object['screening_type']:
119        st = object['screening_type']
120    else:
121        st = 'pume'
122    screening_type = info['screening_type'] = st
123    info['heading'] = headings[screening_type]
124    info['heading_slip'] = headings_slip[screening_type]
[2374]125    info['deadline'] = deadline[screening_type]
[2328]126    layout = "application_%s" % screening_type
[2340]127    without_reg_no = screening_type in ('prence',)
[2328]128else:
129    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
130
131
[2310]132if slip:
133    mode = "view_slip"
134    logger.info('%s/%s views application slip' % (member,reg_no))
135
136res,psm,ds = lt.renderLayout(layout_id= layout,
[2518]137                             schema_id= 'import_application',
[2310]138                             layout_mode = mode,
139                             context=context,
140                             mapping=validate and REQUEST,
141                             ob=object,
142                             commit = False,
143                            )
144if slip:
145    return context.apply_admission_slip(rendered = res,
[2323]146                                        psm = "",
147                                        mode = mode,
148                                        ds = ds,
149                                        info = info,
150                                       )
[477]151if psm == 'invalid':
[2310]152    return context.apply_admission_form(rendered = res,
[2323]153                                        psm = "Please correct your input!",
154                                        mode = mode,
155                                        ds = ds,
156                                        info = info,
157                                       )
[2310]158elif psm == '' and not manage:
159    return context.apply_admission_form(rendered = res,
[2323]160                                        psm = psm,
161                                        ds = ds,
162                                        mode = mode,
163                                        info = info,
164                                       )
165# elif psm == 'valid' or (psm == '' and manage):
166#     pass
[2310]167if without_reg_no:
168    reg_no = ds.get('reg_no')
169data = {}
170dm = ds.getDataModel()
171for field in context.applicants_catalog.schema():
172    if dm.has_key("%s" % field):
173        data[field] = dm.get(field)
174data['reg_no'] = reg_no
[2328]175
[2310]176if apply_admission:
177    if submitted:
178        mode = "view"
179        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
180        logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
181        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]182                                schema_id= 'import_application',
[2310]183                                layout_mode = mode,
184                                context=context,
185                                mapping={},
186                                ob=object,
187                                commit = False,
188                                )
189    elif not request.has_key('confirm'):
190        mode = "edit"
191        psm = "Please confirm Passport Photograph!"
192        logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no))
193    else:
194        mode = "view"
195        psm = "You successfully applied for admission!"
196        if object['status'] == 'edited':
197            data['status'] = "submitted"
198            data['application_date'] = current
199            logger.info('%s/%s modified and submitted application record' % (member,reg_no))
200        elif object['status'] == 'reset':
201            data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y')
202            logger.info('%s/%s modified and resubmitted application record' % (member,reg_no))
203        object['status'] = data['status']
204        context.applicants_catalog.modifyRecord(**data)
[477]205
[2310]206        res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
[2518]207                                schema_id= 'import_application',
[2310]208                                layout_mode = mode,
209                                context=context,
210                                mapping=validate and REQUEST,
211                                ob=object,
212                                commit = False,
213                                )
214elif create:
215    if submitted:
216        mode = "view"
217        logger.info('%s/%s views application record' % (member,reg_no))
218    else:
219        mode = "edit"
220        logger.info('%s/%s edits application record' % (member,reg_no))
221    psm = ""
222    if without_reg_no:
223        object['reg_no'] = reg_no
224    object['pin'] = str(ds.get('pin'))
225    res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]226                                schema_id= 'import_application',
[2310]227                                layout_mode = mode,
228                                context=context,
229                                mapping={},
230                                ob=object,
231                                commit = False,
232                                )
233elif edit:
234    if submitted:
235        mode = "view"
236        psm = "The form has already been submitted and you are not allowed to modify the data!"
237        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
238        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]239                                schema_id= 'import_application',
[2310]240                                layout_mode = mode,
241                                context=context,
242                                mapping={},
243                                ob=object,
244                                commit = False,
245                                )
246    else:
247        mode = "edit"
248        psm = "Content changed!"
249        data['status'] = "edited"
[2322]250        #set_trace()
[2310]251        context.applicants_catalog.modifyRecord(**data)
252        logger.info('%s/%s modified application record' % (member,reg_no))
[543]253
[2310]254elif manage:
255    if submitted:
256        mode = "view"
257        psm = "You are now assuming the applicant's role!"
258        logger.info('%s/%s entered application record' % (member,reg_no))
259        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]260                                schema_id= 'import_application',
[2310]261                                layout_mode = mode,
262                                context=context,
263                                mapping={},
264                                ob=object,
265                                commit = False,
266                                )
267    else:
268        mode = "edit"
269        psm = "You are now assuming the applicant's role!"
270        logger.info('%s/%s entered application record' % (member,reg_no))
271
272
273try:
274    passport_uploaded = bool(data['passport'])
275except:
276    passport_uploaded = False
277
278return context.apply_admission_form(rendered = res,
[2323]279                                    psm = psm,
280                                    mode = mode,
281                                    show_submit = passport_uploaded,
282                                    ds = ds,
283                                    info = info,
[2310]284                              )
Note: See TracBrowser for help on using the repository browser.