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

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

resubmit and reset status added

  • Property svn:keywords set to Id
File size: 7.9 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 2161 2007-08-24 14:23:50Z 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 'submitted' in object['status']:
65            submitted = True
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))
68            return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
69if slip:
70    mode = "view_slip"
71    logger.info('%s/%s views application slip' % (member,reg_no))
72
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
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                                  )
89
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                                  )
97elif psm == '' and not manage:
98    return context.apply_pume_form(rendered = res,
99                                   psm = None,
100                                   ds = ds,
101                                   mode = mode,
102                                  )
103elif psm == 'valid' or (psm == '' and manage):
104    pass
105data = {}
106dm = ds.getDataModel()
107for field in context.applicants_catalog.schema():
108    if dm.has_key("%s" % field):
109        data[field] = dm.get(field)
110data['reg_no'] = reg_no
111
112
113
114if apply_pume:
115    if submitted:
116        mode = "view"
117        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
118        logger.info('%s/%s tried to resubmit application record' % (member,reg_no))
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'):
128        mode = "edit"
129        psm = "Please confirm Passport Photograph!"
130        logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no))
131    else:
132        mode = "view"
133        psm = "You successfully applied for PUME!"
134        data['application_date'] = current
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':
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']   
142        context.applicants_catalog.modifyRecord(**data)
143       
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,
151                                )
152elif create:
153    if submitted:
154        mode = "view"
155        logger.info('%s/%s views application record' % (member,reg_no))
156    else:
157        mode = "edit"
158        logger.info('%s/%s edits application record' % (member,reg_no))
159    psm = ""
160    #set_trace()
161    object['pin'] = str(ds.get('pin'))
162    res,psm,ds_dummy = lt.renderLayout(layout_id= 'application',
163                                schema_id= 'application',
164                                layout_mode = mode,
165                                context=context,
166                                mapping={},
167                                ob=object,
168                                commit = False,
169                                )
170elif edit:
171    if submitted:
172        mode = "view"
173        psm = "The form has already been submitted and you are not allowed to modify the data!"
174        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
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)
188        logger.info('%s/%s modified application record' % (member,reg_no))
189
190elif manage:
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))
207
208
209try:
210    passport_uploaded = bool(data['passport'])
211except:
212    passport_uploaded = False
213
214return context.apply_pume_form(rendered = res,
215                            psm = psm,
216                            #psm = "%s, %s" % (psm,ds),
217                            mode = mode,
218                            show_submit = passport_uploaded,
219                            ds = ds,
220                            )
221
222
Note: See TracBrowser for help on using the repository browser.