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 | """ |
---|
12 | process the Pume Application Form |
---|
13 | """ |
---|
14 | try: |
---|
15 | from Products.zdb import set_trace |
---|
16 | except: |
---|
17 | def set_trace(): |
---|
18 | pass |
---|
19 | |
---|
20 | import DateTime |
---|
21 | import logging |
---|
22 | logger = logging.getLogger('Skins.apply_pume') |
---|
23 | |
---|
24 | mtool = context.portal_membership |
---|
25 | member = mtool.getAuthenticatedMember() |
---|
26 | |
---|
27 | current = DateTime.DateTime() |
---|
28 | pr = context.portal_registration |
---|
29 | request = REQUEST |
---|
30 | |
---|
31 | #type_name = 'StudentApplication' |
---|
32 | #ti = context.portal_types[type_name] |
---|
33 | #REQUEST.set('type_name',type_name) |
---|
34 | create = "create" in request.keys() |
---|
35 | apply_pume = "apply" in request.keys() |
---|
36 | edit = "edit" in request.keys() |
---|
37 | slip = "slip" in request.keys() |
---|
38 | manage = "manage" in request.keys() |
---|
39 | submitted = False |
---|
40 | mode = request.get('mode','') |
---|
41 | if not mode: |
---|
42 | if apply_pume or edit or manage: |
---|
43 | mode = "edit" |
---|
44 | else: |
---|
45 | mode = "create" |
---|
46 | validate = create or edit or apply_pume |
---|
47 | |
---|
48 | if manage: |
---|
49 | validate = False |
---|
50 | |
---|
51 | lt = context.portal_layouts |
---|
52 | reg_no = request.get('widget__reg_no','').upper() |
---|
53 | if not reg_no: |
---|
54 | reg_no = request.form.get('reg_no','').upper() |
---|
55 | pin = request.form.get('pin','') |
---|
56 | object = {} |
---|
57 | if 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()) |
---|
69 | if slip: |
---|
70 | mode = "view_slip" |
---|
71 | logger.info('%s/%s views application slip' % (member,reg_no)) |
---|
72 | |
---|
73 | res,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 | |
---|
82 | if 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 | |
---|
90 | if 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 | ) |
---|
97 | elif psm == '' and not manage: |
---|
98 | return context.apply_pume_form(rendered = res, |
---|
99 | psm = None, |
---|
100 | ds = ds, |
---|
101 | mode = mode, |
---|
102 | ) |
---|
103 | elif psm == 'valid' or (psm == '' and manage): |
---|
104 | pass |
---|
105 | data = {} |
---|
106 | dm = ds.getDataModel() |
---|
107 | for field in context.applicants_catalog.schema(): |
---|
108 | if dm.has_key("%s" % field): |
---|
109 | data[field] = dm.get(field) |
---|
110 | data['reg_no'] = reg_no |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | if 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 | ) |
---|
152 | elif 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 | ) |
---|
170 | elif 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 | |
---|
190 | elif 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 | |
---|
209 | try: |
---|
210 | passport_uploaded = bool(data['passport']) |
---|
211 | except: |
---|
212 | passport_uploaded = False |
---|
213 | |
---|
214 | return 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 | |
---|