source: main/waeup.uniben/trunk/src/waeup/uniben/applicants/browser.py @ 17532

Last change on this file since 17532 was 17532, checked in by Henrik Bettermann, 14 months ago

JAMB National have insisted that the part time undergraduates must register with them first.

  • Property svn:keywords set to Id
File size: 36.1 KB
Line 
1## $Id: browser.py 17532 2023-08-06 08:40:30Z 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
21from time import time
22from zope.component import getUtility, createObject
23from zope.formlib.textwidgets import BytesDisplayWidget
24from zope.security import checkPermission
25from zope.i18n import translate
26from hurry.workflow.interfaces import IWorkflowState
27from waeup.kofa.browser.layout import action, UtilityView
28from waeup.kofa.interfaces import IExtFileStore, IKofaUtils
29from waeup.kofa.applicants.browser import (
30    ApplicantRegistrationPage, ApplicantsContainerPage,
31    ApplicationFeePaymentAddPage,
32    OnlinePaymentApprovePage,
33    ExportPDFPageApplicationSlip,
34    ApplicantBaseDisplayFormPage,
35    CheckTranscriptStatus,
36    AdditionalFile,)
37from waeup.kofa.students.interfaces import IStudentsUtils
38from waeup.kofa.applicants.interfaces import (
39    ISpecialApplicant, IApplicantsUtils)
40from waeup.kofa.browser.interfaces import IPDFCreator
41from kofacustom.nigeria.applicants.browser import (
42    NigeriaApplicantDisplayFormPage,
43    NigeriaApplicantManageFormPage,
44    NigeriaApplicantEditFormPage,
45    NigeriaPDFApplicationSlip,
46    NigeriaExportPDFPaymentSlipPage)
47from waeup.uniben.applicants.interfaces import (
48    ICustomApplicant,
49    IUnibenRegistration,
50    ICustomUGApplicant,
51    ICustomPGApplicant,
52    ICustomPGApplicantEdit,
53    ICustomUGApplicantEdit,
54    IPUTMEApplicantEdit,
55    ITranscriptApplicant,
56    IFrenchApplicant)
57from waeup.kofa.applicants.workflow import ADMITTED, PAID, STARTED
58from kofacustom.nigeria.applicants.interfaces import (
59    UG_OMIT_DISPLAY_FIELDS,
60    UG_OMIT_PDF_FIELDS,
61    UG_OMIT_MANAGE_FIELDS,
62    UG_OMIT_EDIT_FIELDS,
63    CBT_OMIT_DISPLAY_FIELDS,
64    CBT_OMIT_PDF_FIELDS,
65    CBT_OMIT_MANAGE_FIELDS,
66    CBT_OMIT_EDIT_FIELDS,
67    AFFIL_OMIT_DISPLAY_FIELDS,
68    AFFIL_OMIT_PDF_FIELDS,
69    AFFIL_OMIT_MANAGE_FIELDS,
70    AFFIL_OMIT_EDIT_FIELDS,
71    PG_OMIT_DISPLAY_FIELDS,
72    PG_OMIT_PDF_FIELDS,
73    PG_OMIT_MANAGE_FIELDS,
74    PG_OMIT_EDIT_FIELDS,
75    PUTME_OMIT_DISPLAY_FIELDS,
76    PUTME_OMIT_PDF_FIELDS,
77    PUTME_OMIT_MANAGE_FIELDS,
78    PUTME_OMIT_EDIT_FIELDS,
79    PUTME_OMIT_RESULT_SLIP_FIELDS,
80    PUDE_OMIT_DISPLAY_FIELDS,
81    PUDE_OMIT_PDF_FIELDS,
82    PUDE_OMIT_MANAGE_FIELDS,
83    PUDE_OMIT_EDIT_FIELDS,
84    PUDE_OMIT_RESULT_SLIP_FIELDS,
85    PRE_OMIT_DISPLAY_FIELDS,
86    PRE_OMIT_PDF_FIELDS,
87    PRE_OMIT_MANAGE_FIELDS,
88    PRE_OMIT_EDIT_FIELDS,
89    )
90
91from waeup.uniben.interfaces import MessageFactory as _
92
93PASTQ_ALL = ['ADT','CIT','DEF','DEM','EPCS','ESM','HEK','HSE','VTE']
94
95PASTQ_AL = ['ENL','FAA','FOL','HIS','LAL', 'PHL','THR','BUL','JIL',
96            'LAW','PPL','PUL'] + PASTQ_ALL
97
98PASTQ_BS = ['ANT','ANY','CHH','COH','HAE','MED','MEH','PHS','SUR',
99            'PCG','PCH','PCO', 'PCT','PHA','PHM','PMB','ANA','MBC',
100            'MLS','NSC','PSY','DPV','ODR','OSP','PER', 'RES','AEB',
101            'BCH','BOT','CED','EVL','MCB','OPT','PBB','SLT','ZOO',
102            'AEE','ANS', 'CRS','FIS','FOW','SOS'] + PASTQ_ALL
103
104PASTQ_EPS = ['ARC','CHE','CVE','DMIC','EEE','GEM','MCH','PEE','PRE','CHM',
105             'CSC','GLY','MTH','QSV','PHY','CPE','STR'] + PASTQ_ALL
106
107PASTQ_MSS = ['ACC','BNK','BUS','ECO','ESM','GEO','POL','SAA','SWK',
108             'ACT','ENT','HRM','INS','MKT'] + PASTQ_ALL
109
110REGISTRATION_OMIT_DISPLAY_FIELDS = (
111    'locked',
112    'suspended',
113    'course_admitted',
114    )
115
116REGISTRATION_OMIT_EDIT_FIELDS = (
117    'locked',
118    'suspended',
119    'applicant_id',
120    'course_admitted',
121    )
122
123REGISTRATION_OMIT_MANAGE_FIELDS = (
124    'applicant_id',
125    )
126
127
128REGISTRATION_OMIT_PDF_FIELDS = (
129    'locked',
130    'suspended',
131    'course_admitted',
132    )
133
134PUTME_OMIT_PDF_FIELDS = PUTME_OMIT_PDF_FIELDS + (
135    'fst_sit_results', 'scd_sit_results')
136
137TRANS_OMIT_FIELDS = ('suspended',)
138
139#TRANS_SHORT_OMIT_FIELDS = TRANS_OMIT_FIELDS + (
140#    'date_of_birth',
141#    'sex',
142#    #'nationality',
143#    'entry_mode',
144#    'entry_session',
145#    'end_session',
146#    'course_studied',
147#    'course_changed',
148#    #'change_level',
149#    )
150
151TRANS_SHORT_OMIT_FIELDS = TRANS_OMIT_FIELDS
152
153TRANS_OMIT_EDIT_FIELDS = TRANS_OMIT_FIELDS + ('applicant_id', )
154
155TRANS_SHORT_OMIT_EDIT_FIELDS = TRANS_SHORT_OMIT_FIELDS + ('applicant_id', )
156
157TRANS_OMIT_PDF_FIELDS = TRANS_OMIT_FIELDS + ('locked', )
158
159TRANS_SHORT_OMIT_PDF_FIELDS = TRANS_SHORT_OMIT_FIELDS + ('locked', )
160
161class CustomApplicantsContainerPage(ApplicantsContainerPage):
162    """The standard view for regular applicant containers.
163    """
164
165    @property
166    def form_fields(self):
167        form_fields = super(CustomApplicantsContainerPage, self).form_fields
168        usertype = getattr(self.request.principal, 'user_type', None)
169        if self.request.principal.id == 'zope.anybody' or  \
170            usertype in ('applicant', 'student'):
171            return form_fields.omit('application_fee')
172        return form_fields
173
174class CustomApplicantRegistrationPage(ApplicantRegistrationPage):
175    """Captcha'd registration page for applicants.
176    """
177
178    def _redirect(self, email, password, applicant_id):
179        # Forward email and credentials to landing page.
180        self.redirect(self.url(self.context, 'registration_complete',
181            data = dict(email=email, password=password,
182            applicant_id=applicant_id)))
183        return
184
185    @property
186    def label(self):
187        if self.context.prefix.startswith('tsc'):
188            return _('Request for ${a}',
189                mapping = {'a':self.context.title})
190        return _('Apply for ${a}',
191            mapping = {'a':self.context.title})
192
193class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
194    """A display view for applicant data.
195    """
196    grok.template('applicantdisplaypage')
197
198    @property
199    def display_payments(self):
200        if self.context.special or self.target == 'ictwk':
201            return True
202        return getattr(self.context.__parent__, 'application_fee', None)
203
204    def _show_pastq_putme(self):
205        return self.target.startswith('pre') \
206               and self.context.state in ('paid', 'submitted') \
207               and getattr(self.context, 'course1') is not None
208        # return False
209
210    @property
211    def depcode(self):
212        try:
213            code = self.context.course1.__parent__.__parent__.code
214            return code
215        except:
216            return
217
218    @property
219    def show_pastq_al(self):
220        return self._show_pastq_putme() # and self.depcode in PASTQ_AL
221
222    @property
223    def show_pastq_bs(self):
224        return self._show_pastq_putme() # and self.depcode in PASTQ_BS
225
226    @property
227    def show_pastq_eps(self):
228        return self._show_pastq_putme() # and self.depcode in PASTQ_EPS
229
230    @property
231    def show_pastq_mss(self):
232        return self._show_pastq_putme() # and self.depcode in PASTQ_MSS
233
234    @property
235    def show_pastq_pude(self):
236        return self.target.startswith('pude') \
237               and self.context.state in ('paid', 'submitted')
238
239    @property
240    def label(self):
241        if self.target == 'ictwk':
242            container_title = self.context.__parent__.title
243            return _('${a} <br /> Registration Record ${b}', mapping = {
244                'a':container_title, 'b':self.context.application_number})
245        return super(CustomApplicantDisplayFormPage, self).label
246
247    @property
248    def form_fields(self):
249        if self.target is not None and self.target == 'tscf':
250            form_fields = grok.AutoFields(ITranscriptApplicant)
251            for field in TRANS_OMIT_FIELDS:
252                form_fields = form_fields.omit(field)
253            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
254            #form_fields['perm_address'].custom_widget = BytesDisplayWidget
255            return form_fields
256        if self.target is not None and self.target == 'tscs':
257            form_fields = grok.AutoFields(ITranscriptApplicant)
258            for field in TRANS_SHORT_OMIT_FIELDS:
259                form_fields = form_fields.omit(field)
260            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
261            #form_fields['perm_address'].custom_widget = BytesDisplayWidget
262            return form_fields
263        if self.target is not None and self.target == 'flc':
264            form_fields = grok.AutoFields(IFrenchApplicant)
265            for field in REGISTRATION_OMIT_DISPLAY_FIELDS:
266                form_fields = form_fields.omit(field)
267            return form_fields
268        if self.target == 'ictwk':
269            form_fields = grok.AutoFields(IUnibenRegistration)
270            for field in REGISTRATION_OMIT_DISPLAY_FIELDS:
271                form_fields = form_fields.omit(field)
272            return form_fields
273        elif self.target is not None and self.target.startswith('pg'):
274            form_fields = grok.AutoFields(ICustomPGApplicant)
275            for field in PG_OMIT_DISPLAY_FIELDS:
276                form_fields = form_fields.omit(field)
277        elif self.target is not None and self.target.startswith('pre'):
278            form_fields = grok.AutoFields(ICustomPGApplicant)
279            for field in PRE_OMIT_DISPLAY_FIELDS:
280                form_fields = form_fields.omit(field)
281        elif self.target is not None and self.target.startswith('cbt'):
282            form_fields = grok.AutoFields(ICustomUGApplicant)
283            for field in CBT_OMIT_DISPLAY_FIELDS:
284                form_fields = form_fields.omit(field)
285        elif self.target is not None and self.target.startswith('akj'):
286            form_fields = grok.AutoFields(ICustomPGApplicant)
287            for field in PRE_OMIT_DISPLAY_FIELDS:
288                form_fields = form_fields.omit(field)
289        elif self.target is not None and self.target.startswith('ak'):
290            form_fields = grok.AutoFields(ICustomUGApplicant)
291            for field in AFFIL_OMIT_DISPLAY_FIELDS:
292                form_fields = form_fields.omit(field)
293        elif self.target is not None and self.target.startswith('ase'): # was putme
294            form_fields = grok.AutoFields(ICustomUGApplicant)
295            for field in PUTME_OMIT_DISPLAY_FIELDS:
296                form_fields = form_fields.omit(field)
297        elif self.target is not None and self.target.startswith('pude'):
298            form_fields = grok.AutoFields(ICustomUGApplicant)
299            for field in PUDE_OMIT_DISPLAY_FIELDS:
300                form_fields = form_fields.omit(field)
301        else:
302            form_fields = grok.AutoFields(ICustomUGApplicant)
303            for field in UG_OMIT_DISPLAY_FIELDS:
304                form_fields = form_fields.omit(field)
305        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
306        form_fields['notice'].custom_widget = BytesDisplayWidget
307        if not getattr(self.context, 'student_id'):
308            form_fields = form_fields.omit('student_id')
309        if not getattr(self.context, 'screening_score'):
310            form_fields = form_fields.omit('screening_score')
311        if not getattr(self.context, 'screening_venue') or self._not_paid():
312            form_fields = form_fields.omit('screening_venue')
313        if not getattr(self.context, 'screening_date') or self._not_paid():
314            form_fields = form_fields.omit('screening_date')
315        if not self.context.admchecking_fee_paid():
316            form_fields = form_fields.omit(
317                'screening_score', 'aggregate', 'student_id')
318        return form_fields
319
320    @property
321    def display_actions(self):
322        state = IWorkflowState(self.context).getState()
323        actions = []
324        if state == ADMITTED and not self.context.admchecking_fee_paid():
325            actions = [_('Add admission checking payment ticket')]
326        return actions
327
328
329    def getCourseAdmitted(self):
330        """Return link, title and code in html format to the certificate
331           admitted.
332        """
333        if self.admission_checking_info:
334            return '<span class="hint">%s</span>' % self.admission_checking_info
335        return super(CustomApplicantDisplayFormPage, self).getCourseAdmitted()
336
337    @property
338    def admission_checking_info(self):
339        if self.context.state == ADMITTED and \
340            not self.context.admchecking_fee_paid():
341            return _('You must pay the admission checking fee '
342                     'to view your screening results and your course admitted.')
343        return
344
345    @action(_('Add admission checking payment ticket'), style='primary')
346    def addPaymentTicket(self, **data):
347        self.redirect(self.url(self.context, '@@addacp'))
348        return
349
350class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
351    """ Page to add an online payment ticket
352    """
353
354    @property
355    def custom_requirements(self):
356        if self.context.__parent__.with_picture:
357            store = getUtility(IExtFileStore)
358            if self.context.__parent__.picture_editable \
359                and not store.getFileByContext(self.context, attr=u'passport.jpg'):
360                return _('Upload your 1"x1" Red background passport photo before making payment.')
361        return ''
362
363class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View):
364    """ Page to add an admission checking online payment ticket.
365    """
366    grok.context(ICustomApplicant)
367    grok.name('addacp')
368    grok.require('waeup.payApplicant')
369    factory = u'waeup.ApplicantOnlinePayment'
370
371    def _setPaymentDetails(self, payment):
372        container = self.context.__parent__
373        timestamp = ("%d" % int(time()*10000))[1:]
374        session = str(container.year)
375        try:
376            session_config = grok.getSite()['configuration'][session]
377        except KeyError:
378            return _(u'Session configuration object is not available.'), None
379        payment.p_id = "p%s" % timestamp
380        payment.p_item = container.title
381        payment.p_session = container.year
382        payment.amount_auth = 0.0
383        payment.p_category = 'admission_checking'
384        payment.amount_auth = session_config.admchecking_fee
385        if payment.amount_auth in (0.0, None):
386            return _('Amount could not be determined.'), None
387        return
388
389    def update(self):
390        if self.context.admchecking_fee_paid():
391              self.flash(
392                  _('Admission checking payment has already been made.'),
393                  type='warning')
394              self.redirect(self.url(self.context))
395              return
396        payment = createObject(self.factory)
397        failure = self._setPaymentDetails(payment)
398        if failure is not None:
399            self.flash(failure[0], type='danger')
400            self.redirect(self.url(self.context))
401            return
402        self.context[payment.p_id] = payment
403        self.flash(_('Payment ticket created.'))
404        self.redirect(self.url(payment))
405        return
406
407    def render(self):
408        return
409
410
411class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
412
413    @property
414    def display_payments(self):
415        if self.context.special or self.target == 'ictwk':
416            return True
417        return getattr(self.context.__parent__, 'application_fee', None)
418
419    @property
420    def custom_upload_requirements(self):
421        if not checkPermission('waeup.uploadPassportPictures', self.context):
422            return _('You are not entitled to upload passport pictures.')
423
424    def display_fileupload(self, filename):
425        if filename[1] == 'res_stat' \
426            and self.target is not None \
427            and not self.target.startswith('tsc'):
428            return False
429        if filename[1] == 'eligibility' \
430            and self.target is not None \
431            and not self.target.startswith('tsc'):
432            return False
433        return True
434
435    @property
436    def label(self):
437        if self.target == 'ictwk':
438            container_title = self.context.__parent__.title
439            return _('${a} <br /> Registration Record ${b}', mapping = {
440                'a':container_title, 'b':self.context.application_number})
441        return super(CustomApplicantManageFormPage, self).label
442
443    @property
444    def form_fields(self):
445        if self.target is not None and self.target == 'tscf':
446            form_fields = grok.AutoFields(ITranscriptApplicant)
447            for field in TRANS_OMIT_EDIT_FIELDS:
448                form_fields = form_fields.omit(field)
449            return form_fields
450        if self.target is not None and self.target == 'tscs':
451            form_fields = grok.AutoFields(ITranscriptApplicant)
452            for field in TRANS_SHORT_OMIT_EDIT_FIELDS:
453                form_fields = form_fields.omit(field)
454            return form_fields
455        if self.target == 'ictwk':
456            form_fields = grok.AutoFields(IUnibenRegistration)
457            for field in REGISTRATION_OMIT_MANAGE_FIELDS:
458                form_fields = form_fields.omit(field)
459            state = IWorkflowState(self.context).getState()
460            if state != STARTED:
461                form_fields['registration_cats'].for_display = True
462            return form_fields
463        if self.target is not None and self.target == 'flc':
464            form_fields = grok.AutoFields(IFrenchApplicant)
465            for field in REGISTRATION_OMIT_MANAGE_FIELDS:
466                form_fields = form_fields.omit(field)
467            return form_fields
468        if self.target is not None and self.target.startswith('pg'):
469            form_fields = grok.AutoFields(ICustomPGApplicant)
470            for field in PG_OMIT_MANAGE_FIELDS:
471                form_fields = form_fields.omit(field)
472        elif self.target is not None and self.target.startswith('pre'):
473            form_fields = grok.AutoFields(ICustomPGApplicant)
474            for field in PRE_OMIT_MANAGE_FIELDS:
475                form_fields = form_fields.omit(field)
476        elif self.target is not None and self.target.startswith('cbt'):
477            form_fields = grok.AutoFields(ICustomUGApplicant)
478            for field in CBT_OMIT_MANAGE_FIELDS:
479                form_fields = form_fields.omit(field)
480        elif self.target is not None and self.target.startswith('akj'):
481            form_fields = grok.AutoFields(ICustomPGApplicant)
482            for field in PRE_OMIT_MANAGE_FIELDS:
483                form_fields = form_fields.omit(field)
484        elif self.target is not None and self.target.startswith('ak'):
485            form_fields = grok.AutoFields(ICustomUGApplicant)
486            for field in AFFIL_OMIT_MANAGE_FIELDS:
487                form_fields = form_fields.omit(field)
488        elif self.target is not None and self.target.startswith('ase'): # was putme
489            form_fields = grok.AutoFields(ICustomUGApplicant)
490            for field in PUTME_OMIT_MANAGE_FIELDS:
491                form_fields = form_fields.omit(field)
492        elif self.target is not None and self.target.startswith('pude'):
493            form_fields = grok.AutoFields(ICustomUGApplicant)
494            for field in PUDE_OMIT_MANAGE_FIELDS:
495                form_fields = form_fields.omit(field)
496        else:
497            form_fields = grok.AutoFields(ICustomUGApplicant)
498            for field in UG_OMIT_MANAGE_FIELDS:
499                form_fields = form_fields.omit(field)
500        form_fields['student_id'].for_display = True
501        form_fields['applicant_id'].for_display = True
502        return form_fields
503
504
505class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
506    """An applicant-centered edit view for applicant data.
507    """
508
509    def unremovable(self, ticket):
510        return True
511
512    @property
513    def display_payments(self):
514        if self.context.special or self.target == 'ictwk':
515            return True
516        return getattr(self.context.__parent__, 'application_fee', None)
517
518    @property
519    def form_fields(self):
520        state = IWorkflowState(self.context).getState()
521        if self.target is not None and self.target == 'tscf':
522            form_fields = grok.AutoFields(ITranscriptApplicant)
523            form_fields['courier_tno'].for_display = True
524            form_fields['proc_date'].for_display = True
525            for field in TRANS_OMIT_EDIT_FIELDS:
526                form_fields = form_fields.omit(field)
527            if state == PAID:
528                form_fields['order'].for_display = True
529            form_fields = form_fields.omit('locked')
530            return form_fields
531        if self.target is not None and self.target == 'tscs':
532            form_fields = grok.AutoFields(ITranscriptApplicant)
533            form_fields['courier_tno'].for_display = True
534            form_fields['proc_date'].for_display = True
535            for field in TRANS_SHORT_OMIT_EDIT_FIELDS:
536                form_fields = form_fields.omit(field)
537            form_fields = form_fields.omit('locked')
538            if state == PAID:
539                form_fields['order'].for_display = True
540            return form_fields
541        if self.target == 'ictwk':
542            form_fields = grok.AutoFields(IUnibenRegistration)
543            for field in REGISTRATION_OMIT_EDIT_FIELDS:
544                form_fields = form_fields.omit(field)
545            if state != STARTED:
546                form_fields['registration_cats'].for_display = True
547            return form_fields
548        if self.target is not None and self.target == 'flc':
549            form_fields = grok.AutoFields(IFrenchApplicant)
550            for field in REGISTRATION_OMIT_EDIT_FIELDS:
551                form_fields = form_fields.omit(field)
552            return form_fields
553        if self.target is not None and self.target.startswith('pg'):
554            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
555            for field in PG_OMIT_EDIT_FIELDS:
556                form_fields = form_fields.omit(field)
557        elif self.target is not None and self.target.startswith('pre'):
558            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
559            for field in PRE_OMIT_EDIT_FIELDS:
560                form_fields = form_fields.omit(field)
561        elif self.target is not None and self.target.startswith('cbt'):
562            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
563            for field in CBT_OMIT_EDIT_FIELDS:
564                form_fields = form_fields.omit(field)
565        elif self.target is not None and self.target.startswith('akj'):
566            form_fields = grok.AutoFields(ICustomPGApplicant)
567            for field in PRE_OMIT_EDIT_FIELDS:
568                form_fields = form_fields.omit(field)
569        elif self.target is not None and self.target.startswith('ak'):
570            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
571            for field in AFFIL_OMIT_EDIT_FIELDS:
572                form_fields = form_fields.omit(field)
573        elif self.target is not None and self.target.startswith('ase'): # was putme
574            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
575            for field in PUTME_OMIT_EDIT_FIELDS:
576                form_fields = form_fields.omit(field)
577        elif self.target is not None and self.target.startswith('pude'):
578            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
579            for field in PUDE_OMIT_EDIT_FIELDS:
580                form_fields = form_fields.omit(field)
581        else:
582            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
583            for field in UG_OMIT_EDIT_FIELDS:
584                form_fields = form_fields.omit(field)
585        form_fields['applicant_id'].for_display = True
586        form_fields['reg_number'].for_display = True
587        return form_fields
588
589    @property
590    def label(self):
591        if self.target == 'ictwk':
592            container_title = self.context.__parent__.title
593            return _('${a} <br /> Registration Record ${b}', mapping = {
594                'a':container_title, 'b':self.context.application_number})
595        return super(CustomApplicantEditFormPage, self).label
596
597    def display_fileupload(self, filename):
598        if filename[1] == 'res_stat' \
599            and self.target is not None \
600            and not self.target.startswith('tsc'):
601            return False
602        if filename[1] == 'eligibility' \
603            and self.target is not None \
604            and not self.target.startswith('tsc'):
605            return False
606        return True
607
608    def dataNotComplete(self, data):
609        store = getUtility(IExtFileStore)
610        if self.context.__parent__.with_picture \
611            and self.context.__parent__.picture_editable:
612            store = getUtility(IExtFileStore)
613            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
614                return _('No passport picture uploaded.')
615        if self.target is not None \
616            and self.target.startswith('tscf') \
617            and not store.getFileByContext(self.context, attr=u'res_stat.pdf'):
618            return _('No statement of result pdf file uploaded.')
619        if self.target is not None \
620            and self.target.startswith('tsc') \
621            and (not self.context.order or not self.context.charge):
622            return _('Please select Type of Order and Transcript Charge.')
623        if self.target is not None \
624            and self.target.startswith('pt') \
625            and not self.context.jamb_reg_number:
626            return _('Please enter your JAMB Registration Number.')
627        return False
628
629class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage):
630    """ Approval view
631    """
632
633    def update(self):
634        if self.context.p_category == 'admission_checking':
635            if self.context.p_state == 'paid':
636                flashtype = 'warning'
637                msg = _('This ticket has already been paid.')
638                log = None
639            else:
640                self.context.approve()
641                log = 'payment approved: %s' % self.context.p_id
642                msg = _('Payment approved')
643                flashtype = 'success'
644        else:
645            flashtype, msg, log = self.context.approveApplicantPayment()
646        if log is not None:
647            applicant = self.context.__parent__
648            # Add log message to applicants.log
649            applicant.writeLogMessage(self, log)
650            # Add log message to payments.log
651            self.context.logger.info(
652                '%s,%s,%s,%s,%s,,,,,,' % (
653                applicant.applicant_id,
654                self.context.p_id, self.context.p_category,
655                self.context.amount_auth, self.context.r_code))
656        self.flash(msg, type=flashtype)
657        return
658
659class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
660    """Deliver a PDF slip of the context.
661    """
662
663    def update(self):
664        super(CustomExportPDFPageApplicationSlip, self).update()
665        if self.context.state == ADMITTED and \
666            not self.context.admchecking_fee_paid():
667            self.flash(
668                _('Please pay admission checking fee before trying to download '
669                  'the application slip.'), type='warning')
670            return self.redirect(self.url(self.context))
671        return
672
673class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
674
675    def _getPDFCreator(self):
676        if self.target.startswith('ak'):
677            return getUtility(IPDFCreator, name='akoka_pdfcreator')
678        return getUtility(IPDFCreator)
679
680    @property
681    def form_fields(self):
682        if self.target is not None and self.target == 'tscf':
683            form_fields = grok.AutoFields(ITranscriptApplicant)
684            for field in TRANS_OMIT_PDF_FIELDS:
685                form_fields = form_fields.omit(field)
686        elif self.target is not None and self.target == 'tscs':
687            form_fields = grok.AutoFields(ITranscriptApplicant)
688            for field in TRANS_SHORT_OMIT_PDF_FIELDS:
689                form_fields = form_fields.omit(field)
690        elif self.target is not None and self.target == 'ictwk':
691            form_fields = grok.AutoFields(IUnibenRegistration)
692            for field in REGISTRATION_OMIT_PDF_FIELDS:
693                form_fields = form_fields.omit(field)
694        elif self.target is not None and self.target.startswith('pg'):
695            form_fields = grok.AutoFields(ICustomPGApplicant)
696            for field in PG_OMIT_PDF_FIELDS:
697                form_fields = form_fields.omit(field)
698        elif self.target is not None and self.target.startswith('pre'):
699            form_fields = grok.AutoFields(ICustomPGApplicant)
700            for field in PRE_OMIT_PDF_FIELDS:
701                form_fields = form_fields.omit(field)
702        elif self.target is not None and self.target.startswith('cbt'): # uniben
703            form_fields = grok.AutoFields(ICustomUGApplicant)
704            for field in CBT_OMIT_PDF_FIELDS:
705                form_fields = form_fields.omit(field)
706        elif self.target is not None and self.target.startswith('akj'): # uniben
707            form_fields = grok.AutoFields(ICustomPGApplicant)
708            for field in PRE_OMIT_PDF_FIELDS:
709                form_fields = form_fields.omit(field)
710        elif self.target is not None and self.target.startswith('ak'): # uniben
711            form_fields = grok.AutoFields(ICustomUGApplicant)
712            for field in AFFIL_OMIT_PDF_FIELDS:
713                form_fields = form_fields.omit(field)
714        elif self.target is not None and self.target.startswith('ase'): # was putme
715            form_fields = grok.AutoFields(ICustomUGApplicant)
716            if self._reduced_slip():
717                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
718                    form_fields = form_fields.omit(field)
719            else:
720                for field in PUTME_OMIT_PDF_FIELDS:
721                    form_fields = form_fields.omit(field)
722        elif self.target is not None and self.target.startswith('pude'):
723            form_fields = grok.AutoFields(ICustomUGApplicant)
724            if self._reduced_slip():
725                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
726                    form_fields = form_fields.omit(field)
727            else:
728                for field in PUDE_OMIT_PDF_FIELDS:
729                    form_fields = form_fields.omit(field)
730        elif self.target is not None and self.target == 'flc':
731            form_fields = grok.AutoFields(IFrenchApplicant)
732            for field in REGISTRATION_OMIT_PDF_FIELDS:
733                form_fields = form_fields.omit(field)
734        else:
735            form_fields = grok.AutoFields(ICustomUGApplicant)
736            for field in UG_OMIT_PDF_FIELDS:
737                form_fields = form_fields.omit(field)
738        if not getattr(self.context, 'student_id'):
739            form_fields = form_fields.omit('student_id')
740        if not getattr(self.context, 'screening_score'):
741            form_fields = form_fields.omit('screening_score')
742        if not getattr(self.context, 'screening_venue'):
743            form_fields = form_fields.omit('screening_venue')
744        if not getattr(self.context, 'screening_date'):
745            form_fields = form_fields.omit('screening_date')
746        return form_fields
747
748    @property
749    def title(self):
750        container_title = self.context.__parent__.title
751        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
752        ar_translation = translate(_('Application Record'),
753            'waeup.kofa', target_language=portal_language)
754        if self.target == 'ictwk':
755            return '%s - Registration Record %s' % (container_title,
756            self.context.application_number)
757        elif self.target.startswith('ab'):
758            return 'Federal College of Education (Technical) Asaba - %s %s %s' % (
759                container_title, ar_translation,
760                self.context.application_number)
761        elif self.target.startswith('ak'):
762            return 'Federal College of Education (Technical) Akoka - %s - %s %s' % (
763                container_title, ar_translation,
764                self.context.application_number)
765        elif self.target == 'pgn':
766            return 'National Institute for Legislative Studies (NILS) - %s %s %s' % (
767                container_title, ar_translation,
768                self.context.application_number)
769        return '%s - %s %s' % (container_title,
770            ar_translation, self.context.application_number)
771
772class CustomApplicantBaseDisplayFormPage(ApplicantBaseDisplayFormPage):
773
774    @property
775    def form_fields(self):
776        target = getattr(self.context.__parent__, 'prefix', None)
777        if target.startswith('tsc'):
778            form_fields = grok.AutoFields(ICustomApplicant).select(
779                'applicant_id', 'email', 'dispatch_address')
780        else:
781            form_fields = grok.AutoFields(ICustomApplicant).select(
782                'applicant_id', 'reg_number', 'email', 'course1')
783        if self.context.__parent__.prefix in ('special',):
784            form_fields['reg_number'].field.title = u'Identification Number'
785            return form_fields
786        return form_fields
787
788class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
789    """Deliver a PDF slip of the context.
790    """
791
792    @property
793    def omit_fields(self):
794        target = getattr(self.context.__parent__.__parent__, 'prefix', None)
795        if target.startswith('tsc'):
796            return ('date_of_birth', 'course1')
797        return ()
798
799    @property
800    def note(self):
801        return
802
803    def render(self):
804        if self.payment_slip_download_warning:
805            self.flash(self.payment_slip_download_warning, type='danger')
806            self.redirect(self.url(self.context))
807            return
808        applicantview = CustomApplicantBaseDisplayFormPage(self.context.__parent__,
809            self.request)
810        students_utils = getUtility(IStudentsUtils)
811        return students_utils.renderPDF(self,'payment_slip.pdf',
812            self.context.__parent__, applicantview,
813            note=self.note, omit_fields=self.omit_fields)
814
815class ExportScreeningInvitationSlip(UtilityView, grok.View):
816    """Deliver a PDF slip of the context.
817    """
818    grok.context(ICustomApplicant)
819    grok.name('screening_invitation_slip.pdf')
820    grok.require('waeup.viewApplication')
821    form_fields = None
822    label = u'Invitation Letter for Pre-Admission Screening'
823
824
825    @property
826    def note(self):
827        notice = getattr(self.context.__parent__, 'application_slip_notice')
828        if notice is None:
829            notice = ''
830        if self.context.screening_date:
831            return """
832<br /><br /><br /><br /><font size='12'>
833Dear %s,
834<br /><br /><br />
835You are invited for your Uniben Admission Screening Exercise on:
836<br /><br />
837<strong>%s</strong>.
838<br /><br />
839Please bring along this letter of invitation to the
840<br /><br />
841<strong>%s</strong>
842<br /><br />
843on your screening date.
844<br /><br /><br />
845Signed,
846<br /><br />
847The Registrar<br />
848<br /><br />
849<br /><br />
850%s
851</font>
852
853""" % (self.context.display_fullname, self.context.screening_date,
854       self.context.screening_venue, notice)
855        return
856
857    def update(self):
858        if not self.context.screening_date:
859            self.flash(_('Forbidden'), type="warning")
860            self.redirect(self.url(self.context))
861
862    def render(self):
863        applicantview = ApplicantBaseDisplayFormPage(self.context, self.request)
864        students_utils = getUtility(IStudentsUtils)
865        return students_utils.renderPDF(self,'screening_invitation_slip.pdf',
866            self.context, applicantview, note=self.note)
867
868class CustomCheckTranscriptStatus(CheckTranscriptStatus):
869    """A display page for checking transcript processing status.
870    """
871    grok.template('checktranscriptstatus')
872
873    websites = (('Uniben Alumni Portal', 'https://alumni.uniben.edu/'),
874                ('Uniben Student Portal', 'https://waeup.uniben.edu/'),)
875    appl_url1 = 'https://alumni.uniben.edu/applicants/tscf1/register'
876    appl_url2 = 'https://alumni.uniben.edu/applicants/tscs1/register'
877
878class CreateGraduatedPage(UtilityView, grok.View):
879    """Create a student object from transcript application data.
880    """
881    grok.context(ICustomApplicant)
882    grok.name('creategraduated')
883    grok.require('waeup.createStudents')
884
885    def update(self):
886        success, msg = self.context.createStudent(view=self, graduated=True)
887        if success:
888            self.flash(msg)
889        else:
890            self.flash(msg, type='warning')
891        self.redirect(self.url(self.context))
892        return
893
894    def render(self):
895        return
896
897class ResultStatement(AdditionalFile):
898    grok.name('res_stat')
899
900class EligibilityForm(AdditionalFile):
901    grok.name('eligibility')
Note: See TracBrowser for help on using the repository browser.