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

Last change on this file since 17930 was 17597, checked in by Henrik Bettermann, 12 months ago

Set required fields in views not in interfaces.

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