source: WAeUP_SRP/trunk_not_used/skins/waeup_student/apply_pume.py @ 2226

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

add only upper-case reg numbers to portal_pins table

see inline comments and also
comment 09/06/07 16:40:52 in ticket #328

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