source: WAeUP_SRP/base/skins/waeup_student/apply_pume.py @ 2308

Last change on this file since 2308 was 2307, checked in by joachim, 18 years ago

allow apply_pume without reg_no. call with apply_pume/prence

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