source: main/waeup.aaue/trunk/src/waeup/aaue/applicants/browser.py @ 14331

Last change on this file since 14331 was 14304, checked in by Henrik Bettermann, 8 years ago

Add 'certificate request' components.

  • Property svn:keywords set to Id
File size: 18.7 KB
Line 
1## $Id: browser.py 14304 2016-12-02 10:34:05Z 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"""
20import grok
21import os
22from zope.component import getUtility, getAdapter
23from zope.i18n import translate
24from hurry.workflow.interfaces import IWorkflowState
25from waeup.kofa.interfaces import (
26    IExtFileStore, IFileStoreNameChooser, IKofaUtils)
27from zope.formlib.textwidgets import BytesDisplayWidget
28from waeup.kofa.utils.helpers import string_from_bytes, file_size
29from waeup.kofa.applicants.browser import (
30    ApplicantCheckStatusPage, ApplicantBaseDisplayFormPage)
31from waeup.kofa.applicants.workflow import STARTED, PAID
32from waeup.kofa.applicants.viewlets import PDFActionButton
33from waeup.kofa.browser.layout import UtilityView
34from waeup.kofa.students.interfaces import IStudentsUtils
35from waeup.kofa.interfaces import IPDF
36from waeup.kofa.browser.viewlets import ManageActionButton
37from waeup.aaue.interfaces import MessageFactory as _
38from kofacustom.nigeria.applicants.browser import (
39    NigeriaApplicantDisplayFormPage,
40    NigeriaApplicantManageFormPage,
41    NigeriaApplicantEditFormPage,
42    NigeriaPDFApplicationSlip,
43    NigeriaApplicantRegistrationPage,
44    NigeriaExportPDFPaymentSlipPage,
45    )
46from kofacustom.nigeria.applicants.interfaces import OMIT_DISPLAY_FIELDS
47from waeup.aaue.applicants.interfaces import (
48    ICustomUGApplicant,
49    ICustomUGApplicantEdit,
50    ITranscriptApplicant,
51    ICertificateRequest,
52    ICustomApplicant
53    )
54
55UG_OMIT_FIELDS = (
56      'hq_type', 'hq_fname', 'hq_matric_no',
57      'hq_degree', 'hq_school', 'hq_session', 'hq_disc',
58      'hq_type2', 'hq_fname2', 'hq_matric_no2',
59      'hq_degree2', 'hq_school2', 'hq_session2', 'hq_disc2',
60      'hq_type3', 'hq_fname3', 'hq_matric_no3',
61      'hq_degree3', 'hq_school3', 'hq_session3', 'hq_disc3',
62      'nysc_year',
63      'nysc_location',
64      'nysc_lga',
65      'employer',
66      'emp_position',
67      'emp_start',
68      'emp_end',
69      'emp_reason',
70      'employer2',
71      'emp2_position',
72      'emp2_start',
73      'emp2_end',
74      'emp2_reason',
75      'former_matric',
76      )
77UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
78    'jamb_subjects_list', 'master_sheet_number') + UG_OMIT_FIELDS
79UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + UG_OMIT_FIELDS + (
80      'reg_number','alr_fname', 'alr_no', 'alr_date',
81      'alr_results', 'notice')
82UG_OMIT_MANAGE_FIELDS = (
83    'special_application','jamb_subjects_list',) + UG_OMIT_FIELDS
84UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
85    'student_id',
86    'notice',
87    'jamb_age',
88    'jamb_subjects',
89    'jamb_score',
90    'jamb_reg_number',
91    'aggregate',
92    'master_sheet_number',
93    'screening_venue',
94    'screening_score',
95    'screening_date'
96    )
97
98UDE_OMIT_FIELDS = (
99      'nysc_year',
100      'nysc_location',
101      'nysc_lga',
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      'former_matric',
113      )
114UDE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
115    'jamb_subjects_list', 'master_sheet_number') + UDE_OMIT_FIELDS
116UDE_OMIT_PDF_FIELDS = UDE_OMIT_DISPLAY_FIELDS + UDE_OMIT_FIELDS + (
117      'reg_number','alr_fname', 'alr_no', 'alr_date',
118      'alr_results', 'notice')
119UDE_OMIT_MANAGE_FIELDS = (
120    'special_application','jamb_subjects_list',) + UDE_OMIT_FIELDS
121UDE_OMIT_EDIT_FIELDS = UDE_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
122    'student_id',
123    'notice',
124    'jamb_age',
125    'jamb_subjects',
126    'jamb_score',
127    'jamb_reg_number',
128    'aggregate',
129    'master_sheet_number',
130    'screening_venue',
131    'screening_score',
132    'screening_date'
133    )
134
135#UG_OMIT_PDF_FIELDS = tuple([
136#    element for element in UG_OMIT_PDF_FIELDS if not element == 'phone'])
137
138#UG_OMIT_PDF_FIELDS += (
139#      'reg_number','alr_fname', 'alr_no', 'alr_date',
140#      'alr_results', 'notice'
141#      )
142
143PG_OMIT_FIELDS = (
144    'fst_sit_fname',
145    'fst_sit_no',
146    'fst_sit_date',
147    'fst_sit_type',
148    'fst_sit_results',
149    'scd_sit_fname',
150    'scd_sit_no',
151    'scd_sit_date',
152    'scd_sit_type',
153    'scd_sit_results',
154    #'programme_type',
155    'jamb_age',
156    'jamb_subjects',
157    'jamb_score',
158    'jamb_reg_number',
159    'aggregate'
160    )
161PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
162    'jamb_subjects_list',) + PG_OMIT_FIELDS
163PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + PG_OMIT_FIELDS + (
164      'reg_number','alr_fname', 'alr_no', 'alr_date',
165      'alr_results', 'notice',
166      'nysc_year',
167      'nysc_location',
168      'nysc_lga',
169      'former_matric',
170      )
171PG_OMIT_MANAGE_FIELDS = (
172    'special_application','jamb_subjects_list',) + PG_OMIT_FIELDS
173PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
174    'student_id',
175    'notice',
176    )
177
178PTEE_OMIT_FIELDS = (
179    'jamb_age',
180    'jamb_subjects',
181    'jamb_score',
182    'jamb_reg_number',
183    'aggregate'
184    )
185PTEE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
186    'jamb_subjects_list',) + PTEE_OMIT_FIELDS
187PTEE_OMIT_PDF_FIELDS = PTEE_OMIT_DISPLAY_FIELDS + PTEE_OMIT_FIELDS + (
188      'reg_number','alr_fname', 'alr_no', 'alr_date',
189      'alr_results', 'notice',
190      'nysc_year',
191      'nysc_location',
192      'nysc_lga',
193      'employer',
194      'emp_position',
195      'emp_start',
196      'emp_end',
197      'emp_reason',
198      'employer2',
199      'emp2_position',
200      'emp2_start',
201      'emp2_end',
202      'emp2_reason',
203      'former_matric',
204    )
205PTEE_OMIT_MANAGE_FIELDS = (
206    'special_application','jamb_subjects_list',) + PTEE_OMIT_FIELDS
207PTEE_OMIT_EDIT_FIELDS = PTEE_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
208    'student_id',
209    'notice',
210    )
211
212UPDATE_OMIT_FIELDS = (
213    'firstname',
214    'middlename',
215    'lastname',
216    'sex',
217    'lga',
218    'course1',
219    )
220
221class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
222    """A display view for applicant data.
223    """
224
225    @property
226    def form_fields(self):
227        if self.target is not None and self.target == 'trans':
228            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
229                'locked', 'suspended')
230            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
231            form_fields['perm_address'].custom_widget = BytesDisplayWidget
232            return form_fields
233        if self.target is not None and self.target == 'cert':
234            form_fields = grok.AutoFields(ICertificateRequest).omit(
235                'locked', 'suspended')
236            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
237            form_fields['perm_address'].custom_widget = BytesDisplayWidget
238            return form_fields
239        # AAUE is using the same interface for all regular applications.
240        form_fields = grok.AutoFields(ICustomUGApplicant)
241        if self.target is not None and self.target.startswith('pg'):
242            for field in PG_OMIT_DISPLAY_FIELDS:
243                form_fields = form_fields.omit(field)
244        elif self.target is not None and self.target in ('ptee',):
245            for field in PTEE_OMIT_DISPLAY_FIELDS:
246                form_fields = form_fields.omit(field)
247        elif self.target is not None and self.target in ('ude',):
248            for field in UDE_OMIT_DISPLAY_FIELDS:
249                form_fields = form_fields.omit(field)
250        else:
251            for field in UG_OMIT_DISPLAY_FIELDS:
252                form_fields = form_fields.omit(field)
253        form_fields['perm_address'].custom_widget = BytesDisplayWidget
254        form_fields['notice'].custom_widget = BytesDisplayWidget
255        if not getattr(self.context, 'student_id'):
256            form_fields = form_fields.omit('student_id')
257        if not getattr(self.context, 'screening_score'):
258            form_fields = form_fields.omit('screening_score')
259        if not getattr(self.context, 'screening_venue'):
260            form_fields = form_fields.omit('screening_venue')
261        if not getattr(self.context, 'screening_date'):
262            form_fields = form_fields.omit('screening_date')
263        return form_fields
264
265class CustomPDFActionButton(PDFActionButton):
266
267    @property
268    def target_url(self):
269        if self.context.state in ('initialized', 'started', 'paid') \
270            or self.context.special or self.view.target in ('trans', 'cert'):
271            return
272        return self.view.url(self.view.context, self.target)
273
274
275class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
276
277    column_two_fields = ('applicant_id', 'reg_number',
278        'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth')
279    #two_columns_design_fields = [
280    #    'fst_sit_fname', 'fst_sit_no', 'fst_sit_date',
281    #    'fst_sit_type', 'fst_sit_results',
282    #    'scd_sit_fname', 'scd_sit_no', 'scd_sit_date',
283    #    'scd_sit_type', 'scd_sit_results']
284
285
286    def _getCourseAdmittedLink(self, view):
287        return None
288
289    def _getDeptAndFaculty(self):
290        return [None, None]
291
292    @property
293    def note(self):
294        note = getattr(self.context.__parent__, 'application_slip_notice', None)
295        if note:
296            return '<br /><br />' + note
297        if self.context.sex == 'm':
298            pronoun = 'he'
299        else:
300            pronoun = 'she'
301        return '''
302The applicant has acknowledged that, if discovered at any time that %s does not possess
303any of the qualifications which %s claims %s has obtained, %s will be expelled from the
304University not be re-admitted for the same or any other programme, even if %s has
305upgraded previous qualifications or possess additional qualifications.
306
307''' % (
308    pronoun, pronoun, pronoun, pronoun, pronoun)
309
310    @property
311    def form_fields(self):
312        # AAUE is using the same interface for all regular applications.
313        form_fields = grok.AutoFields(ICustomUGApplicant)
314        if self.target is not None and self.target.startswith('pg'):
315            for field in PG_OMIT_PDF_FIELDS:
316                form_fields = form_fields.omit(field)
317        elif self.target is not None and self.target in ('ptee',):
318            for field in PTEE_OMIT_PDF_FIELDS:
319                form_fields = form_fields.omit(field)
320        elif self.target is not None and self.target in ('ude',):
321            for field in UDE_OMIT_PDF_FIELDS:
322                form_fields = form_fields.omit(field)
323        else:
324            for field in UG_OMIT_PDF_FIELDS:
325                form_fields = form_fields.omit(field)
326        if not getattr(self.context, 'student_id'):
327            form_fields = form_fields.omit('student_id')
328        if not getattr(self.context, 'screening_score'):
329            form_fields = form_fields.omit('screening_score')
330        if not getattr(self.context, 'screening_venue'):
331            form_fields = form_fields.omit('screening_venue')
332        if not getattr(self.context, 'screening_date'):
333            form_fields = form_fields.omit('screening_date')
334        return form_fields
335
336class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
337    """A full edit view for applicant data.
338    """
339
340    @property
341    def form_fields(self):
342        if self.target is not None and self.target == 'trans':
343            form_fields = grok.AutoFields(ITranscriptApplicant)
344            form_fields['applicant_id'].for_display = True
345            return form_fields
346        if self.target is not None and self.target == 'cert':
347            form_fields = grok.AutoFields(ICertificateRequest)
348            form_fields['applicant_id'].for_display = True
349            return form_fields
350        # AAUE is using the same interface for all regular applications.
351        form_fields = grok.AutoFields(ICustomUGApplicant)
352        if self.target is not None and self.target.startswith('pg'):
353            for field in PG_OMIT_MANAGE_FIELDS:
354                form_fields = form_fields.omit(field)
355        elif self.target is not None and self.target in ('ptee',):
356            for field in PTEE_OMIT_MANAGE_FIELDS:
357                form_fields = form_fields.omit(field)
358        elif self.target is not None and self.target in ('ude',):
359            for field in UDE_OMIT_MANAGE_FIELDS:
360                form_fields = form_fields.omit(field)
361        else:
362            for field in UG_OMIT_MANAGE_FIELDS:
363                form_fields = form_fields.omit(field)
364        form_fields['student_id'].for_display = True
365        form_fields['applicant_id'].for_display = True
366        return form_fields
367
368class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
369    """An applicant-centered edit view for applicant data.
370    """
371
372    def unremovable(self, ticket):
373        return True
374
375    # AAUE applicants never see the 'Remove Selected Tickets' button.
376    @property
377    def display_actions(self):
378        state = IWorkflowState(self.context).getState()
379        # If the form is unlocked, applicants are allowed to save the form
380        # and remove unused tickets.
381        actions = [[_('Save')], []]
382        # Only in state started they can also add tickets.
383        if state == STARTED:
384            actions = [[_('Save')],
385                [_('Add online payment ticket')]]
386        # In state paid, they can submit the data and further add tickets
387        # if the application is special.
388        elif self.context.special and state == PAID:
389            actions = [[_('Save'), _('Finally Submit')],
390                [_('Add online payment ticket')]]
391        elif state == PAID:
392            actions = [[_('Save'), _('Finally Submit')], []]
393        return actions
394
395    @property
396    def form_fields(self):
397        if self.target is not None and self.target == 'trans':
398            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
399                'locked', 'suspended')
400            form_fields['applicant_id'].for_display = True
401            return form_fields
402        if self.target is not None and self.target == 'cert':
403            form_fields = grok.AutoFields(ICertificateRequest).omit(
404                'locked', 'suspended')
405            form_fields['applicant_id'].for_display = True
406            return form_fields
407        # AAUE is using the same interface for all regular applications.
408        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
409        if self.target is not None and self.target.startswith('pg'):
410            for field in PG_OMIT_EDIT_FIELDS:
411                form_fields = form_fields.omit(field)
412        elif self.target is not None and self.target in ('ptee',):
413            for field in PTEE_OMIT_EDIT_FIELDS:
414                form_fields = form_fields.omit(field)
415        elif self.target is not None and self.target in ('ude',):
416            for field in UDE_OMIT_EDIT_FIELDS:
417                form_fields = form_fields.omit(field)
418        else:
419            for field in UG_OMIT_EDIT_FIELDS:
420                form_fields = form_fields.omit(field)
421        # Additional omissions
422        if self.target is not None and self.target in ('ude', 'utme'):
423            for field in UPDATE_OMIT_FIELDS:
424                form_fields[field].for_display = True
425        form_fields['applicant_id'].for_display = True
426        form_fields['reg_number'].for_display = True
427        return form_fields
428
429class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage):
430    """Captcha'd registration page for applicants.
431    """
432
433    def _redirect(self, email, password, applicant_id):
434        # Forward email and credentials to landing page.
435        self.redirect(self.url(self.context, 'registration_complete',
436            data = dict(email=email, password=password,
437            applicant_id=applicant_id)))
438        return
439
440class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
441
442    @property
443    def payment_slip_download_warning(self):
444        return ''
445
446class CustomApplicantCheckStatusPage(ApplicantCheckStatusPage):
447    """Captcha'd status checking page for applicants.
448    """
449    grok.template('applicantcheckstatus')
450
451class PaymentReceiptActionButton(ManageActionButton):
452    grok.order(8) # This button should always be the last one.
453    grok.context(ICustomApplicant)
454    grok.view(CustomApplicantDisplayFormPage)
455    grok.require('waeup.viewApplication')
456    icon = 'actionicon_pdf.png'
457    text = _('Download screening invitation letter')
458    target = 'screening_invitation.pdf'
459
460    @property
461    def target_url(self):
462        if not self.context.screening_date:
463            return ''
464        return self.view.url(self.view.context, self.target)
465
466class ExportScreeningInvitationLetter(UtilityView, grok.View):
467    """Deliver a slip with only screening data.
468    This form page is available only in AAUE.
469    """
470    grok.context(ICustomApplicant)
471    grok.name('screening_invitation.pdf')
472    grok.require('waeup.viewApplication')
473    prefix = 'form'
474
475    label = u'Screening Invitation Letter'
476
477    form_fields = []
478
479    @property
480    def note(self):
481        if self.context.screening_date:
482            year = self.context.__parent__.year
483            session = '%s/%s' % (year, year + 1)
484            sdate = self.context.screening_date
485            stime = ''
486            if '@' in self.context.screening_date:
487                sdate = self.context.screening_date.split('@')[0].strip()
488                stime = self.context.screening_date.split('@')[1].strip()
489            return """
490<br /><br /><br /><br /><font size='12'>
491Dear %s,
492<br /><br />
493You are invited to the Ambrose Alli University %s Admissions Screening Exercise.
494<br /><br />
495<strong>Date: %s
496<br /><br />
497Time: %s
498<br /><br />
499Venue: %s
500</strong>
501<br /><br />
502Please bring this letter of invitation and the downloaded application form along with you on your screening date.
503<br /><br />
504You are expected to be available 30 minutes before the commencement of your Screening.
505</font>
506
507""" % (
508       self.context.display_fullname,
509       session,
510       sdate,
511       stime,
512       self.context.screening_venue)
513        return
514
515    @property
516    def title(self):
517        return None
518
519    def update(self):
520        if not self.context.screening_date:
521            self.flash(_('Forbidden'), type="warning")
522            self.redirect(self.url(self.context))
523
524    def render(self):
525        applicantview = ApplicantBaseDisplayFormPage(self.context, self.request)
526        students_utils = getUtility(IStudentsUtils)
527        return students_utils.renderPDF(self,'screening_data.pdf',
528            self.context, applicantview, note=self.note)
Note: See TracBrowser for help on using the repository browser.