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

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

make apply_pume work (not yet finished)

  • Property svn:keywords set to Id
File size: 9.7 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 2322 2007-10-06 08:04:42Z 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
29request = REQUEST
30
31#type_name = 'StudentApplication'
32#ti = context.portal_types[type_name]
33#REQUEST.set('type_name',type_name)
34create = "create" in request.keys()
35apply_admission = "apply" in request.keys()
36edit = "edit" in request.keys()
37slip = "slip" in request.keys()
38manage = "manage" in request.keys()
39submitted = False
40mode = request.get('mode','')
41if not mode:
42    if apply_admission or edit or manage:
43        mode = "edit"
44    else:
45        mode = "create"
46validate = create or edit or apply_admission
47
48if manage:
49    validate = False
50#layout = "application_pume"
51#application_type = ""
52without_reg_no = False
53if traverse_subpath and traverse_subpath[0] == "prence":
54    layout = "application_prence"
55    application_type = "prence"
56    without_reg_no = True
57elif traverse_subpath and traverse_subpath[0] == "pume":
58    layout = "application_pume"
59    application_type = "pume"
60elif traverse_subpath and traverse_subpath[0] == "pce":
61    layout = "application_pce"
62    application_type = "pce"
63elif traverse_subpath and traverse_subpath[0] == "pde":
64    layout = "application_pde"
65    application_type = "pde"
66elif traverse_subpath and traverse_subpath[0] == "cest":
67    layout = "application_cest"
68    application_type = "cest"
69else:
70    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
71
72
73lt = context.portal_layouts
74
75pin = request.form.get('pin','')
76
77
78reg_no = request.get('widget__reg_no','').upper()
79if not reg_no:
80    reg_no = request.form.get('reg_no','').upper()
81if not reg_no:
82    reg_no = request.get('widget__pin_n','').upper()
83
84object = {}
85if reg_no:
86    brains = context.applicants_catalog(reg_no = reg_no)
87    if len(brains) == 1:
88        for field in context.applicants_catalog.schema():
89            object[field] = getattr(brains[0],field,None)
90        if not object['passport']:
91                object['passport'] = ''
92        if object['status'] and 'submitted' in object['status']:
93            submitted = True
94
95        if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()):
96            logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
97            return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
98
99
100        # For the next application session it should be reverted to
101        # (see comment 09/06/07 16:40:52 in ticket #328):
102
103        #if not create and (pin != object['pin'] and not context.isSectionOfficer()):
104            #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
105            #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
106
107if slip:
108    mode = "view_slip"
109    logger.info('%s/%s views application slip' % (member,reg_no))
110
111res,psm,ds = lt.renderLayout(layout_id= layout,
112                             schema_id= 'application',
113                             layout_mode = mode,
114                             context=context,
115                             mapping=validate and REQUEST,
116                             ob=object,
117                             commit = False,
118                            )
119                           
120                       
121
122if slip:
123    return context.apply_admission_slip(rendered = res,
124                                   psm = "",
125                                   #psm = "%s, %s" % (psm,ds),
126                                   mode = mode,
127                                   ds = ds,
128                                   application_type = application_type,
129                                  )
130
131if psm == 'invalid':
132    return context.apply_admission_form(rendered = res,
133                                   psm = "Please correct your input!",
134                                   #psm = "%s, %s" % (psm,ds),
135                                   mode = mode,
136                                   ds = ds,
137                                   application_type = application_type,
138                                  )
139elif psm == '' and not manage:
140    return context.apply_admission_form(rendered = res,
141                                   psm = psm,
142                                   ds = ds,
143                                   mode = mode,
144                                   application_type = application_type,
145                                  )
146elif psm == 'valid' or (psm == '' and manage):
147    pass
148if without_reg_no:
149    reg_no = ds.get('reg_no')
150   
151 
152data = {}
153dm = ds.getDataModel()
154for field in context.applicants_catalog.schema():
155    if dm.has_key("%s" % field):
156        data[field] = dm.get(field)
157data['reg_no'] = reg_no
158data['screening_type'] = application_type
159
160
161
162if apply_admission:
163    if submitted:
164        mode = "view"
165        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
166        logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
167        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
168                                schema_id= 'application',
169                                layout_mode = mode,
170                                context=context,
171                                mapping={},
172                                ob=object,
173                                commit = False,
174                                )
175    elif not request.has_key('confirm'):
176        mode = "edit"
177        psm = "Please confirm Passport Photograph!"
178        logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no))
179    else:
180        mode = "view"
181        psm = "You successfully applied for admission!"
182        if object['status'] == 'edited':
183            data['status'] = "submitted"
184            data['application_date'] = current
185            logger.info('%s/%s modified and submitted application record' % (member,reg_no))
186        elif object['status'] == 'reset':
187            data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y')
188            logger.info('%s/%s modified and resubmitted application record' % (member,reg_no))
189        object['status'] = data['status']
190        context.applicants_catalog.modifyRecord(**data)
191
192        res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
193                                schema_id= 'application',
194                                layout_mode = mode,
195                                context=context,
196                                mapping=validate and REQUEST,
197                                ob=object,
198                                commit = False,
199                                )
200elif create:
201    if submitted:
202        mode = "view"
203        logger.info('%s/%s views application record' % (member,reg_no))
204    else:
205        mode = "edit"
206        logger.info('%s/%s edits application record' % (member,reg_no))
207    psm = ""
208    if without_reg_no:
209        object['reg_no'] = reg_no
210    object['pin'] = str(ds.get('pin'))
211    res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
212                                schema_id= 'application',
213                                layout_mode = mode,
214                                context=context,
215                                mapping={},
216                                ob=object,
217                                commit = False,
218                                )
219elif edit:
220    if submitted:
221        mode = "view"
222        psm = "The form has already been submitted and you are not allowed to modify the data!"
223        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
224        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
225                                schema_id= 'application',
226                                layout_mode = mode,
227                                context=context,
228                                mapping={},
229                                ob=object,
230                                commit = False,
231                                )
232    else:
233        mode = "edit"
234        psm = "Content changed!"
235        data['status'] = "edited"
236        #set_trace()
237        context.applicants_catalog.modifyRecord(**data)
238        logger.info('%s/%s modified application record' % (member,reg_no))
239
240elif manage:
241    if submitted:
242        mode = "view"
243        psm = "You are now assuming the applicant's role!"
244        logger.info('%s/%s entered application record' % (member,reg_no))
245        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
246                                schema_id= 'application',
247                                layout_mode = mode,
248                                context=context,
249                                mapping={},
250                                ob=object,
251                                commit = False,
252                                )
253    else:
254        mode = "edit"
255        psm = "You are now assuming the applicant's role!"
256        logger.info('%s/%s entered application record' % (member,reg_no))
257
258
259try:
260    passport_uploaded = bool(data['passport'])
261except:
262    passport_uploaded = False
263
264return context.apply_admission_form(rendered = res,
265                               psm = psm,
266                               #psm = "%s, %s" % (psm,ds),
267                               mode = mode,
268                               show_submit = passport_uploaded,
269                               ds = ds,
270                               application_type = application_type,
271                              )
272
273
Note: See TracBrowser for help on using the repository browser.