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

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

slip_mode wieder eingebaut, war verlorengegangen, bitte testen

  • Property svn:keywords set to Id
File size: 14.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 3416 2008-04-03 16:24:18Z 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
[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()
[3414]123info = {}
[3411]124screening_type = 'pume'
[2328]125if traverse_subpath and traverse_subpath[0] in screening_types:
[3411]126    screening_type = traverse_subpath[0]
[3196]127without_reg_no = screening_type in ('prence','cest','sandwich')
[2739]128info['expired'] = current.greaterThan(deaddates[screening_type])
[3392]129info['expiration_date'] = deaddates[screening_type]
[3411]130info['status'] = object.get('status','')
[3414]131info['screening_type'] = screening_type
132layout = "application_%s" % screening_type
133for co_name,co_dict in configuration:
134    info[co_name] = co_dict[screening_type]
[3411]135#set_trace()
136# the reg_no is a hidden field in the form
137reg_no = request.form.get('reg_no','').upper()
138if not reg_no:
139    # validate form if no reg_no specified
140    res,psm,ds = lt.renderLayout(layout_id= layout,
141                                schema_id= 'import_application',
142                                layout_mode = mode,
143                                context=context,
144                                mapping=validate and REQUEST,
145                                ob={},
146                                commit = False,
147                                )
148    if psm == 'invalid':
149        return context.apply_admission_form(rendered = res,
150                                            psm = "Please correct your input!",
151                                            mode = mode,
152                                            ds = ds,
153                                            info = info,
154                                        )
155    elif psm == '':
156        return context.apply_admission_form(rendered = res,
157                                            psm = psm,
158                                            ds = ds,
159                                            mode = mode,
160                                            info = info,
161                                           )
162    if without_reg_no:
163        reg_no = ds.get('pin_n','').upper()
164    else:
165        reg_no = ds.get('reg_no')
166info['reg_no'] = reg_no
167brains = context.applicants_catalog(reg_no = reg_no)
168if len(brains) == 1:
169    for field in context.applicants_catalog.schema():
170        object[field] = getattr(brains[0],field,None)
171    screening_type = info['screening_type'] = object['screening_type']
172    for co_name,co_dict in configuration:
173        info[co_name] = co_dict[screening_type]
174    if not object['passport']:
175            object['passport'] = ''
176    if object['status'] and ('submitted' in object['status'] or 'admitted' in object['status'] or 'created' in object['status']):
177        submitted = True
[3416]178    # cannot happen anymore but anyway
[3411]179    if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()):
180        logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
181        return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
[2739]182
[3411]183    #rerender with current object = application-record
[3416]184   
185    if slip:
186        mode = "view_slip"
187        logger.info('%s/%s views application slip' % (member,reg_no))
188   
[3411]189    res,psm,ds = lt.renderLayout(layout_id= layout,
190                                schema_id= 'import_application',
191                                layout_mode = mode,
192                                context=context,
193                                mapping=validate and REQUEST,
194                                ob=object,
195                                commit = False,
196                                )
[3416]197    if slip:
198        return context.apply_admission_slip(rendered = res,
199                                            psm = "",
200                                            mode = mode,
201                                            ds = ds,
202                                            info = info,
203                                           )                               
204                               
[3412]205    if psm == 'invalid':
206        return context.apply_admission_form(rendered = res,
207                                            psm = "Please correct your input!",
208                                            mode = mode,
209                                            ds = ds,
210                                            info = info,
211                                        )
[3411]212    # For the next application session it should be reverted to
213    # (see comment 09/06/07 16:40:52 in ticket #328):
[2310]214
[3411]215    #if not create and (pin != object['pin'] and not context.isSectionOfficer()):
216        #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
217        #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
218info['status'] = object.get('status','')
219
[2310]220data = {}
221dm = ds.getDataModel()
222for field in context.applicants_catalog.schema():
223    if dm.has_key("%s" % field):
224        data[field] = dm.get(field)
225data['reg_no'] = reg_no
[3411]226if manage:
[2310]227    if submitted:
228        mode = "view"
[3411]229        psm = "You are now assuming the applicant's role!"
230        logger.info('%s/%s entered application record' % (member,reg_no))
231        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
232        #                         schema_id= 'import_application',
233        #                         layout_mode = mode,
234        #                         context=context,
235        #                         mapping={},
236        #                         ob=object,
237        #                         commit = False,
238        #                         )
239    else:
240        mode = "edit"
241        psm = "You are now assuming the applicant's role!"
242        logger.info('%s/%s entered application record' % (member,reg_no))
243elif apply_admission:
244    if submitted:
245        mode = "view"
[2310]246        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
247        logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
[3411]248        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
249        #                         schema_id= 'import_application',
250        #                         layout_mode = mode,
251        #                         context=context,
252        #                         mapping={},
253        #                         ob=object,
254        #                         commit = False,
255        #                         )
[2310]256    elif not request.has_key('confirm'):
257        mode = "edit"
258        psm = "Please confirm Passport Photograph!"
259        logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no))
260    else:
261        mode = "view"
262        psm = "You successfully applied for admission!"
263        if object['status'] == 'edited':
264            data['status'] = "submitted"
265            data['application_date'] = current
266            logger.info('%s/%s modified and submitted application record' % (member,reg_no))
267        elif object['status'] == 'reset':
268            data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y')
269            logger.info('%s/%s modified and resubmitted application record' % (member,reg_no))
270        object['status'] = data['status']
271        context.applicants_catalog.modifyRecord(**data)
[3411]272        # rerendering neccessary since object changed
[2310]273        res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
[2518]274                                schema_id= 'import_application',
[2310]275                                layout_mode = mode,
276                                context=context,
277                                mapping=validate and REQUEST,
278                                ob=object,
279                                commit = False,
280                                )
281elif create:
282    if submitted:
283        mode = "view"
284        logger.info('%s/%s views application record' % (member,reg_no))
285    else:
286        mode = "edit"
287        logger.info('%s/%s edits application record' % (member,reg_no))
288    psm = ""
289    if without_reg_no:
290        object['reg_no'] = reg_no
291    object['pin'] = str(ds.get('pin'))
[3411]292    # rerendering neccessary since object changed
[2310]293    res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
[2518]294                                schema_id= 'import_application',
[2310]295                                layout_mode = mode,
296                                context=context,
297                                mapping={},
298                                ob=object,
299                                commit = False,
300                                )
301elif edit:
302    if submitted:
303        mode = "view"
304        psm = "The form has already been submitted and you are not allowed to modify the data!"
305        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
[3411]306        # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
307        #                         schema_id= 'import_application',
308        #                         layout_mode = mode,
309        #                         context=context,
310        #                         mapping={},
311        #                         ob=object,
312        #                         commit = False,
313        #                         )
[2310]314    else:
315        mode = "edit"
316        psm = "Content changed!"
317        data['status'] = "edited"
[2322]318        #set_trace()
[2310]319        context.applicants_catalog.modifyRecord(**data)
320        logger.info('%s/%s modified application record' % (member,reg_no))
[543]321
[2310]322try:
323    passport_uploaded = bool(data['passport'])
324except:
325    passport_uploaded = False
326
327return context.apply_admission_form(rendered = res,
[2323]328                                    psm = psm,
329                                    mode = mode,
330                                    show_submit = passport_uploaded,
331                                    ds = ds,
332                                    info = info,
[2310]333                              )
Note: See TracBrowser for help on using the repository browser.