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

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

Change text.

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