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

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

assume role also in state 'entered'

  • Property svn:keywords set to Id
File size: 7.6 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 2160 2007-08-24 09:47:46Z 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'] == "submitted":
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        data['status'] = "submitted"
136        context.applicants_catalog.modifyRecord(**data)
137        logger.info('%s/%s modified and submitted application record' % (member,reg_no))
138        res,psm_dummy,ds = lt.renderLayout(layout_id= 'application',
139                                schema_id= 'application',
140                                layout_mode = mode,
141                                context=context,
142                                mapping=validate and REQUEST,
143                                ob=object,
144                                commit = False,
145                                )
146elif create:
147    if submitted:
148        mode = "view"
149        logger.info('%s/%s views application record' % (member,reg_no))
150    else:
151        mode = "edit"
152        logger.info('%s/%s edits application record' % (member,reg_no))
153    psm = ""
154    #set_trace()
155    object['pin'] = str(ds.get('pin'))
156    res,psm,ds_dummy = lt.renderLayout(layout_id= 'application',
157                                schema_id= 'application',
158                                layout_mode = mode,
159                                context=context,
160                                mapping={},
161                                ob=object,
162                                commit = False,
163                                )
164elif edit:
165    if submitted:
166        mode = "view"
167        psm = "The form has already been submitted and you are not allowed to modify the data!"
168        logger.info('%s/%s tried to edit submitted application record' % (member,reg_no))
169        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application',
170                                schema_id= 'application',
171                                layout_mode = mode,
172                                context=context,
173                                mapping={},
174                                ob=object,
175                                commit = False,
176                                )
177    else:
178        mode = "edit"
179        psm = "Content changed"
180        data['status'] = "edited"
181        context.applicants_catalog.modifyRecord(**data)
182        logger.info('%s/%s modified application record' % (member,reg_no))
183
184elif manage:       
185    if submitted:
186        mode = "view"
187        psm = "You are now assuming the applicant's role!"
188        logger.info('%s/%s entered application record' % (member,reg_no))
189        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application',
190                                schema_id= 'application',
191                                layout_mode = mode,
192                                context=context,
193                                mapping={},
194                                ob=object,
195                                commit = False,
196                                )
197    else:
198        mode = "edit"
199        psm = "You are now assuming the applicant's role!"
200        logger.info('%s/%s entered application record' % (member,reg_no))
201
202
203try:   
204    passport_uploaded = bool(data['passport'])
205except:
206    passport_uploaded = False
207
208return context.apply_pume_form(rendered = res,
209                            psm = psm,
210                            #psm = "%s, %s" % (psm,ds),
211                            mode = mode,
212                            show_submit = passport_uploaded,
213                            ds = ds,
214                            )
215
216
Note: See TracBrowser for help on using the repository browser.