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

Last change on this file since 16827 was 16786, checked in by Henrik Bettermann, 3 years ago

Customize referee report form.

  • Property svn:keywords set to Id
File size: 32.4 KB
RevLine 
[10298]1## $Id: browser.py 16786 2022-02-08 21:35:52Z 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
[13996]22from zope.component import getUtility, getAdapter
23from zope.i18n import translate
[15951]24from zope.catalog.interfaces import ICatalog
[14027]25from hurry.workflow.interfaces import IWorkflowState
[10298]26from waeup.kofa.interfaces import (
[13996]27    IExtFileStore, IFileStoreNameChooser, IKofaUtils)
[10298]28from zope.formlib.textwidgets import BytesDisplayWidget
[16003]29from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
[10298]30from waeup.kofa.utils.helpers import string_from_bytes, file_size
[13996]31from waeup.kofa.applicants.browser import (
[16003]32    ApplicantCheckStatusPage,
[16786]33    AdditionalFile,
34    RefereeReportAddFormPage,
35    RefereeReportDisplayFormPage,
36    ExportPDFReportSlipPage,
37    ExportPDFReportSlipPage2)
[14027]38from waeup.kofa.applicants.workflow import STARTED, PAID
[13538]39from waeup.kofa.applicants.viewlets import PDFActionButton
[14460]40from waeup.kofa.applicants.interfaces import IApplicantRegisterUpdate
[15951]41from waeup.kofa.browser.layout import UtilityView, action
[13996]42from waeup.kofa.students.interfaces import IStudentsUtils
43from waeup.kofa.interfaces import IPDF
[13997]44from waeup.kofa.browser.viewlets import ManageActionButton
[10298]45from waeup.aaue.interfaces import MessageFactory as _
46from kofacustom.nigeria.applicants.browser import (
47    NigeriaApplicantDisplayFormPage,
48    NigeriaApplicantManageFormPage,
49    NigeriaApplicantEditFormPage,
50    NigeriaPDFApplicationSlip,
[10929]51    NigeriaApplicantRegistrationPage,
[11755]52    NigeriaExportPDFPaymentSlipPage,
[13545]53    )
54from kofacustom.nigeria.applicants.interfaces import OMIT_DISPLAY_FIELDS
[10298]55from waeup.aaue.applicants.interfaces import (
56    ICustomUGApplicant,
[16763]57    ICustomPGApplicant,
[13544]58    ICustomUGApplicantEdit,
[16763]59    ICustomPGApplicantEdit,
[13996]60    ITranscriptApplicant,
[14304]61    ICertificateRequest,
[15530]62    ICustomApplicant,
[15531]63    IVerificationRequest,
[15950]64    ISendByEmailRequest,
[15991]65    IFedexRequest,
66    IRecruitment,
[16003]67    ICustomApplicantOnlinePayment,
[16786]68    ICustomApplicantRefereeReport,
[11291]69    )
[10298]70
[13545]71UG_OMIT_FIELDS = (
72      'hq_type', 'hq_fname', 'hq_matric_no',
73      'hq_degree', 'hq_school', 'hq_session', 'hq_disc',
74      'hq_type2', 'hq_fname2', 'hq_matric_no2',
75      'hq_degree2', 'hq_school2', 'hq_session2', 'hq_disc2',
76      'hq_type3', 'hq_fname3', 'hq_matric_no3',
[13679]77      'hq_degree3', 'hq_school3', 'hq_session3', 'hq_disc3',
78      'nysc_year',
79      'nysc_location',
80      'nysc_lga',
81      'employer',
82      'emp_position',
83      'emp_start',
84      'emp_end',
85      'emp_reason',
86      'employer2',
87      'emp2_position',
88      'emp2_start',
89      'emp2_end',
90      'emp2_reason',
91      'former_matric',
[13545]92      )
[13546]93UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
[13977]94    'jamb_subjects_list', 'master_sheet_number') + UG_OMIT_FIELDS
[13545]95UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + UG_OMIT_FIELDS + (
[14363]96      'alr_fname', 'alr_no', 'alr_date',
[13545]97      'alr_results', 'notice')
[13546]98UG_OMIT_MANAGE_FIELDS = (
99    'special_application','jamb_subjects_list',) + UG_OMIT_FIELDS
100UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
[13545]101    'student_id',
102    'notice',
103    'jamb_age',
104    'jamb_subjects',
105    'jamb_score',
106    'jamb_reg_number',
[13679]107    'aggregate',
[13977]108    'master_sheet_number',
[13996]109    'screening_venue',
110    'screening_score',
111    'screening_date'
[13679]112    )
[10298]113
[14209]114UDE_OMIT_FIELDS = (
115      'nysc_year',
116      'nysc_location',
117      'nysc_lga',
118      'employer',
119      'emp_position',
120      'emp_start',
121      'emp_end',
122      'emp_reason',
123      'employer2',
124      'emp2_position',
125      'emp2_start',
126      'emp2_end',
127      'emp2_reason',
128      'former_matric',
129      )
130UDE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
131    'jamb_subjects_list', 'master_sheet_number') + UDE_OMIT_FIELDS
132UDE_OMIT_PDF_FIELDS = UDE_OMIT_DISPLAY_FIELDS + UDE_OMIT_FIELDS + (
[15091]133      #'alr_fname', 'alr_no', 'alr_date', 'alr_results',
134      'hq_type2', 'hq_fname2', 'hq_matric_no2',
135      'hq_degree2', 'hq_school2', 'hq_session2', 'hq_disc2',
136      'hq_type3', 'hq_fname3', 'hq_matric_no3',
137      'hq_degree3', 'hq_school3', 'hq_session3', 'hq_disc3',
138      'notice')
[14209]139UDE_OMIT_MANAGE_FIELDS = (
140    'special_application','jamb_subjects_list',) + UDE_OMIT_FIELDS
141UDE_OMIT_EDIT_FIELDS = UDE_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
142    'student_id',
143    'notice',
144    'jamb_age',
145    'jamb_subjects',
146    'jamb_score',
147    'jamb_reg_number',
148    'aggregate',
149    'master_sheet_number',
150    'screening_venue',
151    'screening_score',
152    'screening_date'
153    )
154
[13545]155#UG_OMIT_PDF_FIELDS = tuple([
156#    element for element in UG_OMIT_PDF_FIELDS if not element == 'phone'])
[11291]157
[13545]158#UG_OMIT_PDF_FIELDS += (
159#      'reg_number','alr_fname', 'alr_no', 'alr_date',
160#      'alr_results', 'notice'
161#      )
[13538]162
[13545]163PG_OMIT_FIELDS = (
[16763]164
[13545]165    )
166PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
[16763]167    ) + PG_OMIT_FIELDS
[13545]168PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + PG_OMIT_FIELDS + (
[13679]169      )
[13545]170PG_OMIT_MANAGE_FIELDS = (
[16763]171    ) + PG_OMIT_FIELDS
[13546]172PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
173    )
[13545]174
[13679]175PTEE_OMIT_FIELDS = (
176    'jamb_age',
177    'jamb_subjects',
178    'jamb_score',
179    'jamb_reg_number',
180    'aggregate'
181    )
182PTEE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
183    'jamb_subjects_list',) + PTEE_OMIT_FIELDS
184PTEE_OMIT_PDF_FIELDS = PTEE_OMIT_DISPLAY_FIELDS + PTEE_OMIT_FIELDS + (
185      'reg_number','alr_fname', 'alr_no', 'alr_date',
186      'alr_results', 'notice',
187      'nysc_year',
188      'nysc_location',
189      'nysc_lga',
190      'employer',
191      'emp_position',
192      'emp_start',
193      'emp_end',
194      'emp_reason',
195      'employer2',
196      'emp2_position',
197      'emp2_start',
198      'emp2_end',
199      'emp2_reason',
200      'former_matric',
201    )
202PTEE_OMIT_MANAGE_FIELDS = (
203    'special_application','jamb_subjects_list',) + PTEE_OMIT_FIELDS
204PTEE_OMIT_EDIT_FIELDS = PTEE_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
205    'student_id',
206    'notice',
207    )
208
[14150]209UPDATE_OMIT_FIELDS = (
210    'firstname',
211    'middlename',
212    'lastname',
213    'sex',
214    'lga',
215    'course1',
216    )
217
[15113]218MAX_FILE_UPLOAD_SIZE = 1024 * 500
219
[10298]220class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
221    """A display view for applicant data.
222    """
223
224    @property
225    def form_fields(self):
[13538]226        if self.target is not None and self.target == 'trans':
[13544]227            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
[14580]228                'locked', 'suspended')
[13544]229            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
230            form_fields['perm_address'].custom_widget = BytesDisplayWidget
231            return form_fields
[15530]232        if self.target is not None and self.target == 'ver':
233            form_fields = grok.AutoFields(IVerificationRequest).omit(
234                'locked', 'suspended')
235            form_fields['body_address'].custom_widget = BytesDisplayWidget
236            return form_fields
[15950]237        if self.target is not None and self.target == 'fedex':
238            form_fields = grok.AutoFields(IFedexRequest).omit(
239                'locked', 'suspended')
[16003]240            return form_fields
[15991]241        if self.target is not None and self.target == 'rec':
242            form_fields = grok.AutoFields(IRecruitment).omit(
243                'locked', 'suspended')
244            form_fields['address'].custom_widget = BytesDisplayWidget
[15994]245            form_fields['position'].custom_widget = BytesDisplayWidget
[15950]246            return form_fields
[15531]247        if self.target is not None and self.target == 'send':
248            form_fields = grok.AutoFields(ISendByEmailRequest).omit(
249                'locked', 'suspended')
250            form_fields['body_address'].custom_widget = BytesDisplayWidget
251            return form_fields
[14304]252        if self.target is not None and self.target == 'cert':
253            form_fields = grok.AutoFields(ICertificateRequest).omit(
[14580]254                'locked', 'suspended')
[14304]255            return form_fields
[16763]256        if self.target is not None and self.target in ('ptee','dsh',):
257            form_fields = grok.AutoFields(ICustomUGApplicant)
[13679]258            for field in PTEE_OMIT_DISPLAY_FIELDS:
[10298]259                form_fields = form_fields.omit(field)
[15217]260        elif self.target is not None and self.target in ('bridge', 'ude',):
[16763]261            form_fields = grok.AutoFields(ICustomUGApplicant)
[14209]262            for field in UDE_OMIT_DISPLAY_FIELDS:
263                form_fields = form_fields.omit(field)
[16763]264        elif self.target is not None and self.target.startswith('pg'):
265            form_fields = grok.AutoFields(ICustomPGApplicant)
266            for field in PG_OMIT_DISPLAY_FIELDS:
267                form_fields = form_fields.omit(field)
[10298]268        else:
[16763]269            form_fields = grok.AutoFields(ICustomUGApplicant)
[10298]270            for field in UG_OMIT_DISPLAY_FIELDS:
271                form_fields = form_fields.omit(field)
272        if not getattr(self.context, 'student_id'):
273            form_fields = form_fields.omit('student_id')
274        if not getattr(self.context, 'screening_score'):
275            form_fields = form_fields.omit('screening_score')
[14840]276        if not getattr(self.context, 'screening_venue') or \
277            self.context.state not in ('submitted', 'admitted', 'created'):
[10298]278            form_fields = form_fields.omit('screening_venue')
[14840]279        if not getattr(self.context, 'screening_date') or \
280            self.context.state not in ('submitted', 'admitted', 'created'):
[10298]281            form_fields = form_fields.omit('screening_date')
282        return form_fields
283
[14371]284    def getCourseAdmitted(self):
285        """Return link, title and code in html format to the certificate
286           admitted.
287        """
288        if self.layout.isApplicant():
289            return ''
290        course_admitted = self.context.course_admitted
291        if getattr(course_admitted, '__parent__',None):
292            url = self.url(course_admitted)
293            title = course_admitted.title
294            code = course_admitted.code
295            return '<a href="%s">%s - %s</a>' %(url,code,title)
296        return ''
297
[13538]298class CustomPDFActionButton(PDFActionButton):
299
300    @property
301    def target_url(self):
[15835]302        if self.context.state in ('initialized', 'started', 'paid'):
303            # or self.context.special or self.view.target in ('trans', 'cert'):
[13540]304            return
305        return self.view.url(self.view.context, self.target)
[13538]306
307
[10298]308class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
309
[10311]310    column_two_fields = ('applicant_id', 'reg_number',
311        'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth')
[13679]312    #two_columns_design_fields = [
313    #    'fst_sit_fname', 'fst_sit_no', 'fst_sit_date',
314    #    'fst_sit_type', 'fst_sit_results',
315    #    'scd_sit_fname', 'scd_sit_no', 'scd_sit_date',
316    #    'scd_sit_type', 'scd_sit_results']
[10311]317
[14228]318    def _getCourseAdmittedLink(self, view):
319        return None
320
321    def _getDeptAndFaculty(self):
322        return [None, None]
323
[10301]324    @property
325    def note(self):
[14057]326        note = getattr(self.context.__parent__, 'application_slip_notice', None)
327        if note:
328            return '<br /><br />' + note
[15835]329        if self.target is not None and self.target in (
[16003]330            'trans', 'cert', 'ver', 'send', 'fedex'):
[15835]331            return
[10301]332        if self.context.sex == 'm':
333            pronoun = 'he'
334        else:
335            pronoun = 'she'
336        return '''
[10897]337The applicant has acknowledged that, if discovered at any time that %s does not possess
338any of the qualifications which %s claims %s has obtained, %s will be expelled from the
[14224]339University not be re-admitted for the same or any other programme, even if %s has
340upgraded previous qualifications or possess additional qualifications.
341
[10331]342''' % (
[10301]343    pronoun, pronoun, pronoun, pronoun, pronoun)
[10298]344
345    @property
346    def form_fields(self):
[13538]347        # AAUE is using the same interface for all regular applications.
[11291]348        form_fields = grok.AutoFields(ICustomUGApplicant)
[13538]349        if self.target is not None and self.target.startswith('pg'):
350            for field in PG_OMIT_PDF_FIELDS:
[16763]351                form_fields = grok.AutoFields(ICustomPGApplicant)
[13538]352                form_fields = form_fields.omit(field)
[15521]353        elif self.target is not None and self.target in ('ptee', 'dsh',):
[13679]354            for field in PTEE_OMIT_PDF_FIELDS:
[10298]355                form_fields = form_fields.omit(field)
[15217]356        elif self.target is not None and self.target in ('bridge', 'ude',):
[14209]357            for field in UDE_OMIT_PDF_FIELDS:
358                form_fields = form_fields.omit(field)
[15835]359        elif self.target is not None and self.target == 'trans':
360            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
361                'locked', 'suspended')
362        elif self.target is not None and self.target == 'ver':
363            form_fields = grok.AutoFields(IVerificationRequest).omit(
364                'locked', 'suspended')
365        elif self.target is not None and self.target == 'send':
366            form_fields = grok.AutoFields(ISendByEmailRequest).omit(
367                'locked', 'suspended')
368        elif self.target is not None and self.target == 'cert':
369            form_fields = grok.AutoFields(ICertificateRequest).omit(
370                'locked', 'suspended')
[16003]371        elif self.target is not None and self.target == 'fedex':
372            form_fields = grok.AutoFields(IFedexRequest).omit(
373                'locked', 'suspended')
[10298]374        else:
375            for field in UG_OMIT_PDF_FIELDS:
376                form_fields = form_fields.omit(field)
377        if not getattr(self.context, 'student_id'):
378            form_fields = form_fields.omit('student_id')
379        if not getattr(self.context, 'screening_score'):
380            form_fields = form_fields.omit('screening_score')
381        if not getattr(self.context, 'screening_venue'):
382            form_fields = form_fields.omit('screening_venue')
383        if not getattr(self.context, 'screening_date'):
384            form_fields = form_fields.omit('screening_date')
[16763]385        hqfields = ('hq_type', 'hq_fname', 'hq_matric_no',
386                    'hq_degree', 'hq_school', 'hq_session', 'hq_disc')
387        if not getattr(self.context, 'hq_type'):
388            for hq in hqfields:
389                form_fields = form_fields.omit(hq)
390        if not getattr(self.context, 'hq_type2'):
391            for hq in hqfields:
392                form_fields = form_fields.omit(hq + '2')
393        if not getattr(self.context, 'hq_type3'):
394            for hq in hqfields:
395                form_fields = form_fields.omit(hq + '3')
396        if not getattr(self.context, 'hq_type4'):
397            for hq in hqfields:
398                form_fields = form_fields.omit(hq + '4')
[10298]399        return form_fields
400
401class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
402    """A full edit view for applicant data.
403    """
404
[15948]405    def display_fileupload(self, filename):
[16548]406        if filename[1] == 'stateresult':
[15948]407            if self.target in ('trans', 'cert'):
408                return True
[16548]409        if filename[1] == 'verificationdoc':
[15948]410            if self.target in ('ver', 'send'):
411                return True
412        return False
413
[10298]414    @property
415    def form_fields(self):
[13538]416        if self.target is not None and self.target == 'trans':
[13544]417            form_fields = grok.AutoFields(ITranscriptApplicant)
[13538]418            form_fields['applicant_id'].for_display = True
419            return form_fields
[14304]420        if self.target is not None and self.target == 'cert':
421            form_fields = grok.AutoFields(ICertificateRequest)
422            form_fields['applicant_id'].for_display = True
423            return form_fields
[15530]424        if self.target is not None and self.target == 'ver':
425            form_fields = grok.AutoFields(IVerificationRequest)
426            form_fields['applicant_id'].for_display = True
427            return form_fields
[15531]428        if self.target is not None and self.target == 'send':
429            form_fields = grok.AutoFields(ISendByEmailRequest)
430            form_fields['applicant_id'].for_display = True
431            return form_fields
[15950]432        if self.target is not None and self.target == 'fedex':
433            form_fields = grok.AutoFields(IFedexRequest)
434            form_fields['applicant_id'].for_display = True
435            return form_fields
[15991]436        if self.target is not None and self.target == 'rec':
437            form_fields = grok.AutoFields(IRecruitment)
438            form_fields['applicant_id'].for_display = True
439            return form_fields
[13538]440        # AAUE is using the same interface for all regular applications.
[11291]441        form_fields = grok.AutoFields(ICustomUGApplicant)
[13538]442        if self.target is not None and self.target.startswith('pg'):
[16763]443            form_fields = grok.AutoFields(ICustomPGApplicant)
[13538]444            for field in PG_OMIT_MANAGE_FIELDS:
445                form_fields = form_fields.omit(field)
[15521]446        elif self.target is not None and self.target in ('ptee', 'dsh',):
[13679]447            for field in PTEE_OMIT_MANAGE_FIELDS:
[10298]448                form_fields = form_fields.omit(field)
[15217]449        elif self.target is not None and self.target in ('bridge', 'ude',):
[14209]450            for field in UDE_OMIT_MANAGE_FIELDS:
451                form_fields = form_fields.omit(field)
[10298]452        else:
453            for field in UG_OMIT_MANAGE_FIELDS:
454                form_fields = form_fields.omit(field)
455        form_fields['student_id'].for_display = True
456        form_fields['applicant_id'].for_display = True
457        return form_fields
458
459class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
460    """An applicant-centered edit view for applicant data.
461    """
462
[15948]463    def display_fileupload(self, filename):
[16548]464        if filename[1] == 'stateresult':
[15948]465            if self.target in ('trans', 'cert'):
466                return True
[16548]467        if filename[1] == 'verificationdoc':
[15948]468            if self.target in ('ver', 'send'):
469                return True
470        return False
471
[14027]472    def unremovable(self, ticket):
473        return True
474
[15639]475    def dataNotComplete(self, data):
[15099]476        store = getUtility(IExtFileStore)
[15265]477        # Temporarily enable passport upload also for cert and trans
478        # applications.
[15503]479        if self.context.__parent__.with_picture:
[15100]480            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
[15099]481                return _('No passport picture uploaded.')
[15991]482            if not self.target in ('cert', 'trans') and \
[15265]483                not self.request.form.get('confirm_passport', False):
[15099]484                return _('Passport picture confirmation box not ticked.')
[15132]485        if self.target in ('trans', 'cert') and \
[16548]486            not store.getFileByContext(self.context, attr=u'stateresult'):
[15113]487            return _('No statement of result pdf file uploaded.')
[15531]488        if self.target in ('ver',) and \
[16548]489            not store.getFileByContext(self.context, attr=u'verificationdoc'):
[15531]490            return _('No pdf file uploaded.')
[15954]491        if self.target == 'fedex':
492            cat = getUtility(ICatalog, name='applicants_catalog')
493            results = list(cat.searchResults(
494                applicant_id=(data['trans_id'], data['trans_id'])))
495            if not results:
496                return _('The transcript application id does not exist.')
[15099]497        return False
498
[14027]499    # AAUE applicants never see the 'Remove Selected Tickets' button.
[10298]500    @property
[14027]501    def display_actions(self):
502        # If the form is unlocked, applicants are allowed to save the form
[14029]503        # and remove unused tickets.
504        actions = [[_('Save')], []]
[14027]505        # Only in state started they can also add tickets.
[14822]506        if self.context.state == STARTED:
[14029]507            actions = [[_('Save')],
508                [_('Add online payment ticket')]]
[14027]509        # In state paid, they can submit the data and further add tickets
510        # if the application is special.
[14822]511        elif self.context.special and self.context.state == PAID:
[14027]512            actions = [[_('Save'), _('Finally Submit')],
[14029]513                [_('Add online payment ticket')]]
[14822]514        elif self.context.state == PAID:
[14029]515            actions = [[_('Save'), _('Finally Submit')], []]
[14027]516        return actions
517
518    @property
[10298]519    def form_fields(self):
[13538]520        if self.target is not None and self.target == 'trans':
[13544]521            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
522                'locked', 'suspended')
[13538]523            form_fields['applicant_id'].for_display = True
[14472]524            form_fields['reg_number'].for_display = True
[15276]525            form_fields['place_of_birth'].field.required = True
526            form_fields['date_of_birth'].field.required = True
527            form_fields['nationality'].field.required = True
528            form_fields['email'].field.required = True
529            form_fields['phone'].field.required = True
530            form_fields['perm_address'].field.required = True
531            form_fields['dispatch_address'].field.required = True
532            form_fields['entry_mode'].field.required = True
533            form_fields['entry_session'].field.required = True
534            form_fields['end_session'].field.required = True
535            form_fields['course_studied'].field.required = True
[13538]536            return form_fields
[14304]537        if self.target is not None and self.target == 'cert':
538            form_fields = grok.AutoFields(ICertificateRequest).omit(
539                'locked', 'suspended')
540            form_fields['applicant_id'].for_display = True
[14472]541            form_fields['reg_number'].for_display = True
[15276]542            form_fields['place_of_birth'].field.required = True
543            form_fields['date_of_birth'].field.required = True
544            form_fields['nationality'].field.required = True
545            form_fields['email'].field.required = True
546            form_fields['phone'].field.required = True
547            form_fields['entry_session'].field.required = True
548            form_fields['end_session'].field.required = True
549            form_fields['course_studied'].field.required = True
550            form_fields['certificate_type'].field.required = True
[14696]551            # Additional omissions
552            if self.context.__parent__.code == 'cert5':
553                for field in ('firstname', 'middlename', 'lastname'):
554                    form_fields[field].for_display = True
[14304]555            return form_fields
[15530]556        if self.target is not None and self.target == 'ver':
557            form_fields = grok.AutoFields(IVerificationRequest).omit(
558                'locked', 'suspended')
559            form_fields['applicant_id'].for_display = True
560            return form_fields
[15531]561        if self.target is not None and self.target == 'send':
562            form_fields = grok.AutoFields(ISendByEmailRequest).omit(
563                'locked', 'suspended')
564            form_fields['applicant_id'].for_display = True
565            return form_fields
[15950]566        if self.target is not None and self.target == 'fedex':
567            form_fields = grok.AutoFields(IFedexRequest).omit(
568                'locked', 'suspended')
569            form_fields['applicant_id'].for_display = True
570            return form_fields
[15991]571        if self.target is not None and self.target == 'rec':
572            form_fields = grok.AutoFields(IRecruitment).omit(
573                'locked', 'suspended')
574            form_fields['applicant_id'].for_display = True
575            return form_fields
[13538]576        # AAUE is using the same interface for all regular applications.
[11291]577        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
[13538]578        if self.target is not None and self.target.startswith('pg'):
[16763]579            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
[13538]580            for field in PG_OMIT_EDIT_FIELDS:
581                form_fields = form_fields.omit(field)
[16765]582            form_fields['screening_venue'].for_display = True
583            form_fields['screening_date'].for_display = True
584            form_fields['screening_score'].for_display = True
585            form_fields['student_id'].for_display = True
[16774]586            form_fields['notice'].for_display = True
[15521]587        elif self.target is not None and self.target in ('ptee','dsh',):
[13679]588            for field in PTEE_OMIT_EDIT_FIELDS:
[10298]589                form_fields = form_fields.omit(field)
[15217]590        elif self.target is not None and self.target in ('bridge', 'ude',):
[14209]591            for field in UDE_OMIT_EDIT_FIELDS:
592                form_fields = form_fields.omit(field)
[10298]593        else:
594            for field in UG_OMIT_EDIT_FIELDS:
595                form_fields = form_fields.omit(field)
[14150]596        # Additional omissions
[14696]597        if self.target is not None and self.target in ('ude', 'utme'):
[14150]598            for field in UPDATE_OMIT_FIELDS:
599                form_fields[field].for_display = True
[10298]600        form_fields['applicant_id'].for_display = True
601        form_fields['reg_number'].for_display = True
602        return form_fields
[10929]603
[15113]604    def update(self):
605        if self.context.locked or (
606            self.context.__parent__.expired and
607            self.context.__parent__.strict_deadline):
608            self.emit_lock_message()
609            return
[15459]610        if getattr(
611            self.context.course1, 'code', 'nocourse') == self.request.form.get(
612            'form.course2', None):
613            self.flash(_('2nd choice course must differ from 1st choice course.'),
614                       type='danger')
615            self.redirect(self.url(self.context))
616            return
617        if getattr(
618            self.context.course1, 'code', 'nocourse') == self.request.form.get(
619            'form.course3', None):
620            self.flash(_('3rd choice course must differ from 1st choice course.'),
621                       type='danger')
622            self.redirect(self.url(self.context))
623            return
[15113]624        super(CustomApplicantEditFormPage, self).update()
625        return
626
[10929]627class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage):
628    """Captcha'd registration page for applicants.
629    """
630
[14460]631    @property
632    def form_fields(self):
633        form_fields = None
634        if self.context.mode == 'update':
635            form_fields = grok.AutoFields(IApplicantRegisterUpdate).select(
636                'lastname','reg_number','email')
[14465]637            target = getattr(self.context, 'prefix', None)
[14460]638            if target in ('trans', 'cert'):
639                form_fields.get('reg_number').field.title = u'Matriculation Number'
640        else: #if self.context.mode == 'create':
641            form_fields = grok.AutoFields(ICustomUGApplicantEdit).select(
642                'firstname', 'middlename', 'lastname', 'email', 'phone')
643        return form_fields
644
[10929]645    def _redirect(self, email, password, applicant_id):
646        # Forward email and credentials to landing page.
647        self.redirect(self.url(self.context, 'registration_complete',
648            data = dict(email=email, password=password,
649            applicant_id=applicant_id)))
[11755]650        return
651
[14579]652    @property
653    def _postfix(self):
654        """Alumni records have to be imported into several containers.
655        Therefore a string must be added to their registration number
656        to make it unique.
657        """
658        if self.context.prefix in ('trans', 'cert'):
659            return self.context.code
660        return ''
661
[16003]662class ApplicantBaseDisplayFormPage(CustomApplicantDisplayFormPage):
663    grok.context(ICustomApplicant)
664    grok.name('base')
665
666    @property
667    def form_fields(self):
668        if self.context.__parent__.prefix in ('fedex',):
669            form_fields = grok.AutoFields(IFedexRequest).select(
670                'applicant_id', 'trans_id', 'email',)
671        else:
672            form_fields = grok.AutoFields(ICustomApplicant).select(
673                'applicant_id', 'reg_number', 'email', 'course1')
674        if self.context.__parent__.prefix in ('special',):
675            form_fields['reg_number'].field.title = u'Identification Number'
676            return form_fields
677        return form_fields
678
[11755]679class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
680
[16003]681    form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit(
682        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item',
683        'p_split_data')
684    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
685    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
686
[11755]687    @property
688    def payment_slip_download_warning(self):
[13422]689        return ''
690
[16003]691    def render(self):
692        if self.payment_slip_download_warning:
693            self.flash(self.payment_slip_download_warning, type='danger')
694            self.redirect(self.url(self.context))
695            return
696        applicantview = ApplicantBaseDisplayFormPage(self.context.__parent__,
697            self.request)
698        students_utils = getUtility(IStudentsUtils)
699        return students_utils.renderPDF(self,'payment_slip.pdf',
700            self.context.__parent__, applicantview, note=self.note)
701
[13422]702class CustomApplicantCheckStatusPage(ApplicantCheckStatusPage):
703    """Captcha'd status checking page for applicants.
704    """
705    grok.template('applicantcheckstatus')
[13996]706
[14822]707class ScreeningInvitationActionButton(ManageActionButton):
[13997]708    grok.order(8) # This button should always be the last one.
709    grok.context(ICustomApplicant)
710    grok.view(CustomApplicantDisplayFormPage)
711    grok.require('waeup.viewApplication')
712    icon = 'actionicon_pdf.png'
713    text = _('Download screening invitation letter')
714    target = 'screening_invitation.pdf'
[13996]715
[13997]716    @property
717    def target_url(self):
[14822]718        if not self.context.screening_date or not self.context.state in (
[14824]719            'submitted', 'admitted', 'created'):
[13997]720            return ''
721        return self.view.url(self.view.context, self.target)
722
[13996]723class ExportScreeningInvitationLetter(UtilityView, grok.View):
724    """Deliver a slip with only screening data.
725    This form page is available only in AAUE.
726    """
[13997]727    grok.context(ICustomApplicant)
[13996]728    grok.name('screening_invitation.pdf')
729    grok.require('waeup.viewApplication')
730    prefix = 'form'
731
732    label = u'Screening Invitation Letter'
733
734    form_fields = []
735
736    @property
737    def note(self):
738        if self.context.screening_date:
[13999]739            year = self.context.__parent__.year
740            session = '%s/%s' % (year, year + 1)
741            sdate = self.context.screening_date
742            stime = ''
743            if '@' in self.context.screening_date:
744                sdate = self.context.screening_date.split('@')[0].strip()
745                stime = self.context.screening_date.split('@')[1].strip()
[13996]746            return """
747<br /><br /><br /><br /><font size='12'>
748Dear %s,
749<br /><br />
[13999]750You are invited to the Ambrose Alli University %s Admissions Screening Exercise.
[13996]751<br /><br />
[13999]752<strong>Date: %s
[13996]753<br /><br />
[13999]754Time: %s
755<br /><br />
[13997]756Venue: %s
757</strong>
[13996]758<br /><br />
[14015]759Please bring this letter of invitation and the downloaded application form along with you on your screening date.
760<br /><br />
761You are expected to be available 30 minutes before the commencement of your Screening.
[13996]762</font>
763
[13999]764""" % (
765       self.context.display_fullname,
766       session,
767       sdate,
768       stime,
[13996]769       self.context.screening_venue)
770        return
771
772    @property
773    def title(self):
774        return None
775
776    def update(self):
[14822]777        if not self.context.screening_date or not self.context.state in (
[14824]778            'submitted', 'admitted', 'created'):
[13996]779            self.flash(_('Forbidden'), type="warning")
780            self.redirect(self.url(self.context))
781
782    def render(self):
783        applicantview = ApplicantBaseDisplayFormPage(self.context, self.request)
784        students_utils = getUtility(IStudentsUtils)
785        return students_utils.renderPDF(self,'screening_data.pdf',
[14015]786            self.context, applicantview, note=self.note)
[15113]787
[16786]788class CustomRefereeReportAddFormPage(RefereeReportAddFormPage):
789    """Add-form to add an referee report. This form
790    is protected by a mandate.
791    """
792    form_fields = grok.AutoFields(
793        ICustomApplicantRefereeReport).omit('creation_date')
794
795class CustomRefereeReportDisplayFormPage(RefereeReportDisplayFormPage):
796    """A display view for referee reports.
797    """
798    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
799    form_fields[
800        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
801
802class CustomExportPDFReportSlipPage(ExportPDFReportSlipPage):
803    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
804    form_fields[
805        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
806
807class CustomExportPDFReportSlipPage2(ExportPDFReportSlipPage2):
808    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
809    form_fields[
810        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
811
[15948]812class StateResult(AdditionalFile):
[15113]813    """Renders the pdf form extension for applicants.
814    """
[16548]815    grok.name('stateresult')
[15113]816
[15948]817class VerificationDoc(AdditionalFile):
[15530]818    """Renders the pdf form extension for applicants.
819    """
[16548]820    grok.name('verificationdoc')
Note: See TracBrowser for help on using the repository browser.