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

Last change on this file since 17492 was 17084, checked in by Henrik Bettermann, 2 years ago

Charge and order fields must not be required.

  • Property svn:keywords set to Id
File size: 35.9 KB
Line 
1## $Id: browser.py 17084 2022-09-06 05:14:44Z 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        return False
624
625class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage):
626    """ Approval view
627    """
628
629    def update(self):
630        if self.context.p_category == 'admission_checking':
631            if self.context.p_state == 'paid':
632                flashtype = 'warning'
633                msg = _('This ticket has already been paid.')
634                log = None
635            else:
636                self.context.approve()
637                log = 'payment approved: %s' % self.context.p_id
638                msg = _('Payment approved')
639                flashtype = 'success'
640        else:
641            flashtype, msg, log = self.context.approveApplicantPayment()
642        if log is not None:
643            applicant = self.context.__parent__
644            # Add log message to applicants.log
645            applicant.writeLogMessage(self, log)
646            # Add log message to payments.log
647            self.context.logger.info(
648                '%s,%s,%s,%s,%s,,,,,,' % (
649                applicant.applicant_id,
650                self.context.p_id, self.context.p_category,
651                self.context.amount_auth, self.context.r_code))
652        self.flash(msg, type=flashtype)
653        return
654
655class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
656    """Deliver a PDF slip of the context.
657    """
658
659    def update(self):
660        super(CustomExportPDFPageApplicationSlip, self).update()
661        if self.context.state == ADMITTED and \
662            not self.context.admchecking_fee_paid():
663            self.flash(
664                _('Please pay admission checking fee before trying to download '
665                  'the application slip.'), type='warning')
666            return self.redirect(self.url(self.context))
667        return
668
669class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
670
671    def _getPDFCreator(self):
672        if self.target.startswith('ak'):
673            return getUtility(IPDFCreator, name='akoka_pdfcreator')
674        return getUtility(IPDFCreator)
675
676    @property
677    def form_fields(self):
678        if self.target is not None and self.target == 'tscf':
679            form_fields = grok.AutoFields(ITranscriptApplicant)
680            for field in TRANS_OMIT_PDF_FIELDS:
681                form_fields = form_fields.omit(field)
682        elif self.target is not None and self.target == 'tscs':
683            form_fields = grok.AutoFields(ITranscriptApplicant)
684            for field in TRANS_SHORT_OMIT_PDF_FIELDS:
685                form_fields = form_fields.omit(field)
686        elif self.target is not None and self.target == 'ictwk':
687            form_fields = grok.AutoFields(IUnibenRegistration)
688            for field in REGISTRATION_OMIT_PDF_FIELDS:
689                form_fields = form_fields.omit(field)
690        elif self.target is not None and self.target.startswith('pg'):
691            form_fields = grok.AutoFields(ICustomPGApplicant)
692            for field in PG_OMIT_PDF_FIELDS:
693                form_fields = form_fields.omit(field)
694        elif self.target is not None and self.target.startswith('pre'):
695            form_fields = grok.AutoFields(ICustomPGApplicant)
696            for field in PRE_OMIT_PDF_FIELDS:
697                form_fields = form_fields.omit(field)
698        elif self.target is not None and self.target.startswith('cbt'): # uniben
699            form_fields = grok.AutoFields(ICustomUGApplicant)
700            for field in CBT_OMIT_PDF_FIELDS:
701                form_fields = form_fields.omit(field)
702        elif self.target is not None and self.target.startswith('akj'): # uniben
703            form_fields = grok.AutoFields(ICustomPGApplicant)
704            for field in PRE_OMIT_PDF_FIELDS:
705                form_fields = form_fields.omit(field)
706        elif self.target is not None and self.target.startswith('ak'): # uniben
707            form_fields = grok.AutoFields(ICustomUGApplicant)
708            for field in AFFIL_OMIT_PDF_FIELDS:
709                form_fields = form_fields.omit(field)
710        elif self.target is not None and self.target.startswith('ase'): # was putme
711            form_fields = grok.AutoFields(ICustomUGApplicant)
712            if self._reduced_slip():
713                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
714                    form_fields = form_fields.omit(field)
715            else:
716                for field in PUTME_OMIT_PDF_FIELDS:
717                    form_fields = form_fields.omit(field)
718        elif self.target is not None and self.target.startswith('pude'):
719            form_fields = grok.AutoFields(ICustomUGApplicant)
720            if self._reduced_slip():
721                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
722                    form_fields = form_fields.omit(field)
723            else:
724                for field in PUDE_OMIT_PDF_FIELDS:
725                    form_fields = form_fields.omit(field)
726        elif self.target is not None and self.target == 'flc':
727            form_fields = grok.AutoFields(IFrenchApplicant)
728            for field in REGISTRATION_OMIT_PDF_FIELDS:
729                form_fields = form_fields.omit(field)
730        else:
731            form_fields = grok.AutoFields(ICustomUGApplicant)
732            for field in UG_OMIT_PDF_FIELDS:
733                form_fields = form_fields.omit(field)
734        if not getattr(self.context, 'student_id'):
735            form_fields = form_fields.omit('student_id')
736        if not getattr(self.context, 'screening_score'):
737            form_fields = form_fields.omit('screening_score')
738        if not getattr(self.context, 'screening_venue'):
739            form_fields = form_fields.omit('screening_venue')
740        if not getattr(self.context, 'screening_date'):
741            form_fields = form_fields.omit('screening_date')
742        return form_fields
743
744    @property
745    def title(self):
746        container_title = self.context.__parent__.title
747        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
748        ar_translation = translate(_('Application Record'),
749            'waeup.kofa', target_language=portal_language)
750        if self.target == 'ictwk':
751            return '%s - Registration Record %s' % (container_title,
752            self.context.application_number)
753        elif self.target.startswith('ab'):
754            return 'Federal College of Education (Technical) Asaba - %s %s %s' % (
755                container_title, ar_translation,
756                self.context.application_number)
757        elif self.target.startswith('ak'):
758            return 'Federal College of Education (Technical) Akoka - %s - %s %s' % (
759                container_title, ar_translation,
760                self.context.application_number)
761        elif self.target == 'pgn':
762            return 'National Institute for Legislative Studies (NILS) - %s %s %s' % (
763                container_title, ar_translation,
764                self.context.application_number)
765        return '%s - %s %s' % (container_title,
766            ar_translation, self.context.application_number)
767
768class CustomApplicantBaseDisplayFormPage(ApplicantBaseDisplayFormPage):
769
770    @property
771    def form_fields(self):
772        target = getattr(self.context.__parent__, 'prefix', None)
773        if target.startswith('tsc'):
774            form_fields = grok.AutoFields(ICustomApplicant).select(
775                'applicant_id', 'email', 'dispatch_address')
776        else:
777            form_fields = grok.AutoFields(ICustomApplicant).select(
778                'applicant_id', 'reg_number', 'email', 'course1')
779        if self.context.__parent__.prefix in ('special',):
780            form_fields['reg_number'].field.title = u'Identification Number'
781            return form_fields
782        return form_fields
783
784class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
785    """Deliver a PDF slip of the context.
786    """
787
788    @property
789    def omit_fields(self):
790        target = getattr(self.context.__parent__.__parent__, 'prefix', None)
791        if target.startswith('tsc'):
792            return ('date_of_birth', 'course1')
793        return ()
794
795    @property
796    def note(self):
797        return
798
799    def render(self):
800        if self.payment_slip_download_warning:
801            self.flash(self.payment_slip_download_warning, type='danger')
802            self.redirect(self.url(self.context))
803            return
804        applicantview = CustomApplicantBaseDisplayFormPage(self.context.__parent__,
805            self.request)
806        students_utils = getUtility(IStudentsUtils)
807        return students_utils.renderPDF(self,'payment_slip.pdf',
808            self.context.__parent__, applicantview,
809            note=self.note, omit_fields=self.omit_fields)
810
811class ExportScreeningInvitationSlip(UtilityView, grok.View):
812    """Deliver a PDF slip of the context.
813    """
814    grok.context(ICustomApplicant)
815    grok.name('screening_invitation_slip.pdf')
816    grok.require('waeup.viewApplication')
817    form_fields = None
818    label = u'Invitation Letter for Pre-Admission Screening'
819
820
821    @property
822    def note(self):
823        notice = getattr(self.context.__parent__, 'application_slip_notice')
824        if notice is None:
825            notice = ''
826        if self.context.screening_date:
827            return """
828<br /><br /><br /><br /><font size='12'>
829Dear %s,
830<br /><br /><br />
831You are invited for your Uniben Admission Screening Exercise on:
832<br /><br />
833<strong>%s</strong>.
834<br /><br />
835Please bring along this letter of invitation to the
836<br /><br />
837<strong>%s</strong>
838<br /><br />
839on your screening date.
840<br /><br /><br />
841Signed,
842<br /><br />
843The Registrar<br />
844<br /><br />
845<br /><br />
846%s
847</font>
848
849""" % (self.context.display_fullname, self.context.screening_date,
850       self.context.screening_venue, notice)
851        return
852
853    def update(self):
854        if not self.context.screening_date:
855            self.flash(_('Forbidden'), type="warning")
856            self.redirect(self.url(self.context))
857
858    def render(self):
859        applicantview = ApplicantBaseDisplayFormPage(self.context, self.request)
860        students_utils = getUtility(IStudentsUtils)
861        return students_utils.renderPDF(self,'screening_invitation_slip.pdf',
862            self.context, applicantview, note=self.note)
863
864class CustomCheckTranscriptStatus(CheckTranscriptStatus):
865    """A display page for checking transcript processing status.
866    """
867    grok.template('checktranscriptstatus')
868
869    websites = (('Uniben Alumni Portal', 'https://alumni.uniben.edu/'),
870                ('Uniben Student Portal', 'https://waeup.uniben.edu/'),)
871    appl_url1 = 'https://alumni.uniben.edu/applicants/tscf1/register'
872    appl_url2 = 'https://alumni.uniben.edu/applicants/tscs1/register'
873
874class CreateGraduatedPage(UtilityView, grok.View):
875    """Create a student object from transcript application data.
876    """
877    grok.context(ICustomApplicant)
878    grok.name('creategraduated')
879    grok.require('waeup.createStudents')
880
881    def update(self):
882        success, msg = self.context.createStudent(view=self, graduated=True)
883        if success:
884            self.flash(msg)
885        else:
886            self.flash(msg, type='warning')
887        self.redirect(self.url(self.context))
888        return
889
890    def render(self):
891        return
892
893class ResultStatement(AdditionalFile):
894    grok.name('res_stat')
895
896class EligibilityForm(AdditionalFile):
897    grok.name('eligibility')
Note: See TracBrowser for help on using the repository browser.