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

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

new structure should work better

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