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

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

allow SectionOfficer? to assume applicant's role

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