source: WAeUP_SRP/trunk/skins/waeup_fceokene/apply_admission.py @ 6863

Last change on this file since 6863 was 6614, checked in by Henrik Bettermann, 13 years ago

Open PCE and Pre-NCE application.

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