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

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

Some changes to make PRE-NCE application work.

mail2student.py: senders name and email address changed

  • 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 2316 2007-10-05 10:16:23Z 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
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()
81
82
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
120if slip:
121    return context.apply_admission_slip(rendered = res,
122                                   psm = "",
123                                   #psm = "%s, %s" % (psm,ds),
124                                   mode = mode,
125                                   ds = ds,
126                                   application_type = application_type,
127                                  )
128
129if psm == 'invalid':
130    return context.apply_admission_form(rendered = res,
131                                   psm = "Please correct your input!",
132                                   #psm = "%s, %s" % (psm,ds),
133                                   mode = mode,
134                                   ds = ds,
135                                   application_type = application_type,
136                                  )
137elif psm == '' and not manage:
138    return context.apply_admission_form(rendered = res,
139                                   psm = psm,
140                                   ds = ds,
141                                   mode = mode,
142                                   application_type = application_type,
143                                  )
144elif psm == 'valid' or (psm == '' and manage):
145    pass
146if without_reg_no:
147    reg_no = ds.get('reg_no')
148data = {}
149dm = ds.getDataModel()
150for field in context.applicants_catalog.schema():
151    if dm.has_key("%s" % field):
152        data[field] = dm.get(field)
153data['reg_no'] = reg_no
154
155if apply_admission:
156    if submitted:
157        mode = "view"
158        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
159        logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
160        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
161                                schema_id= 'application',
162                                layout_mode = mode,
163                                context=context,
164                                mapping={},
165                                ob=object,
166                                commit = False,
167                                )
168    elif not request.has_key('confirm'):
169        mode = "edit"
170        psm = "Please confirm Passport Photograph!"
171        logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no))
172    else:
173        mode = "view"
174        psm = "You successfully applied for admission!"
175        if object['status'] == 'edited':
176            data['status'] = "submitted"
177            data['application_date'] = current
178            logger.info('%s/%s modified and submitted application record' % (member,reg_no))
179        elif object['status'] == 'reset':
180            data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y')
181            logger.info('%s/%s modified and resubmitted application record' % (member,reg_no))
182        object['status'] = data['status']
183        context.applicants_catalog.modifyRecord(**data)
184
185        res,psm_dummy,ds = lt.renderLayout(layout_id= layout,
186                                schema_id= 'application',
187                                layout_mode = mode,
188                                context=context,
189                                mapping=validate and REQUEST,
190                                ob=object,
191                                commit = False,
192                                )
193elif create:
194    if submitted:
195        mode = "view"
196        logger.info('%s/%s views application record' % (member,reg_no))
197    else:
198        mode = "edit"
199        logger.info('%s/%s edits application record' % (member,reg_no))
200    psm = ""
201    if without_reg_no:
202        object['reg_no'] = reg_no
203    object['pin'] = str(ds.get('pin'))
204    res,psm,ds_dummy = lt.renderLayout(layout_id= layout,
205                                schema_id= 'application',
206                                layout_mode = mode,
207                                context=context,
208                                mapping={},
209                                ob=object,
210                                commit = False,
211                                )
212elif edit:
213    if submitted:
214        mode = "view"
215        psm = "The form has already been submitted and you are not allowed to modify the data!"
216        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
217        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
218                                schema_id= 'application',
219                                layout_mode = mode,
220                                context=context,
221                                mapping={},
222                                ob=object,
223                                commit = False,
224                                )
225    else:
226        mode = "edit"
227        psm = "Content changed!"
228        data['status'] = "edited"
229        context.applicants_catalog.modifyRecord(**data)
230        logger.info('%s/%s modified application record' % (member,reg_no))
231
232elif manage:
233    if submitted:
234        mode = "view"
235        psm = "You are now assuming the applicant's role!"
236        logger.info('%s/%s entered application record' % (member,reg_no))
237        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout,
238                                schema_id= 'application',
239                                layout_mode = mode,
240                                context=context,
241                                mapping={},
242                                ob=object,
243                                commit = False,
244                                )
245    else:
246        mode = "edit"
247        psm = "You are now assuming the applicant's role!"
248        logger.info('%s/%s entered application record' % (member,reg_no))
249
250
251try:
252    passport_uploaded = bool(data['passport'])
253except:
254    passport_uploaded = False
255
256return context.apply_admission_form(rendered = res,
257                               psm = psm,
258                               #psm = "%s, %s" % (psm,ds),
259                               mode = mode,
260                               show_submit = passport_uploaded,
261                               ds = ds,
262                               application_type = application_type,
263                              )
264
265
Note: See TracBrowser for help on using the repository browser.