1 | ## $Id: browser.py 14017 2016-07-07 06:43:21Z 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, getAdapter |
---|
23 | from zope.i18n import translate |
---|
24 | from waeup.kofa.interfaces import ( |
---|
25 | IExtFileStore, IFileStoreNameChooser, IKofaUtils) |
---|
26 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
27 | from waeup.kofa.utils.helpers import string_from_bytes, file_size |
---|
28 | from waeup.kofa.applicants.browser import ( |
---|
29 | ApplicantCheckStatusPage, ApplicantBaseDisplayFormPage) |
---|
30 | from waeup.kofa.applicants.viewlets import PDFActionButton |
---|
31 | from waeup.kofa.browser.layout import UtilityView |
---|
32 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
33 | from waeup.kofa.interfaces import IPDF |
---|
34 | from waeup.kofa.browser.viewlets import ManageActionButton |
---|
35 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
36 | from kofacustom.nigeria.applicants.browser import ( |
---|
37 | NigeriaApplicantDisplayFormPage, |
---|
38 | NigeriaApplicantManageFormPage, |
---|
39 | NigeriaApplicantEditFormPage, |
---|
40 | NigeriaPDFApplicationSlip, |
---|
41 | NigeriaApplicantRegistrationPage, |
---|
42 | NigeriaExportPDFPaymentSlipPage, |
---|
43 | ) |
---|
44 | from kofacustom.nigeria.applicants.interfaces import OMIT_DISPLAY_FIELDS |
---|
45 | from waeup.aaue.applicants.interfaces import ( |
---|
46 | ICustomUGApplicant, |
---|
47 | ICustomUGApplicantEdit, |
---|
48 | ITranscriptApplicant, |
---|
49 | ICustomApplicant |
---|
50 | ) |
---|
51 | |
---|
52 | UG_OMIT_FIELDS = ( |
---|
53 | 'hq_type', 'hq_fname', 'hq_matric_no', |
---|
54 | 'hq_degree', 'hq_school', 'hq_session', 'hq_disc', |
---|
55 | 'hq_type2', 'hq_fname2', 'hq_matric_no2', |
---|
56 | 'hq_degree2', 'hq_school2', 'hq_session2', 'hq_disc2', |
---|
57 | 'hq_type3', 'hq_fname3', 'hq_matric_no3', |
---|
58 | 'hq_degree3', 'hq_school3', 'hq_session3', 'hq_disc3', |
---|
59 | 'nysc_year', |
---|
60 | 'nysc_location', |
---|
61 | 'nysc_lga', |
---|
62 | 'employer', |
---|
63 | 'emp_position', |
---|
64 | 'emp_start', |
---|
65 | 'emp_end', |
---|
66 | 'emp_reason', |
---|
67 | 'employer2', |
---|
68 | 'emp2_position', |
---|
69 | 'emp2_start', |
---|
70 | 'emp2_end', |
---|
71 | 'emp2_reason', |
---|
72 | 'former_matric', |
---|
73 | ) |
---|
74 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
75 | 'jamb_subjects_list', 'master_sheet_number') + UG_OMIT_FIELDS |
---|
76 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + UG_OMIT_FIELDS + ( |
---|
77 | 'reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
78 | 'alr_results', 'notice') |
---|
79 | UG_OMIT_MANAGE_FIELDS = ( |
---|
80 | 'special_application','jamb_subjects_list',) + UG_OMIT_FIELDS |
---|
81 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
82 | 'student_id', |
---|
83 | 'notice', |
---|
84 | 'jamb_age', |
---|
85 | 'jamb_subjects', |
---|
86 | 'jamb_score', |
---|
87 | 'jamb_reg_number', |
---|
88 | 'aggregate', |
---|
89 | |
---|
90 | 'firstname', |
---|
91 | 'middlename', |
---|
92 | 'lastname', |
---|
93 | 'sex', |
---|
94 | 'lga', |
---|
95 | 'course1', |
---|
96 | 'master_sheet_number', |
---|
97 | 'screening_venue', |
---|
98 | 'screening_score', |
---|
99 | 'screening_date' |
---|
100 | ) |
---|
101 | |
---|
102 | #UG_OMIT_PDF_FIELDS = tuple([ |
---|
103 | # element for element in UG_OMIT_PDF_FIELDS if not element == 'phone']) |
---|
104 | |
---|
105 | #UG_OMIT_PDF_FIELDS += ( |
---|
106 | # 'reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
107 | # 'alr_results', 'notice' |
---|
108 | # ) |
---|
109 | |
---|
110 | PG_OMIT_FIELDS = ( |
---|
111 | 'fst_sit_fname', |
---|
112 | 'fst_sit_no', |
---|
113 | 'fst_sit_date', |
---|
114 | 'fst_sit_type', |
---|
115 | 'fst_sit_results', |
---|
116 | 'scd_sit_fname', |
---|
117 | 'scd_sit_no', |
---|
118 | 'scd_sit_date', |
---|
119 | 'scd_sit_type', |
---|
120 | 'scd_sit_results', |
---|
121 | #'programme_type', |
---|
122 | 'jamb_age', |
---|
123 | 'jamb_subjects', |
---|
124 | 'jamb_score', |
---|
125 | 'jamb_reg_number', |
---|
126 | 'aggregate' |
---|
127 | ) |
---|
128 | PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
129 | 'jamb_subjects_list',) + PG_OMIT_FIELDS |
---|
130 | PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + PG_OMIT_FIELDS + ( |
---|
131 | 'reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
132 | 'alr_results', 'notice', |
---|
133 | 'nysc_year', |
---|
134 | 'nysc_location', |
---|
135 | 'nysc_lga', |
---|
136 | 'former_matric', |
---|
137 | ) |
---|
138 | PG_OMIT_MANAGE_FIELDS = ( |
---|
139 | 'special_application','jamb_subjects_list',) + PG_OMIT_FIELDS |
---|
140 | PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
141 | 'student_id', |
---|
142 | 'notice', |
---|
143 | ) |
---|
144 | |
---|
145 | PTEE_OMIT_FIELDS = ( |
---|
146 | 'jamb_age', |
---|
147 | 'jamb_subjects', |
---|
148 | 'jamb_score', |
---|
149 | 'jamb_reg_number', |
---|
150 | 'aggregate' |
---|
151 | ) |
---|
152 | PTEE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
153 | 'jamb_subjects_list',) + PTEE_OMIT_FIELDS |
---|
154 | PTEE_OMIT_PDF_FIELDS = PTEE_OMIT_DISPLAY_FIELDS + PTEE_OMIT_FIELDS + ( |
---|
155 | 'reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
156 | 'alr_results', 'notice', |
---|
157 | 'nysc_year', |
---|
158 | 'nysc_location', |
---|
159 | 'nysc_lga', |
---|
160 | 'employer', |
---|
161 | 'emp_position', |
---|
162 | 'emp_start', |
---|
163 | 'emp_end', |
---|
164 | 'emp_reason', |
---|
165 | 'employer2', |
---|
166 | 'emp2_position', |
---|
167 | 'emp2_start', |
---|
168 | 'emp2_end', |
---|
169 | 'emp2_reason', |
---|
170 | 'former_matric', |
---|
171 | ) |
---|
172 | PTEE_OMIT_MANAGE_FIELDS = ( |
---|
173 | 'special_application','jamb_subjects_list',) + PTEE_OMIT_FIELDS |
---|
174 | PTEE_OMIT_EDIT_FIELDS = PTEE_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
175 | 'student_id', |
---|
176 | 'notice', |
---|
177 | ) |
---|
178 | |
---|
179 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
180 | """A display view for applicant data. |
---|
181 | """ |
---|
182 | |
---|
183 | @property |
---|
184 | def form_fields(self): |
---|
185 | if self.target is not None and self.target == 'trans': |
---|
186 | form_fields = grok.AutoFields(ITranscriptApplicant).omit( |
---|
187 | 'locked', 'suspended') |
---|
188 | form_fields['dispatch_address'].custom_widget = BytesDisplayWidget |
---|
189 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
190 | return form_fields |
---|
191 | # AAUE is using the same interface for all regular applications. |
---|
192 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
193 | if self.target is not None and self.target.startswith('pg'): |
---|
194 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
195 | form_fields = form_fields.omit(field) |
---|
196 | elif self.target is not None and self.target in ('ptee', 'ude'): |
---|
197 | for field in PTEE_OMIT_DISPLAY_FIELDS: |
---|
198 | form_fields = form_fields.omit(field) |
---|
199 | else: |
---|
200 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
201 | form_fields = form_fields.omit(field) |
---|
202 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
203 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
204 | if not getattr(self.context, 'student_id'): |
---|
205 | form_fields = form_fields.omit('student_id') |
---|
206 | if not getattr(self.context, 'screening_score'): |
---|
207 | form_fields = form_fields.omit('screening_score') |
---|
208 | if not getattr(self.context, 'screening_venue'): |
---|
209 | form_fields = form_fields.omit('screening_venue') |
---|
210 | if not getattr(self.context, 'screening_date'): |
---|
211 | form_fields = form_fields.omit('screening_date') |
---|
212 | return form_fields |
---|
213 | |
---|
214 | class CustomPDFActionButton(PDFActionButton): |
---|
215 | |
---|
216 | @property |
---|
217 | def target_url(self): |
---|
218 | if self.context.state in ('initialized', 'started', 'paid') \ |
---|
219 | or self.context.special or self.view.target == 'trans': |
---|
220 | return |
---|
221 | return self.view.url(self.view.context, self.target) |
---|
222 | |
---|
223 | |
---|
224 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
225 | |
---|
226 | column_two_fields = ('applicant_id', 'reg_number', |
---|
227 | 'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth') |
---|
228 | #two_columns_design_fields = [ |
---|
229 | # 'fst_sit_fname', 'fst_sit_no', 'fst_sit_date', |
---|
230 | # 'fst_sit_type', 'fst_sit_results', |
---|
231 | # 'scd_sit_fname', 'scd_sit_no', 'scd_sit_date', |
---|
232 | # 'scd_sit_type', 'scd_sit_results'] |
---|
233 | |
---|
234 | @property |
---|
235 | def note(self): |
---|
236 | if self.context.sex == 'm': |
---|
237 | pronoun = 'he' |
---|
238 | else: |
---|
239 | pronoun = 'she' |
---|
240 | return ''' |
---|
241 | The applicant has acknowledged that, if discovered at any time that %s does not possess |
---|
242 | any of the qualifications which %s claims %s has obtained, %s will be expelled from the |
---|
243 | University not be re-admitted for the same or any other programme, even if %s has |
---|
244 | upgraded previous and shall qualifications or possess additional qualifications. |
---|
245 | ''' % ( |
---|
246 | pronoun, pronoun, pronoun, pronoun, pronoun) |
---|
247 | |
---|
248 | @property |
---|
249 | def form_fields(self): |
---|
250 | # AAUE is using the same interface for all regular applications. |
---|
251 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
252 | if self.target is not None and self.target.startswith('pg'): |
---|
253 | for field in PG_OMIT_PDF_FIELDS: |
---|
254 | form_fields = form_fields.omit(field) |
---|
255 | elif self.target is not None and self.target in ('ptee', 'ude'): |
---|
256 | for field in PTEE_OMIT_PDF_FIELDS: |
---|
257 | form_fields = form_fields.omit(field) |
---|
258 | else: |
---|
259 | for field in UG_OMIT_PDF_FIELDS: |
---|
260 | form_fields = form_fields.omit(field) |
---|
261 | if not getattr(self.context, 'student_id'): |
---|
262 | form_fields = form_fields.omit('student_id') |
---|
263 | if not getattr(self.context, 'screening_score'): |
---|
264 | form_fields = form_fields.omit('screening_score') |
---|
265 | if not getattr(self.context, 'screening_venue'): |
---|
266 | form_fields = form_fields.omit('screening_venue') |
---|
267 | if not getattr(self.context, 'screening_date'): |
---|
268 | form_fields = form_fields.omit('screening_date') |
---|
269 | return form_fields |
---|
270 | |
---|
271 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
272 | """A full edit view for applicant data. |
---|
273 | """ |
---|
274 | |
---|
275 | @property |
---|
276 | def form_fields(self): |
---|
277 | if self.target is not None and self.target == 'trans': |
---|
278 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
279 | form_fields['applicant_id'].for_display = True |
---|
280 | return form_fields |
---|
281 | # AAUE is using the same interface for all regular applications. |
---|
282 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
283 | if self.target is not None and self.target.startswith('pg'): |
---|
284 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
285 | form_fields = form_fields.omit(field) |
---|
286 | elif self.target is not None and self.target in ('ptee', 'ude'): |
---|
287 | for field in PTEE_OMIT_MANAGE_FIELDS: |
---|
288 | form_fields = form_fields.omit(field) |
---|
289 | else: |
---|
290 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
291 | form_fields = form_fields.omit(field) |
---|
292 | form_fields['student_id'].for_display = True |
---|
293 | form_fields['applicant_id'].for_display = True |
---|
294 | return form_fields |
---|
295 | |
---|
296 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
297 | """An applicant-centered edit view for applicant data. |
---|
298 | """ |
---|
299 | |
---|
300 | grok.template('applicanteditpage') |
---|
301 | |
---|
302 | @property |
---|
303 | def form_fields(self): |
---|
304 | if self.target is not None and self.target == 'trans': |
---|
305 | form_fields = grok.AutoFields(ITranscriptApplicant).omit( |
---|
306 | 'locked', 'suspended') |
---|
307 | form_fields['applicant_id'].for_display = True |
---|
308 | return form_fields |
---|
309 | # AAUE is using the same interface for all regular applications. |
---|
310 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
311 | if self.target is not None and self.target.startswith('pg'): |
---|
312 | for field in PG_OMIT_EDIT_FIELDS: |
---|
313 | form_fields = form_fields.omit(field) |
---|
314 | elif self.target is not None and self.target in ('ptee', 'ude'): |
---|
315 | for field in PTEE_OMIT_EDIT_FIELDS: |
---|
316 | form_fields = form_fields.omit(field) |
---|
317 | else: |
---|
318 | for field in UG_OMIT_EDIT_FIELDS: |
---|
319 | form_fields = form_fields.omit(field) |
---|
320 | form_fields['applicant_id'].for_display = True |
---|
321 | form_fields['reg_number'].for_display = True |
---|
322 | return form_fields |
---|
323 | |
---|
324 | class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage): |
---|
325 | """Captcha'd registration page for applicants. |
---|
326 | """ |
---|
327 | |
---|
328 | def _redirect(self, email, password, applicant_id): |
---|
329 | # Forward email and credentials to landing page. |
---|
330 | self.redirect(self.url(self.context, 'registration_complete', |
---|
331 | data = dict(email=email, password=password, |
---|
332 | applicant_id=applicant_id))) |
---|
333 | return |
---|
334 | |
---|
335 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
336 | |
---|
337 | @property |
---|
338 | def payment_slip_download_warning(self): |
---|
339 | return '' |
---|
340 | |
---|
341 | class CustomApplicantCheckStatusPage(ApplicantCheckStatusPage): |
---|
342 | """Captcha'd status checking page for applicants. |
---|
343 | """ |
---|
344 | grok.template('applicantcheckstatus') |
---|
345 | |
---|
346 | class PaymentReceiptActionButton(ManageActionButton): |
---|
347 | grok.order(8) # This button should always be the last one. |
---|
348 | grok.context(ICustomApplicant) |
---|
349 | grok.view(CustomApplicantDisplayFormPage) |
---|
350 | grok.require('waeup.viewApplication') |
---|
351 | icon = 'actionicon_pdf.png' |
---|
352 | text = _('Download screening invitation letter') |
---|
353 | target = 'screening_invitation.pdf' |
---|
354 | |
---|
355 | @property |
---|
356 | def target_url(self): |
---|
357 | if not self.context.screening_date: |
---|
358 | return '' |
---|
359 | return self.view.url(self.view.context, self.target) |
---|
360 | |
---|
361 | class ExportScreeningInvitationLetter(UtilityView, grok.View): |
---|
362 | """Deliver a slip with only screening data. |
---|
363 | This form page is available only in AAUE. |
---|
364 | """ |
---|
365 | grok.context(ICustomApplicant) |
---|
366 | grok.name('screening_invitation.pdf') |
---|
367 | grok.require('waeup.viewApplication') |
---|
368 | prefix = 'form' |
---|
369 | |
---|
370 | label = u'Screening Invitation Letter' |
---|
371 | |
---|
372 | form_fields = [] |
---|
373 | |
---|
374 | @property |
---|
375 | def note(self): |
---|
376 | if self.context.screening_date: |
---|
377 | year = self.context.__parent__.year |
---|
378 | session = '%s/%s' % (year, year + 1) |
---|
379 | sdate = self.context.screening_date |
---|
380 | stime = '' |
---|
381 | if '@' in self.context.screening_date: |
---|
382 | sdate = self.context.screening_date.split('@')[0].strip() |
---|
383 | stime = self.context.screening_date.split('@')[1].strip() |
---|
384 | return """ |
---|
385 | <br /><br /><br /><br /><font size='12'> |
---|
386 | Dear %s, |
---|
387 | <br /><br /> |
---|
388 | You are invited to the Ambrose Alli University %s Admissions Screening Exercise. |
---|
389 | <br /><br /> |
---|
390 | <strong>Date: %s |
---|
391 | <br /><br /> |
---|
392 | Time: %s |
---|
393 | <br /><br /> |
---|
394 | Venue: %s |
---|
395 | </strong> |
---|
396 | <br /><br /> |
---|
397 | Please bring this letter of invitation and the downloaded application form along with you on your screening date. |
---|
398 | <br /><br /> |
---|
399 | You are expected to be available 30 minutes before the commencement of your Screening. |
---|
400 | </font> |
---|
401 | |
---|
402 | """ % ( |
---|
403 | self.context.display_fullname, |
---|
404 | session, |
---|
405 | sdate, |
---|
406 | stime, |
---|
407 | self.context.screening_venue) |
---|
408 | return |
---|
409 | |
---|
410 | @property |
---|
411 | def title(self): |
---|
412 | return None |
---|
413 | |
---|
414 | def update(self): |
---|
415 | if not self.context.screening_date: |
---|
416 | self.flash(_('Forbidden'), type="warning") |
---|
417 | self.redirect(self.url(self.context)) |
---|
418 | |
---|
419 | def render(self): |
---|
420 | applicantview = ApplicantBaseDisplayFormPage(self.context, self.request) |
---|
421 | students_utils = getUtility(IStudentsUtils) |
---|
422 | return students_utils.renderPDF(self,'screening_data.pdf', |
---|
423 | self.context, applicantview, note=self.note) |
---|