source: WAeUP_SRP/trunk/skins/waeup_student/apply_admission.py @ 4335

Last change on this file since 4335 was 4241, checked in by Henrik Bettermann, 16 years ago

fix last revision

  • 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 4241 2009-06-10 07:35:29Z 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
[4099]29pprops = context.portal_properties
[2310]30request = REQUEST
[482]31
[3426]32#manage = "manage" in request.keys()
[4241]33screening_types = ('prence','pume','pce','pde','cest','sandwich','dp','ct','pt')
[3426]34if not (traverse_subpath and traverse_subpath[0] in screening_types):
[2739]35    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
36configuration = []
37headings = {}
[4240]38headings['pume'] = 'Apply for Post UME Screening Test (2009/2010)! '
39headings['pde'] = 'Apply for Post UDE Screening Test (2009/2010)! '
[3791]40headings['prence'] = 'Apply for Pre-NCE Programme (2007/2008)! '
[2739]41headings['pce'] = 'Apply for PCE Screening (2007/2008)! '
[4099]42headings['cest'] = 'Apply for Part-Time Degree or Diploma Programmes (2008/2009)! '
[4240]43headings['pt'] = 'Apply for Part-Time Degree (2009/2010)! '
44headings['dp'] = 'Apply for Diploma Programmes (2009/2010)! '
45headings['ct'] = 'Apply for Certificate Programmes (2009/2010)! '
[4116]46headings['sandwich'] = 'Apply for Part Time Degree in Education (2008/2009)! '
[4240]47configuration += ('heading',headings),
[2739]48
49headings_slip = {}
[4240]50headings_slip['pume'] = 'Post UME Screening (2009/2010) Aknowledgement Slip!'
51headings_slip['pde'] = 'Post UDE Screening (2009/2010) Aknowledgement Slip'
[3791]52headings_slip['prence'] = 'Pre-NCE Application (2007/2008) Aknowledgement Slip'
[2739]53headings_slip['pce'] = 'PCE Screening (2007/2008) Aknowledgement Slip'
[3791]54headings_slip['cest'] = 'CEST Application (2008/2009) Aknowledgement Slip'
[4241]55headings_slip['pt'] = 'Part-Time Degree Application (2009/2010) Aknowledgement Slip'
56headings_slip['dp'] = 'Diploma Programme Application (2009/2010) Aknowledgement Slip'
57headings_slip['ct'] = 'Certificate Programme Application (2009/2010) Aknowledgement Slip'
[4116]58headings_slip['sandwich'] = 'Application for Part Time Degree in Education (2008/2009) Aknowledgement Slip'
[2739]59configuration += ('heading_slip',headings_slip),
60
61deaddates = {}
[3824]62
63#config_params = context.getConfigParams()
64#deaddates['pume'] = config_params['dead_pume']
65
[4099]66deaddates['pume'] = DateTime.DateTime(pprops.date1)
67deaddates['pde'] = DateTime.DateTime(pprops.date2)
[4121]68deaddates['prence'] = DateTime.DateTime(pprops.date1)
[3028]69deaddates['pce'] = DateTime.DateTime('2007/08/12 23:59')
[4099]70deaddates['cest'] = DateTime.DateTime(pprops.date3)
71deaddates['sandwich'] = DateTime.DateTime(pprops.date4)
[4240]72deaddates['pt'] = DateTime.DateTime(pprops.date5)
73deaddates['dp'] = DateTime.DateTime(pprops.date5)
[4241]74deaddates['ct'] = DateTime.DateTime(pprops.date5)
[2739]75configuration += ('deaddate',deaddates),
76
77deadline = {}
78for sct in screening_types:
79    deadline[sct] = deaddates[sct].strftime('%A, %d. %B %Y')
80configuration += ('deadline',deadline),
81
82confirm = {}
83confirm['pume'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me."
84confirm['pde'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me."
85confirm['prence'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me."
86confirm['pce'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me."
[4240]87confirm['cest'] = confirm['sandwich'] = confirm['pt'] = confirm['dp'] = confirm['ct'] = """I hereby acknowledge
88by ticking this check box that if it is discovered
[2739]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
[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:
[3426]104    if apply_admission or edit:
[2310]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]112without_reg_no = False
[2323]113
[2324]114
[2310]115lt = context.portal_layouts
[3411]116object = {}
[2316]117pin = request.form.get('pin','')
[3409]118# reg_no = request.get('widget__reg_no','').upper()
119# if not reg_no:
120#     reg_no = request.form.get('reg_no','').upper()
[3414]121info = {}
[3411]122screening_type = 'pume'
[2328]123if traverse_subpath and traverse_subpath[0] in screening_types:
[3411]124    screening_type = traverse_subpath[0]
[3196]125without_reg_no = screening_type in ('prence','cest','sandwich')
[2739]126info['expired'] = current.greaterThan(deaddates[screening_type])
[3392]127info['expiration_date'] = deaddates[screening_type]
[3411]128info['status'] = object.get('status','')
[3414]129info['screening_type'] = screening_type
130layout = "application_%s" % screening_type
131for co_name,co_dict in configuration:
132    info[co_name] = co_dict[screening_type]
[3411]133# the reg_no is a hidden field in the form
134reg_no = request.form.get('reg_no','').upper()
[4121]135
[3411]136if not reg_no:
137    # validate form if no reg_no specified
138    res,psm,ds = lt.renderLayout(layout_id= layout,
139                                schema_id= 'import_application',
140                                layout_mode = mode,
141                                context=context,
142                                mapping=validate and REQUEST,
143                                ob={},
144                                commit = False,
145                                )
146    if psm == 'invalid':
147        return context.apply_admission_form(rendered = res,
148                                            psm = "Please correct your input!",
149                                            mode = mode,
150                                            ds = ds,
151                                            info = info,
152                                        )
153    elif psm == '':
154        return context.apply_admission_form(rendered = res,
155                                            psm = psm,
156                                            ds = ds,
157                                            mode = mode,
158                                            info = info,
159                                           )
160    if without_reg_no:
[4121]161        ## see fceokene #147
[3411]162        reg_no = ds.get('pin_n','').upper()
[4121]163        #reg_no = ds.get('pin_p') + ds.get('pin_b') + ds.get('pin_n')
[3411]164    else:
165        reg_no = ds.get('reg_no')
166info['reg_no'] = reg_no
[4121]167
[3472]168brains = context.applicants_catalog(reg_no = reg_no.upper())
[3411]169if len(brains) == 1:
170    for field in context.applicants_catalog.schema():
171        object[field] = getattr(brains[0],field,None)
172    screening_type = info['screening_type'] = object['screening_type']
173    for co_name,co_dict in configuration:
174        info[co_name] = co_dict[screening_type]
175    if not object['passport']:
176            object['passport'] = ''
177    if object['status'] and ('submitted' in object['status'] or 'admitted' in object['status'] or 'created' in object['status']):
178        submitted = True
[3416]179    # cannot happen anymore but anyway
[3426]180    #if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()):
181    #    logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
182    #    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
[2739]183
[3411]184    #rerender with current object = application-record
[3426]185
[3416]186    if slip:
187        mode = "view_slip"
188        logger.info('%s/%s views application slip' % (member,reg_no))
[3426]189
[3411]190    res,psm,ds = lt.renderLayout(layout_id= layout,
191                                schema_id= 'import_application',
192                                layout_mode = mode,
193                                context=context,
194                                mapping=validate and REQUEST,
195                                ob=object,
196                                commit = False,
197                                )
[3416]198    if slip:
199        return context.apply_admission_slip(rendered = res,
200                                            psm = "",
201                                            mode = mode,
202                                            ds = ds,
203                                            info = info,
[3426]204                                           )
205
[3412]206    if psm == 'invalid':
207        return context.apply_admission_form(rendered = res,
208                                            psm = "Please correct your input!",
209                                            mode = mode,
210                                            ds = ds,
211                                            info = info,
212                                        )
[3411]213    # For the next application session it should be reverted to
214    # (see comment 09/06/07 16:40:52 in ticket #328):
[2310]215
[3411]216    #if not create and (pin != object['pin'] and not context.isSectionOfficer()):
217        #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
218        #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
219info['status'] = object.get('status','')
220
[2310]221data = {}
222dm = ds.getDataModel()
223for field in context.applicants_catalog.schema():
224    if dm.has_key("%s" % field):
225        data[field] = dm.get(field)
226data['reg_no'] = reg_no
[3426]227
228if apply_admission:
[2310]229    if submitted:
230        mode = "view"
231        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
232        logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
[3411]233        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
234        #                         schema_id= 'import_application',
235        #                         layout_mode = mode,
236        #                         context=context,
237        #                         mapping={},
238        #                         ob=object,
239        #                         commit = False,
240        #                         )
[2310]241    elif not request.has_key('confirm'):
242        mode = "edit"
243        psm = "Please confirm Passport Photograph!"
244        logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no))
245    else:
246        mode = "view"
247        psm = "You successfully applied for admission!"
248        if object['status'] == 'edited':
249            data['status'] = "submitted"
250            data['application_date'] = current
251            logger.info('%s/%s modified and submitted application record' % (member,reg_no))
252        elif object['status'] == 'reset':
253            data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y')
254            logger.info('%s/%s modified and resubmitted application record' % (member,reg_no))
255        object['status'] = data['status']
256        context.applicants_catalog.modifyRecord(**data)
[3411]257        # rerendering neccessary since object changed
[2310]258        res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
[2518]259                                schema_id= 'import_application',
[2310]260                                layout_mode = mode,
261                                context=context,
262                                mapping=validate and REQUEST,
263                                ob=object,
264                                commit = False,
265                                )
266elif create:
267    if submitted:
268        mode = "view"
269        logger.info('%s/%s views application record' % (member,reg_no))
270    else:
271        mode = "edit"
272        logger.info('%s/%s edits application record' % (member,reg_no))
273    psm = ""
274    if without_reg_no:
275        object['reg_no'] = reg_no
276    object['pin'] = str(ds.get('pin'))
[3411]277    # rerendering neccessary since object changed
[2310]278    res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]279                                schema_id= 'import_application',
[2310]280                                layout_mode = mode,
281                                context=context,
282                                mapping={},
283                                ob=object,
284                                commit = False,
285                                )
286elif edit:
287    if submitted:
288        mode = "view"
289        psm = "The form has already been submitted and you are not allowed to modify the data!"
290        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
[3411]291        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
292        #                         schema_id= 'import_application',
293        #                         layout_mode = mode,
294        #                         context=context,
295        #                         mapping={},
296        #                         ob=object,
297        #                         commit = False,
298        #                         )
[2310]299    else:
300        mode = "edit"
301        psm = "Content changed!"
302        data['status'] = "edited"
[2322]303        #set_trace()
[2310]304        context.applicants_catalog.modifyRecord(**data)
305        logger.info('%s/%s modified application record' % (member,reg_no))
[543]306
[2310]307try:
308    passport_uploaded = bool(data['passport'])
309except:
310    passport_uploaded = False
311
312return context.apply_admission_form(rendered = res,
[2323]313                                    psm = psm,
314                                    mode = mode,
315                                    show_submit = passport_uploaded,
316                                    ds = ds,
317                                    info = info,
[2310]318                              )
Note: See TracBrowser for help on using the repository browser.