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

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

store date of resubmission

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