source: WAeUP_SRP/trunk/skins/waeup_student/apply_pume.py @ 2198

Last change on this file since 2198 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
RevLine 
[2098]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
[2119]21import logging
22logger = logging.getLogger('Skins.apply_pume')
23
[2159]24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
26
[2098]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()
[2103]37slip = "slip" in request.keys()
[2159]38manage = "manage" in request.keys()
[2102]39submitted = False
[2098]40mode = request.get('mode','')
41if not mode:
[2159]42    if apply_pume or edit or manage:
[2098]43        mode = "edit"
44    else:
45        mode = "create"
[2160]46validate = create or edit or apply_pume
[2098]47
[2160]48if manage:
49    validate = False
50
[2098]51lt = context.portal_layouts
52reg_no = request.get('widget__reg_no','').upper()
53if not reg_no:
[2102]54    reg_no = request.form.get('reg_no','').upper()
55pin = request.form.get('pin','')
[2098]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)
[2114]62        if not object['passport']:
[2160]63                object['passport'] = ''
[2162]64        if object['status'] and 'submitted' in object['status']:
[2102]65            submitted = True
[2184]66       
[2182]67        if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()):
[2159]68            logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin))
[2102]69            return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
[2184]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
[2103]79if slip:
80    mode = "view_slip"
[2159]81    logger.info('%s/%s views application slip' % (member,reg_no))
[2160]82
[2098]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
[2103]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                                  )
[2105]99
[2098]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                                  )
[2160]107elif psm == '' and not manage:
[2098]108    return context.apply_pume_form(rendered = res,
[2168]109                                   psm = psm,
[2098]110                                   ds = ds,
111                                   mode = mode,
112                                  )
[2160]113elif psm == 'valid' or (psm == '' and manage):
[2098]114    pass
[2102]115data = {}
[2114]116dm = ds.getDataModel()
[2102]117for field in context.applicants_catalog.schema():
[2114]118    if dm.has_key("%s" % field):
119        data[field] = dm.get(field)
[2102]120data['reg_no'] = reg_no
[2160]121
122
123
[2102]124if apply_pume:
[2111]125    if submitted:
126        mode = "view"
127        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
[2159]128        logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
[2111]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'):
[2102]138        mode = "edit"
[2111]139        psm = "Please confirm Passport Photograph!"
[2159]140        logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no))
[2102]141    else:
142        mode = "view"
[2111]143        psm = "You successfully applied for PUME!"
[2161]144        if object['status'] == 'edited':
145            data['status'] = "submitted"
[2168]146            data['application_date'] = current
[2161]147            logger.info('%s/%s modified and submitted application record' % (member,reg_no))
148        elif object['status'] == 'reset':
[2162]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']
[2111]152        context.applicants_catalog.modifyRecord(**data)
[2162]153
[2108]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,
[2111]161                                )
[2102]162elif create:
163    if submitted:
164        mode = "view"
[2159]165        logger.info('%s/%s views application record' % (member,reg_no))
[2102]166    else:
167        mode = "edit"
[2159]168        logger.info('%s/%s edits application record' % (member,reg_no))
[2102]169    psm = ""
170    #set_trace()
171    object['pin'] = str(ds.get('pin'))
[2111]172    res,psm,ds_dummy = lt.renderLayout(layout_id= 'application',
[2102]173                                schema_id= 'application',
174                                layout_mode = mode,
175                                context=context,
176                                mapping={},
177                                ob=object,
178                                commit = False,
179                                )
180elif edit:
[2111]181    if submitted:
182        mode = "view"
183        psm = "The form has already been submitted and you are not allowed to modify the data!"
[2159]184        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
[2111]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"
[2168]195        psm = "Content changed!"
[2111]196        data['status'] = "edited"
197        context.applicants_catalog.modifyRecord(**data)
[2159]198        logger.info('%s/%s modified application record' % (member,reg_no))
[2098]199
[2161]200elif manage:
[2159]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))
[2108]217
[2159]218
[2161]219try:
[2160]220    passport_uploaded = bool(data['passport'])
221except:
222    passport_uploaded = False
223
[2102]224return context.apply_pume_form(rendered = res,
225                            psm = psm,
226                            #psm = "%s, %s" % (psm,ds),
227                            mode = mode,
[2160]228                            show_submit = passport_uploaded,
[2102]229                            ds = ds,
230                            )
[2098]231
[2102]232
Note: See TracBrowser for help on using the repository browser.