source: WAeUP_SRP/trunk/skins/waeup_student/apply_admission_2.py @ 11154

Last change on this file since 11154 was 4524, checked in by Henrik Bettermann, 15 years ago

fix 'Aknowledgement' spelling error

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