1 | ## $Id: browser.py 13556 2015-12-21 15:08:12Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | """UI components for basic applicants and related components. |
---|
19 | """ |
---|
20 | import grok |
---|
21 | from zope.component import getUtility |
---|
22 | from zope.i18n import translate |
---|
23 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
24 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
25 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
26 | from waeup.kofa.applicants.interfaces import ( |
---|
27 | IApplicantRegisterUpdate, IApplicant, IApplicantEdit) |
---|
28 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
29 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
30 | ApplicantRegistrationPage, ApplicantAddFormPage, |
---|
31 | OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage, |
---|
32 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
33 | ApplicantBaseDisplayFormPage) |
---|
34 | from waeup.kofa.applicants.viewlets import ( |
---|
35 | PaymentReceiptActionButton, PDFActionButton) |
---|
36 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
37 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
38 | INigeriaPGApplicant, INigeriaUGApplicant, |
---|
39 | INigeriaPGApplicantEdit, INigeriaUGApplicantEdit, |
---|
40 | INigeriaApplicantOnlinePayment,IPUTMEApplicantEdit, |
---|
41 | UG_OMIT_DISPLAY_FIELDS, |
---|
42 | UG_OMIT_PDF_FIELDS, |
---|
43 | UG_OMIT_MANAGE_FIELDS, |
---|
44 | UG_OMIT_EDIT_FIELDS, |
---|
45 | CBT_OMIT_DISPLAY_FIELDS, |
---|
46 | CBT_OMIT_PDF_FIELDS, |
---|
47 | CBT_OMIT_MANAGE_FIELDS, |
---|
48 | CBT_OMIT_EDIT_FIELDS, |
---|
49 | AFFIL_OMIT_DISPLAY_FIELDS, |
---|
50 | AFFIL_OMIT_PDF_FIELDS, |
---|
51 | AFFIL_OMIT_MANAGE_FIELDS, |
---|
52 | AFFIL_OMIT_EDIT_FIELDS, |
---|
53 | PG_OMIT_DISPLAY_FIELDS, |
---|
54 | PG_OMIT_PDF_FIELDS, |
---|
55 | PG_OMIT_MANAGE_FIELDS, |
---|
56 | PG_OMIT_EDIT_FIELDS, |
---|
57 | PUTME_OMIT_DISPLAY_FIELDS, |
---|
58 | PUTME_OMIT_PDF_FIELDS, |
---|
59 | PUTME_OMIT_MANAGE_FIELDS, |
---|
60 | PUTME_OMIT_EDIT_FIELDS, |
---|
61 | PUTME_OMIT_RESULT_SLIP_FIELDS, |
---|
62 | PUDE_OMIT_DISPLAY_FIELDS, |
---|
63 | PUDE_OMIT_PDF_FIELDS, |
---|
64 | PUDE_OMIT_MANAGE_FIELDS, |
---|
65 | PUDE_OMIT_EDIT_FIELDS, |
---|
66 | PUDE_OMIT_RESULT_SLIP_FIELDS, |
---|
67 | PRE_OMIT_DISPLAY_FIELDS, |
---|
68 | PRE_OMIT_PDF_FIELDS, |
---|
69 | PRE_OMIT_MANAGE_FIELDS, |
---|
70 | PRE_OMIT_EDIT_FIELDS, |
---|
71 | ) |
---|
72 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
73 | |
---|
74 | class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
75 | """A breadcrumb for payments. |
---|
76 | """ |
---|
77 | grok.context(INigeriaApplicantOnlinePayment) |
---|
78 | |
---|
79 | class PDFActionButton(PDFActionButton): |
---|
80 | |
---|
81 | @property |
---|
82 | def text(self): |
---|
83 | if getattr(self.context, 'result_uploaded', False): |
---|
84 | return _('Download result slip') |
---|
85 | return _('Download application slip') |
---|
86 | |
---|
87 | class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
88 | """A display view for applicant data. |
---|
89 | """ |
---|
90 | |
---|
91 | def _not_paid(self): |
---|
92 | return self.context.state in ('initialized', 'started',) |
---|
93 | |
---|
94 | @property |
---|
95 | def form_fields(self): |
---|
96 | if self.target is not None and self.target.startswith('pg'): |
---|
97 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
98 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
99 | form_fields = form_fields.omit(field) |
---|
100 | elif self.target is not None and self.target.startswith('pre'): |
---|
101 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
102 | for field in PRE_OMIT_DISPLAY_FIELDS: |
---|
103 | form_fields = form_fields.omit(field) |
---|
104 | elif self.target is not None and self.target.startswith('cbt'): |
---|
105 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
106 | for field in CBT_OMIT_DISPLAY_FIELDS: |
---|
107 | form_fields = form_fields.omit(field) |
---|
108 | elif self.target is not None and self.target.startswith('af'): |
---|
109 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
110 | for field in AFFIL_OMIT_DISPLAY_FIELDS: |
---|
111 | form_fields = form_fields.omit(field) |
---|
112 | elif self.target is not None and self.target.startswith('putme'): |
---|
113 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
114 | for field in PUTME_OMIT_DISPLAY_FIELDS: |
---|
115 | form_fields = form_fields.omit(field) |
---|
116 | elif self.target is not None and self.target.startswith('pude'): |
---|
117 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
118 | for field in PUDE_OMIT_DISPLAY_FIELDS: |
---|
119 | form_fields = form_fields.omit(field) |
---|
120 | else: |
---|
121 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
122 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
123 | form_fields = form_fields.omit(field) |
---|
124 | #form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
125 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
126 | if not getattr(self.context, 'student_id'): |
---|
127 | form_fields = form_fields.omit('student_id') |
---|
128 | if not getattr(self.context, 'screening_score'): |
---|
129 | form_fields = form_fields.omit('screening_score') |
---|
130 | if not getattr(self.context, 'screening_venue') or self._not_paid(): |
---|
131 | form_fields = form_fields.omit('screening_venue') |
---|
132 | if not getattr(self.context, 'screening_date') or self._not_paid(): |
---|
133 | form_fields = form_fields.omit('screening_date') |
---|
134 | return form_fields |
---|
135 | |
---|
136 | class NigeriaPDFApplicationSlip(PDFApplicationSlip): |
---|
137 | |
---|
138 | def _addLoginInformation(self): |
---|
139 | """ We do no longer render login information on |
---|
140 | pdf application slips. |
---|
141 | """ |
---|
142 | return |
---|
143 | |
---|
144 | def _reduced_slip(self): |
---|
145 | return getattr(self.context, 'result_uploaded', False) |
---|
146 | |
---|
147 | @property |
---|
148 | def form_fields(self): |
---|
149 | if self.target is not None and self.target.startswith('pg'): |
---|
150 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
151 | for field in PG_OMIT_PDF_FIELDS: |
---|
152 | form_fields = form_fields.omit(field) |
---|
153 | elif self.target is not None and self.target.startswith('pre'): |
---|
154 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
155 | for field in PRE_OMIT_PDF_FIELDS: |
---|
156 | form_fields = form_fields.omit(field) |
---|
157 | elif self.target is not None and self.target.startswith('cbt'): |
---|
158 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
159 | for field in CBT_OMIT_PDF_FIELDS: |
---|
160 | form_fields = form_fields.omit(field) |
---|
161 | elif self.target is not None and self.target.startswith('af'): |
---|
162 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
163 | for field in AFFIL_OMIT_PDF_FIELDS: |
---|
164 | form_fields = form_fields.omit(field) |
---|
165 | elif self.target is not None and self.target.startswith('putme'): |
---|
166 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
167 | if self._reduced_slip(): |
---|
168 | for field in PUTME_OMIT_RESULT_SLIP_FIELDS: |
---|
169 | form_fields = form_fields.omit(field) |
---|
170 | else: |
---|
171 | for field in PUTME_OMIT_PDF_FIELDS: |
---|
172 | form_fields = form_fields.omit(field) |
---|
173 | elif self.target is not None and self.target.startswith('pude'): |
---|
174 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
175 | if self._reduced_slip(): |
---|
176 | for field in PUDE_OMIT_RESULT_SLIP_FIELDS: |
---|
177 | form_fields = form_fields.omit(field) |
---|
178 | else: |
---|
179 | for field in PUDE_OMIT_PDF_FIELDS: |
---|
180 | form_fields = form_fields.omit(field) |
---|
181 | else: |
---|
182 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
183 | for field in UG_OMIT_PDF_FIELDS: |
---|
184 | form_fields = form_fields.omit(field) |
---|
185 | if not getattr(self.context, 'student_id'): |
---|
186 | form_fields = form_fields.omit('student_id') |
---|
187 | if not getattr(self.context, 'screening_score'): |
---|
188 | form_fields = form_fields.omit('screening_score') |
---|
189 | if not getattr(self.context, 'screening_venue'): |
---|
190 | form_fields = form_fields.omit('screening_venue') |
---|
191 | if not getattr(self.context, 'screening_date'): |
---|
192 | form_fields = form_fields.omit('screening_date') |
---|
193 | return form_fields |
---|
194 | |
---|
195 | class NigeriaApplicantManageFormPage(ApplicantManageFormPage): |
---|
196 | """A full edit view for applicant data. |
---|
197 | """ |
---|
198 | |
---|
199 | @property |
---|
200 | def form_fields(self): |
---|
201 | if self.target is not None and self.target.startswith('pg'): |
---|
202 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
203 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
204 | form_fields = form_fields.omit(field) |
---|
205 | elif self.target is not None and self.target.startswith('pre'): |
---|
206 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
207 | for field in PRE_OMIT_MANAGE_FIELDS: |
---|
208 | form_fields = form_fields.omit(field) |
---|
209 | elif self.target is not None and self.target.startswith('cbt'): |
---|
210 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
211 | for field in CBT_OMIT_MANAGE_FIELDS: |
---|
212 | form_fields = form_fields.omit(field) |
---|
213 | elif self.target is not None and self.target.startswith('af'): |
---|
214 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
215 | for field in AFFIL_OMIT_MANAGE_FIELDS: |
---|
216 | form_fields = form_fields.omit(field) |
---|
217 | elif self.target is not None and self.target.startswith('putme'): |
---|
218 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
219 | for field in PUTME_OMIT_MANAGE_FIELDS: |
---|
220 | form_fields = form_fields.omit(field) |
---|
221 | elif self.target is not None and self.target.startswith('pude'): |
---|
222 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
223 | for field in PUDE_OMIT_MANAGE_FIELDS: |
---|
224 | form_fields = form_fields.omit(field) |
---|
225 | else: |
---|
226 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
227 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
228 | form_fields = form_fields.omit(field) |
---|
229 | form_fields['student_id'].for_display = True |
---|
230 | form_fields['applicant_id'].for_display = True |
---|
231 | return form_fields |
---|
232 | |
---|
233 | class NigeriaApplicantEditFormPage(ApplicantEditFormPage): |
---|
234 | """An applicant-centered edit view for applicant data. |
---|
235 | """ |
---|
236 | |
---|
237 | @property |
---|
238 | def form_fields(self): |
---|
239 | if self.target is not None and self.target.startswith('pg'): |
---|
240 | form_fields = grok.AutoFields(INigeriaPGApplicantEdit) |
---|
241 | for field in PG_OMIT_EDIT_FIELDS: |
---|
242 | form_fields = form_fields.omit(field) |
---|
243 | elif self.target is not None and self.target.startswith('pre'): |
---|
244 | form_fields = grok.AutoFields(INigeriaPGApplicantEdit) |
---|
245 | for field in PRE_OMIT_EDIT_FIELDS: |
---|
246 | form_fields = form_fields.omit(field) |
---|
247 | elif self.target is not None and self.target.startswith('cbt'): |
---|
248 | form_fields = grok.AutoFields(INigeriaUGApplicantEdit) |
---|
249 | for field in CBT_OMIT_EDIT_FIELDS: |
---|
250 | form_fields = form_fields.omit(field) |
---|
251 | elif self.target is not None and self.target.startswith('af'): |
---|
252 | form_fields = grok.AutoFields(INigeriaUGApplicantEdit) |
---|
253 | for field in AFFIL_OMIT_EDIT_FIELDS: |
---|
254 | form_fields = form_fields.omit(field) |
---|
255 | elif self.target is not None and self.target.startswith('putme'): |
---|
256 | form_fields = grok.AutoFields(IPUTMEApplicantEdit) |
---|
257 | for field in PUTME_OMIT_EDIT_FIELDS: |
---|
258 | form_fields = form_fields.omit(field) |
---|
259 | elif self.target is not None and self.target.startswith('pude'): |
---|
260 | form_fields = grok.AutoFields(INigeriaUGApplicantEdit) |
---|
261 | for field in PUDE_OMIT_EDIT_FIELDS: |
---|
262 | form_fields = form_fields.omit(field) |
---|
263 | else: |
---|
264 | form_fields = grok.AutoFields(INigeriaUGApplicantEdit) |
---|
265 | for field in UG_OMIT_EDIT_FIELDS: |
---|
266 | form_fields = form_fields.omit(field) |
---|
267 | form_fields['applicant_id'].for_display = True |
---|
268 | form_fields['reg_number'].for_display = True |
---|
269 | return form_fields |
---|
270 | |
---|
271 | class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
272 | """ Page to view an online payment ticket |
---|
273 | """ |
---|
274 | grok.context(INigeriaApplicantOnlinePayment) |
---|
275 | form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac', |
---|
276 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
277 | form_fields[ |
---|
278 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
279 | form_fields[ |
---|
280 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
281 | |
---|
282 | class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
283 | """Deliver a PDF slip of the context. |
---|
284 | """ |
---|
285 | grok.context(INigeriaApplicantOnlinePayment) |
---|
286 | form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit( |
---|
287 | 'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
288 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
289 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
290 | |
---|
291 | class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage): |
---|
292 | """Captcha'd registration page for applicants. |
---|
293 | """ |
---|
294 | |
---|
295 | #def _redirect(self, email, password, applicant_id): |
---|
296 | # # Forward email and credentials to landing page. |
---|
297 | # self.redirect(self.url(self.context, 'registration_complete', |
---|
298 | # data = dict(email=email, password=password, |
---|
299 | # applicant_id=applicant_id))) |
---|
300 | # return |
---|