1 | ## $Id: browser.py 16077 2020-04-29 07:14:44Z 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 | import os |
---|
22 | from zope.component import getUtility, queryUtility |
---|
23 | from zope.catalog.interfaces import ICatalog |
---|
24 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
25 | from waeup.kofa.interfaces import ( |
---|
26 | IExtFileStore, IFileStoreNameChooser) |
---|
27 | from waeup.kofa.utils.helpers import string_from_bytes, file_size, now |
---|
28 | from waeup.kofa.applicants.browser import ( |
---|
29 | ApplicantRegistrationPage, ApplicantsContainerPage, AdditionalFile, |
---|
30 | RefereeReportAddFormPage, ExportPDFReportSlipPage, ExportPDFReportSlipPage2, |
---|
31 | RefereeReportDisplayFormPage) |
---|
32 | from waeup.kofa.applicants.interfaces import ( |
---|
33 | ISpecialApplicant, IApplicantsContainer, AppCatCertificateSource) |
---|
34 | from kofacustom.nigeria.applicants.browser import ( |
---|
35 | NigeriaApplicantDisplayFormPage, |
---|
36 | NigeriaApplicantManageFormPage, |
---|
37 | NigeriaApplicantEditFormPage, |
---|
38 | NigeriaPDFApplicationSlip) |
---|
39 | from waeup.kofa.widgets.datewidget import ( |
---|
40 | FriendlyDateDisplayWidget, |
---|
41 | FriendlyDatetimeDisplayWidget) |
---|
42 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
43 | OMIT_DISPLAY_FIELDS, |
---|
44 | #UG_OMIT_DISPLAY_FIELDS, |
---|
45 | #UG_OMIT_PDF_FIELDS, |
---|
46 | #UG_OMIT_MANAGE_FIELDS, |
---|
47 | #UG_OMIT_EDIT_FIELDS, |
---|
48 | #PG_OMIT_DISPLAY_FIELDS, |
---|
49 | #PG_OMIT_PDF_FIELDS, |
---|
50 | #PG_OMIT_MANAGE_FIELDS, |
---|
51 | #PG_OMIT_EDIT_FIELDS, |
---|
52 | ) |
---|
53 | from kofacustom.iuokada.applicants.interfaces import ( |
---|
54 | ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant, |
---|
55 | ICustomPGApplicantEdit, ICustomUGApplicantEdit, |
---|
56 | ICustomApplicantOnlinePayment, ICustomApplicantRefereeReport |
---|
57 | ) |
---|
58 | from kofacustom.iuokada.interfaces import MessageFactory as _ |
---|
59 | |
---|
60 | MAX_FILE_UPLOAD_SIZE = 1024 * 500 |
---|
61 | |
---|
62 | # UG students are all undergraduate students. |
---|
63 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
64 | #'jamb_subjects_list', |
---|
65 | 'programme_type',) |
---|
66 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
67 | UG_OMIT_MANAGE_FIELDS = ( |
---|
68 | 'special_application', |
---|
69 | #'jamb_subjects_list', |
---|
70 | 'programme_type', |
---|
71 | 'course1', |
---|
72 | 'course2',) |
---|
73 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
74 | 'student_id', |
---|
75 | 'notice', |
---|
76 | 'screening_score', |
---|
77 | 'screening_venue', |
---|
78 | 'screening_date', |
---|
79 | #'jamb_age', |
---|
80 | #'jamb_subjects', |
---|
81 | #'jamb_score', |
---|
82 | #'jamb_reg_number', |
---|
83 | 'aggregate', |
---|
84 | ) |
---|
85 | |
---|
86 | # PG has its own interface |
---|
87 | PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
88 | 'employer', |
---|
89 | 'emp_position', |
---|
90 | 'emp_start', |
---|
91 | 'emp_end', |
---|
92 | 'emp_reason', |
---|
93 | 'employer2', |
---|
94 | 'emp2_position', |
---|
95 | 'emp2_start', |
---|
96 | 'emp2_end', |
---|
97 | 'emp2_reason', |
---|
98 | ) |
---|
99 | PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
100 | PG_OMIT_MANAGE_FIELDS = ( |
---|
101 | 'special_application', |
---|
102 | 'employer', |
---|
103 | 'emp_position', |
---|
104 | 'emp_start', |
---|
105 | 'emp_end', |
---|
106 | 'emp_reason', |
---|
107 | 'employer2', |
---|
108 | 'emp2_position', |
---|
109 | 'emp2_start', |
---|
110 | 'emp2_end', |
---|
111 | 'emp2_reason', |
---|
112 | 'course1', |
---|
113 | 'course2', |
---|
114 | ) |
---|
115 | PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + PG_OMIT_DISPLAY_FIELDS + ( |
---|
116 | 'student_id', |
---|
117 | 'notice', |
---|
118 | 'screening_score', |
---|
119 | 'screening_venue', |
---|
120 | 'screening_date',) |
---|
121 | |
---|
122 | class CustomApplicantsContainerPage(ApplicantsContainerPage): |
---|
123 | """The standard view for regular applicant containers. |
---|
124 | """ |
---|
125 | |
---|
126 | @property |
---|
127 | def form_fields(self): |
---|
128 | form_fields = grok.AutoFields(IApplicantsContainer).omit( |
---|
129 | 'title', 'description') |
---|
130 | if self.request.principal.id == 'zope.anybody': |
---|
131 | form_fields = form_fields.omit( |
---|
132 | 'code', 'prefix', 'year', 'mode', 'hidden', |
---|
133 | 'strict_deadline', 'application_category', |
---|
134 | 'application_slip_notice', |
---|
135 | 'application_fee', 'with_picture', |
---|
136 | 'startdate', 'enddate') |
---|
137 | return form_fields |
---|
138 | |
---|
139 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
140 | """A display view for applicant data. |
---|
141 | """ |
---|
142 | |
---|
143 | @property |
---|
144 | def form_fields(self): |
---|
145 | if self.target is not None and self.target.startswith('pg'): |
---|
146 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
147 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
148 | form_fields = form_fields.omit(field) |
---|
149 | else: |
---|
150 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
151 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
152 | form_fields = form_fields.omit(field) |
---|
153 | #form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
154 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
155 | if not getattr(self.context, 'student_id'): |
---|
156 | form_fields = form_fields.omit('student_id') |
---|
157 | if not getattr(self.context, 'screening_score'): |
---|
158 | form_fields = form_fields.omit('screening_score') |
---|
159 | if not getattr(self.context, 'screening_venue') or self._not_paid(): |
---|
160 | form_fields = form_fields.omit('screening_venue') |
---|
161 | if not getattr(self.context, 'screening_date') or self._not_paid(): |
---|
162 | form_fields = form_fields.omit('screening_date') |
---|
163 | return form_fields |
---|
164 | |
---|
165 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
166 | """A full edit view for applicant data. |
---|
167 | """ |
---|
168 | |
---|
169 | def getCerts(self, coursex): |
---|
170 | yield(dict(code='', title='--', selected='')) |
---|
171 | appcatcertificatesource = AppCatCertificateSource().factory |
---|
172 | for cert in appcatcertificatesource.getValues(self.context): |
---|
173 | selected = '' |
---|
174 | course = getattr(self.context, coursex) |
---|
175 | if course is not None and course.code == cert.code: |
---|
176 | selected = 'selected' |
---|
177 | title = appcatcertificatesource.getTitle(self.context, cert) |
---|
178 | yield(dict(code=cert.code, title=title, selected=selected)) |
---|
179 | |
---|
180 | def saveCourses(self, changed_fields): |
---|
181 | """In custom packages we needed to customize the certificate |
---|
182 | select widget. We just save course1 and course2 if these customized |
---|
183 | fields appear in the form. |
---|
184 | """ |
---|
185 | form = self.request.form |
---|
186 | course1 = form.get('custom.course1', None) |
---|
187 | course2 = form.get('custom.course2', None) |
---|
188 | cat = queryUtility(ICatalog, name='certificates_catalog') |
---|
189 | if course1: |
---|
190 | results = list( |
---|
191 | cat.searchResults(code=(course1, course1))) |
---|
192 | self.context.course1 = results[0] |
---|
193 | changed_fields.append('course1') |
---|
194 | if course2: |
---|
195 | results = list( |
---|
196 | cat.searchResults(code=(course2, course2))) |
---|
197 | self.context.course2 = results[0] |
---|
198 | changed_fields.append('course2') |
---|
199 | return changed_fields |
---|
200 | |
---|
201 | @property |
---|
202 | def display_refereereports(self): |
---|
203 | if self.context.refereereports: |
---|
204 | return True |
---|
205 | return False |
---|
206 | |
---|
207 | @property |
---|
208 | def form_fields(self): |
---|
209 | if self.target is not None and self.target.startswith('pg'): |
---|
210 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
211 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
212 | form_fields = form_fields.omit(field) |
---|
213 | else: |
---|
214 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
215 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
216 | form_fields = form_fields.omit(field) |
---|
217 | form_fields['student_id'].for_display = True |
---|
218 | form_fields['applicant_id'].for_display = True |
---|
219 | return form_fields |
---|
220 | |
---|
221 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
222 | """An applicant-centered edit view for applicant data. |
---|
223 | """ |
---|
224 | |
---|
225 | def getCerts(self, coursex): |
---|
226 | yield(dict(code='', title='--', selected='')) |
---|
227 | appcatcertificatesource = AppCatCertificateSource().factory |
---|
228 | for cert in appcatcertificatesource.getValues(self.context): |
---|
229 | selected = '' |
---|
230 | course = getattr(self.context, coursex) |
---|
231 | if course is not None and course.code == cert.code: |
---|
232 | selected = 'selected' |
---|
233 | title = appcatcertificatesource.getTitle(self.context, cert) |
---|
234 | yield(dict(code=cert.code, title=title, selected=selected)) |
---|
235 | |
---|
236 | def saveCourses(self): |
---|
237 | """In custom packages we needed to customize the certificate |
---|
238 | select widget. We just save course1 and course2 if these customized |
---|
239 | fields appear in the form. |
---|
240 | """ |
---|
241 | form = self.request.form |
---|
242 | course1 = form.get('custom.course1', None) |
---|
243 | course2 = form.get('custom.course2', None) |
---|
244 | cat = queryUtility(ICatalog, name='certificates_catalog') |
---|
245 | if course1: |
---|
246 | results = list( |
---|
247 | cat.searchResults(code=(course1, course1))) |
---|
248 | self.context.course1 = results[0] |
---|
249 | if course2: |
---|
250 | results = list( |
---|
251 | cat.searchResults(code=(course2, course2))) |
---|
252 | self.context.course2 = results[0] |
---|
253 | return |
---|
254 | |
---|
255 | def display_fileupload(self, filename): |
---|
256 | if filename[1] == 'res_stat.pdf': |
---|
257 | if self.context.subtype != 'transfer': |
---|
258 | return False |
---|
259 | if filename[1] == 'jamb.pdf' \ |
---|
260 | and self.target is not None \ |
---|
261 | and self.target.startswith('pg'): |
---|
262 | return False |
---|
263 | if filename[1] == 'nysc.pdf' \ |
---|
264 | and self.target is not None \ |
---|
265 | and not self.target.startswith('pg'): |
---|
266 | return False |
---|
267 | return True |
---|
268 | |
---|
269 | def dataNotComplete(self, data): |
---|
270 | store = getUtility(IExtFileStore) |
---|
271 | if self.context.__parent__.with_picture: |
---|
272 | store = getUtility(IExtFileStore) |
---|
273 | if not store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
274 | return _('No passport picture uploaded.') |
---|
275 | if self.context.subtype == 'transfer' \ |
---|
276 | and self.context.__parent__.code!= 'ug2020' \ |
---|
277 | and not store.getFileByContext(self.context, attr=u'res_stat.pdf'): |
---|
278 | return _('No statement of result pdf file uploaded.') |
---|
279 | return False |
---|
280 | |
---|
281 | @property |
---|
282 | def form_fields(self): |
---|
283 | if self.target is not None and self.target.startswith('pg'): |
---|
284 | form_fields = grok.AutoFields(ICustomPGApplicantEdit) |
---|
285 | for field in PG_OMIT_EDIT_FIELDS: |
---|
286 | form_fields = form_fields.omit(field) |
---|
287 | else: |
---|
288 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
289 | for field in UG_OMIT_EDIT_FIELDS: |
---|
290 | form_fields = form_fields.omit(field) |
---|
291 | form_fields['applicant_id'].for_display = True |
---|
292 | form_fields['reg_number'].for_display = True |
---|
293 | return form_fields |
---|
294 | |
---|
295 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
296 | |
---|
297 | @property |
---|
298 | def form_fields(self): |
---|
299 | if self.target is not None and self.target.startswith('pg'): |
---|
300 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
301 | for field in PG_OMIT_PDF_FIELDS: |
---|
302 | form_fields = form_fields.omit(field) |
---|
303 | else: |
---|
304 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
305 | for field in UG_OMIT_PDF_FIELDS: |
---|
306 | form_fields = form_fields.omit(field) |
---|
307 | if not getattr(self.context, 'student_id'): |
---|
308 | form_fields = form_fields.omit('student_id') |
---|
309 | if not getattr(self.context, 'screening_score'): |
---|
310 | form_fields = form_fields.omit('screening_score') |
---|
311 | if not getattr(self.context, 'screening_venue'): |
---|
312 | form_fields = form_fields.omit('screening_venue') |
---|
313 | if not getattr(self.context, 'screening_date'): |
---|
314 | form_fields = form_fields.omit('screening_date') |
---|
315 | return form_fields |
---|
316 | |
---|
317 | class RefereeReportAddFormPage(RefereeReportAddFormPage): |
---|
318 | """Add-form to add an referee report. This form |
---|
319 | is protected by a mandate. |
---|
320 | """ |
---|
321 | form_fields = grok.AutoFields( |
---|
322 | ICustomApplicantRefereeReport).omit('creation_date') |
---|
323 | |
---|
324 | class CustomRefereeReportDisplayFormPage(RefereeReportDisplayFormPage): |
---|
325 | """A display view for referee reports. |
---|
326 | """ |
---|
327 | form_fields = grok.AutoFields(ICustomApplicantRefereeReport) |
---|
328 | form_fields[ |
---|
329 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
330 | |
---|
331 | |
---|
332 | class CustomExportPDFReportSlipPage(ExportPDFReportSlipPage): |
---|
333 | form_fields = grok.AutoFields(ICustomApplicantRefereeReport) |
---|
334 | form_fields[ |
---|
335 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
336 | |
---|
337 | class CustomExportPDFReportSlipPage2(ExportPDFReportSlipPage2): |
---|
338 | form_fields = grok.AutoFields(ICustomApplicantRefereeReport) |
---|
339 | form_fields[ |
---|
340 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
341 | |
---|
342 | class ResultStatement(AdditionalFile): |
---|
343 | grok.name('res_stat.pdf') |
---|
344 | |
---|
345 | class JAMBResult(AdditionalFile): |
---|
346 | grok.name('jamb.pdf') |
---|
347 | |
---|
348 | class FirstSitting(AdditionalFile): |
---|
349 | grok.name('fst_sit_scan.pdf') |
---|
350 | |
---|
351 | class SecondSitting(AdditionalFile): |
---|
352 | grok.name('scd_sit_scan.pdf') |
---|
353 | |
---|
354 | class HighQual(AdditionalFile): |
---|
355 | grok.name('hq_scan.pdf') |
---|
356 | |
---|
357 | class AdvancedLevelResult(AdditionalFile): |
---|
358 | grok.name('alr_scan.pdf') |
---|
359 | |
---|
360 | class NYSCCertificate(AdditionalFile): |
---|
361 | grok.name('nysc.pdf') |
---|