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

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

Show res_stat upload button also to tscf applicants.

  • Property svn:keywords set to Id
File size: 32.4 KB
Line 
1## $Id: browser.py 16332 2020-11-23 20:05:52Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""UI components for basic applicants and related components.
19"""
20import grok
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            for field in TRANS_OMIT_EDIT_FIELDS:
497                form_fields = form_fields.omit(field)
498                form_fields = form_fields.omit('locked')
499            return form_fields
500        if self.target is not None and self.target == 'tscs':
501            form_fields = grok.AutoFields(ITranscriptApplicant)
502            for field in TRANS_SHORT_OMIT_EDIT_FIELDS:
503                form_fields = form_fields.omit(field)
504                form_fields = form_fields.omit('locked')
505            return form_fields
506        if self.target == 'ictwk':
507            form_fields = grok.AutoFields(IUnibenRegistration)
508            for field in REGISTRATION_OMIT_EDIT_FIELDS:
509                form_fields = form_fields.omit(field)
510            state = IWorkflowState(self.context).getState()
511            if state != STARTED:
512                form_fields['registration_cats'].for_display = True
513            return form_fields
514        if self.target is not None and self.target.startswith('pg'):
515            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
516            for field in PG_OMIT_EDIT_FIELDS:
517                form_fields = form_fields.omit(field)
518        elif self.target is not None and self.target.startswith('pre'):
519            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
520            for field in PRE_OMIT_EDIT_FIELDS:
521                form_fields = form_fields.omit(field)
522        elif self.target is not None and self.target.startswith('cbt'):
523            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
524            for field in CBT_OMIT_EDIT_FIELDS:
525                form_fields = form_fields.omit(field)
526        elif self.target is not None and self.target.startswith('akj'):
527            form_fields = grok.AutoFields(ICustomPGApplicant)
528            for field in PRE_OMIT_EDIT_FIELDS:
529                form_fields = form_fields.omit(field)
530        elif self.target is not None and self.target.startswith('ak'):
531            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
532            for field in AFFIL_OMIT_EDIT_FIELDS:
533                form_fields = form_fields.omit(field)
534        elif self.target is not None and self.target.startswith('ase'): # was putme
535            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
536            for field in PUTME_OMIT_EDIT_FIELDS:
537                form_fields = form_fields.omit(field)
538        elif self.target is not None and self.target.startswith('pude'):
539            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
540            for field in PUDE_OMIT_EDIT_FIELDS:
541                form_fields = form_fields.omit(field)
542        else:
543            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
544            for field in UG_OMIT_EDIT_FIELDS:
545                form_fields = form_fields.omit(field)
546        form_fields['applicant_id'].for_display = True
547        form_fields['reg_number'].for_display = True
548        return form_fields
549
550    @property
551    def label(self):
552        if self.target == 'ictwk':
553            container_title = self.context.__parent__.title
554            return _('${a} <br /> Registration Record ${b}', mapping = {
555                'a':container_title, 'b':self.context.application_number})
556        return super(CustomApplicantEditFormPage, self).label
557
558    def display_fileupload(self, filename):
559        if filename[1] == 'res_stat.pdf' \
560            and self.target is not None \
561            and not self.target.startswith('tsc'):
562            return False
563        if filename[1] == 'eligibility.pdf' \
564            and self.target is not None \
565            and not self.target.startswith('tsc'):
566            return False
567        return True
568
569    def dataNotComplete(self, data):
570        store = getUtility(IExtFileStore)
571        if self.context.__parent__.with_picture \
572            and self.context.__parent__.picture_editable:
573            store = getUtility(IExtFileStore)
574            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
575                return _('No passport picture uploaded.')
576        if self.target is not None \
577            and self.target.startswith('tscf') \
578            and not store.getFileByContext(self.context, attr=u'res_stat.pdf'):
579            return _('No statement of result pdf file uploaded.')
580        #if self.target is not None \
581        #    and self.target.startswith('tsc') \
582        #    and not store.getFileByContext(self.context, attr=u'eligibility.pdf'):
583        #    return _('No eligibility form pdf file uploaded.')
584        return False
585
586class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage):
587    """ Approval view
588    """
589
590    def update(self):
591        if self.context.p_category == 'admission_checking':
592            if self.context.p_state == 'paid':
593                flashtype = 'warning'
594                msg = _('This ticket has already been paid.')
595                log = None
596            else:
597                self.context.approve()
598                log = 'payment approved: %s' % self.context.p_id
599                msg = _('Payment approved')
600                flashtype = 'success'
601        else:
602            flashtype, msg, log = self.context.approveApplicantPayment()
603        if log is not None:
604            applicant = self.context.__parent__
605            # Add log message to applicants.log
606            applicant.writeLogMessage(self, log)
607            # Add log message to payments.log
608            self.context.logger.info(
609                '%s,%s,%s,%s,%s,,,,,,' % (
610                applicant.applicant_id,
611                self.context.p_id, self.context.p_category,
612                self.context.amount_auth, self.context.r_code))
613        self.flash(msg, type=flashtype)
614        return
615
616class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
617    """Deliver a PDF slip of the context.
618    """
619
620    def update(self):
621        super(CustomExportPDFPageApplicationSlip, self).update()
622        if self.context.state == ADMITTED and \
623            not self.context.admchecking_fee_paid():
624            self.flash(
625                _('Please pay admission checking fee before trying to download '
626                  'the application slip.'), type='warning')
627            return self.redirect(self.url(self.context))
628        return
629
630class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
631
632    def _getPDFCreator(self):
633        if self.target.startswith('ak'):
634            return getUtility(IPDFCreator, name='akoka_pdfcreator')
635        return getUtility(IPDFCreator)
636
637    @property
638    def form_fields(self):
639        if self.target is not None and self.target == 'tscf':
640            form_fields = grok.AutoFields(ITranscriptApplicant)
641            for field in TRANS_OMIT_PDF_FIELDS:
642                form_fields = form_fields.omit(field)
643        elif self.target is not None and self.target == 'tscs':
644            form_fields = grok.AutoFields(ITranscriptApplicant)
645            for field in TRANS_SHORT_OMIT_PDF_FIELDS:
646                form_fields = form_fields.omit(field)
647        elif self.target is not None and self.target == 'ictwk':
648            form_fields = grok.AutoFields(IUnibenRegistration)
649            for field in REGISTRATION_OMIT_PDF_FIELDS:
650                form_fields = form_fields.omit(field)
651        elif self.target is not None and self.target.startswith('pg'):
652            form_fields = grok.AutoFields(ICustomPGApplicant)
653            for field in PG_OMIT_PDF_FIELDS:
654                form_fields = form_fields.omit(field)
655        elif self.target is not None and self.target.startswith('pre'):
656            form_fields = grok.AutoFields(ICustomPGApplicant)
657            for field in PRE_OMIT_PDF_FIELDS:
658                form_fields = form_fields.omit(field)
659        elif self.target is not None and self.target.startswith('cbt'): # uniben
660            form_fields = grok.AutoFields(ICustomUGApplicant)
661            for field in CBT_OMIT_PDF_FIELDS:
662                form_fields = form_fields.omit(field)
663        elif self.target is not None and self.target.startswith('akj'): # uniben
664            form_fields = grok.AutoFields(ICustomPGApplicant)
665            for field in PRE_OMIT_PDF_FIELDS:
666                form_fields = form_fields.omit(field)
667        elif self.target is not None and self.target.startswith('ak'): # uniben
668            form_fields = grok.AutoFields(ICustomUGApplicant)
669            for field in AFFIL_OMIT_PDF_FIELDS:
670                form_fields = form_fields.omit(field)
671        elif self.target is not None and self.target.startswith('ase'): # was putme
672            form_fields = grok.AutoFields(ICustomUGApplicant)
673            if self._reduced_slip():
674                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
675                    form_fields = form_fields.omit(field)
676            else:
677                for field in PUTME_OMIT_PDF_FIELDS:
678                    form_fields = form_fields.omit(field)
679        elif self.target is not None and self.target.startswith('pude'):
680            form_fields = grok.AutoFields(ICustomUGApplicant)
681            if self._reduced_slip():
682                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
683                    form_fields = form_fields.omit(field)
684            else:
685                for field in PUDE_OMIT_PDF_FIELDS:
686                    form_fields = form_fields.omit(field)
687        else:
688            form_fields = grok.AutoFields(ICustomUGApplicant)
689            for field in UG_OMIT_PDF_FIELDS:
690                form_fields = form_fields.omit(field)
691        if not getattr(self.context, 'student_id'):
692            form_fields = form_fields.omit('student_id')
693        if not getattr(self.context, 'screening_score'):
694            form_fields = form_fields.omit('screening_score')
695        if not getattr(self.context, 'screening_venue'):
696            form_fields = form_fields.omit('screening_venue')
697        if not getattr(self.context, 'screening_date'):
698            form_fields = form_fields.omit('screening_date')
699        return form_fields
700
701    @property
702    def title(self):
703        container_title = self.context.__parent__.title
704        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
705        ar_translation = translate(_('Application Record'),
706            'waeup.kofa', target_language=portal_language)
707        if self.target == 'ictwk':
708            return '%s - Registration Record %s' % (container_title,
709            self.context.application_number)
710        elif self.target.startswith('ab'):
711            return 'Federal College of Education (Technical) Asaba - %s %s %s' % (
712                container_title, ar_translation,
713                self.context.application_number)
714        elif self.target.startswith('ak'):
715            return 'Federal College of Education (Technical) Akoka - %s - %s %s' % (
716                container_title, ar_translation,
717                self.context.application_number)
718        elif self.target == 'pgn':
719            return 'National Institute for Legislative Studies (NILS) - %s %s %s' % (
720                container_title, ar_translation,
721                self.context.application_number)
722        return '%s - %s %s' % (container_title,
723            ar_translation, self.context.application_number)
724
725class ExportScreeningInvitationSlip(UtilityView, grok.View):
726    """Deliver a PDF slip of the context.
727    """
728    grok.context(ICustomApplicant)
729    grok.name('screening_invitation_slip.pdf')
730    grok.require('waeup.viewApplication')
731    form_fields = None
732    label = u'Invitation Letter for Pre-Admission Screening'
733
734
735    @property
736    def note(self):
737        notice = getattr(self.context.__parent__, 'application_slip_notice', None)
738        if self.context.screening_date:
739            return """
740<br /><br /><br /><br /><font size='12'>
741Dear %s,
742<br /><br /><br />
743You are invited for your Uniben Admission Screening Exercise on:
744<br /><br />
745<strong>%s</strong>.
746<br /><br />
747Please bring along this letter of invitation to the
748<br /><br />
749<strong>%s</strong>
750<br /><br />
751on your screening date.
752<br /><br /><br />
753Signed,
754<br /><br />
755The Registrar<br />
756<br /><br />
757<br /><br />
758%s
759</font>
760
761""" % (self.context.display_fullname, self.context.screening_date,
762       self.context.screening_venue, notice)
763        return
764
765    def update(self):
766        if not self.context.screening_date:
767            self.flash(_('Forbidden'), type="warning")
768            self.redirect(self.url(self.context))
769
770    def render(self):
771        applicantview = ApplicantBaseDisplayFormPage(self.context, self.request)
772        students_utils = getUtility(IStudentsUtils)
773        return students_utils.renderPDF(self,'screening_invitation_slip.pdf',
774            self.context, applicantview, note=self.note)
775
776class CustomCheckTranscriptStatus(CheckTranscriptStatus):
777    """A display page for checking transcript processing status.
778    """
779    websites = (('Uniben Alumni Portal', 'https://uniben-alumni.waeup.org/'),
780                ('Uniben Student Portal', 'https://uniben.waeup.org/'),)
781    appl_url1 = 'https://uniben-alumni.waeup.org/applicants/tscf1/register'
782    appl_url2 = 'https://uniben-alumni.waeup.org/applicants/tscs1/register'
783
784class CreateGraduatedPage(UtilityView, grok.View):
785    """Create a student object from transcript application data.
786    """
787    grok.context(ICustomApplicant)
788    grok.name('creategraduated')
789    grok.require('waeup.createStudents')
790
791    def update(self):
792        success, msg = self.context.createStudent(view=self, graduated=True)
793        if success:
794            self.flash(msg)
795        else:
796            self.flash(msg, type='warning')
797        self.redirect(self.url(self.context))
798        return
799
800    def render(self):
801        return
802
803class ResultStatement(AdditionalFile):
804    grok.name('res_stat.pdf')
805
806class EligibilityForm(AdditionalFile):
807    grok.name('eligibility.pdf')
Note: See TracBrowser for help on using the repository browser.