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

Last change on this file since 16475 was 16471, checked in by Henrik Bettermann, 4 years ago

Add two fields to transcript application.

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