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

Last change on this file since 2311 was 2310, checked in by Henrik Bettermann, 18 years ago

generic application form for all kinds of application processes (Part1)

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