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

Last change on this file since 16204 was 16199, checked in by Henrik Bettermann, 5 years ago

ASE applicants are not allowed to edit their uploaded passport picture. But they are allowed to submit if no poassport picture has been uploaded.

  • Property svn:keywords set to Id
File size: 31.4 KB
Line 
1## $Id: browser.py 16199 2020-08-15 09:15:24Z 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 = ('locked', 'suspended', 'applicant_id',)
133
134TRANS_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
146class CustomApplicantsContainerPage(ApplicantsContainerPage):
147    """The standard view for regular applicant containers.
148    """
149
150    @property
151    def form_fields(self):
152        form_fields = super(CustomApplicantsContainerPage, self).form_fields
153        usertype = getattr(self.request.principal, 'user_type', None)
154        if self.request.principal.id == 'zope.anybody' or  \
155            usertype in ('applicant', 'student'):
156            return form_fields.omit('application_fee')
157        return form_fields
158
159class CustomApplicantRegistrationPage(ApplicantRegistrationPage):
160    """Captcha'd registration page for applicants.
161    """
162
163    def _redirect(self, email, password, applicant_id):
164        # Forward email and credentials to landing page.
165        self.redirect(self.url(self.context, 'registration_complete',
166            data = dict(email=email, password=password,
167            applicant_id=applicant_id)))
168        return
169
170    @property
171    def label(self):
172        if self.context.prefix.startswith('tsc'):
173            return _('Request for ${a}',
174                mapping = {'a':self.context.title})
175        return _('Apply for ${a}',
176            mapping = {'a':self.context.title})
177
178class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
179    """A display view for applicant data.
180    """
181    grok.template('applicantdisplaypage')
182
183    @property
184    def display_payments(self):
185        if self.context.special or self.target == 'ictwk':
186            return True
187        return getattr(self.context.__parent__, 'application_fee', None)
188
189    def _show_pastq_putme(self):
190        return self.target.startswith('pre') \
191               and self.context.state in ('paid', 'submitted') \
192               and getattr(self.context, 'course1') is not None
193        # return False
194
195    @property
196    def depcode(self):
197        try:
198            code = self.context.course1.__parent__.__parent__.code
199            return code
200        except:
201            return
202
203    @property
204    def show_pastq_al(self):
205        return self._show_pastq_putme() # and self.depcode in PASTQ_AL
206
207    @property
208    def show_pastq_bs(self):
209        return self._show_pastq_putme() # and self.depcode in PASTQ_BS
210
211    @property
212    def show_pastq_eps(self):
213        return self._show_pastq_putme() # and self.depcode in PASTQ_EPS
214
215    @property
216    def show_pastq_mss(self):
217        return self._show_pastq_putme() # and self.depcode in PASTQ_MSS
218
219    @property
220    def show_pastq_pude(self):
221        return self.target.startswith('pude') \
222               and self.context.state in ('paid', 'submitted')
223
224    @property
225    def label(self):
226        if self.target == 'ictwk':
227            container_title = self.context.__parent__.title
228            return _('${a} <br /> Registration Record ${b}', mapping = {
229                'a':container_title, 'b':self.context.application_number})
230        return super(CustomApplicantDisplayFormPage, self).label
231
232    @property
233    def form_fields(self):
234        if self.target is not None and self.target == 'tscf':
235            form_fields = grok.AutoFields(ITranscriptApplicant)
236            for field in TRANS_OMIT_FIELDS:
237                form_fields = form_fields.omit(field)
238            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
239            #form_fields['perm_address'].custom_widget = BytesDisplayWidget
240            return form_fields
241        if self.target is not None and self.target == 'tscs':
242            form_fields = grok.AutoFields(ITranscriptApplicant)
243            for field in TRANS_SHORT_OMIT_FIELDS:
244                form_fields = form_fields.omit(field)
245            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
246            #form_fields['perm_address'].custom_widget = BytesDisplayWidget
247            return form_fields
248        if self.target == 'ictwk':
249            form_fields = grok.AutoFields(IUnibenRegistration)
250            for field in REGISTRATION_OMIT_DISPLAY_FIELDS:
251                form_fields = form_fields.omit(field)
252            return form_fields
253        elif self.target is not None and self.target.startswith('pg'):
254            form_fields = grok.AutoFields(ICustomPGApplicant)
255            for field in PG_OMIT_DISPLAY_FIELDS:
256                form_fields = form_fields.omit(field)
257        elif self.target is not None and self.target.startswith('pre'):
258            form_fields = grok.AutoFields(ICustomPGApplicant)
259            for field in PRE_OMIT_DISPLAY_FIELDS:
260                form_fields = form_fields.omit(field)
261        elif self.target is not None and self.target.startswith('cbt'):
262            form_fields = grok.AutoFields(ICustomUGApplicant)
263            for field in CBT_OMIT_DISPLAY_FIELDS:
264                form_fields = form_fields.omit(field)
265        elif self.target is not None and self.target.startswith('akj'):
266            form_fields = grok.AutoFields(ICustomPGApplicant)
267            for field in PRE_OMIT_DISPLAY_FIELDS:
268                form_fields = form_fields.omit(field)
269        elif self.target is not None and self.target.startswith('ak'):
270            form_fields = grok.AutoFields(ICustomUGApplicant)
271            for field in AFFIL_OMIT_DISPLAY_FIELDS:
272                form_fields = form_fields.omit(field)
273        elif self.target is not None and self.target.startswith('ase'): # was putme
274            form_fields = grok.AutoFields(ICustomUGApplicant)
275            for field in PUTME_OMIT_DISPLAY_FIELDS:
276                form_fields = form_fields.omit(field)
277        elif self.target is not None and self.target.startswith('pude'):
278            form_fields = grok.AutoFields(ICustomUGApplicant)
279            for field in PUDE_OMIT_DISPLAY_FIELDS:
280                form_fields = form_fields.omit(field)
281        else:
282            form_fields = grok.AutoFields(ICustomUGApplicant)
283            for field in UG_OMIT_DISPLAY_FIELDS:
284                form_fields = form_fields.omit(field)
285        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
286        form_fields['notice'].custom_widget = BytesDisplayWidget
287        if not getattr(self.context, 'student_id'):
288            form_fields = form_fields.omit('student_id')
289        if not getattr(self.context, 'screening_score'):
290            form_fields = form_fields.omit('screening_score')
291        if not getattr(self.context, 'screening_venue') or self._not_paid():
292            form_fields = form_fields.omit('screening_venue')
293        if not getattr(self.context, 'screening_date') or self._not_paid():
294            form_fields = form_fields.omit('screening_date')
295        if not self.context.admchecking_fee_paid():
296            form_fields = form_fields.omit(
297                'screening_score', 'aggregate', 'student_id')
298        return form_fields
299
300    @property
301    def display_actions(self):
302        state = IWorkflowState(self.context).getState()
303        actions = []
304        if state == ADMITTED and not self.context.admchecking_fee_paid():
305            actions = [_('Add admission checking payment ticket')]
306        return actions
307
308
309    def getCourseAdmitted(self):
310        """Return link, title and code in html format to the certificate
311           admitted.
312        """
313        if self.admission_checking_info:
314            return '<span class="hint">%s</span>' % self.admission_checking_info
315        return super(CustomApplicantDisplayFormPage, self).getCourseAdmitted()
316
317    @property
318    def admission_checking_info(self):
319        if self.context.state == ADMITTED and \
320            not self.context.admchecking_fee_paid():
321            return _('You must pay the admission checking fee '
322                     'to view your screening results and your course admitted.')
323        return
324
325    @action(_('Add admission checking payment ticket'), style='primary')
326    def addPaymentTicket(self, **data):
327        self.redirect(self.url(self.context, '@@addacp'))
328        return
329
330class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
331    """ Page to add an online payment ticket
332    """
333
334    @property
335    def custom_requirements(self):
336        if self.context.__parent__.with_picture:
337            store = getUtility(IExtFileStore)
338            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
339                return _('Upload your 1"x1" Red background passport photo before making payment.')
340        return ''
341
342class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View):
343    """ Page to add an admission checking online payment ticket.
344    """
345    grok.context(ICustomApplicant)
346    grok.name('addacp')
347    grok.require('waeup.payApplicant')
348    factory = u'waeup.ApplicantOnlinePayment'
349
350    def _setPaymentDetails(self, payment):
351        container = self.context.__parent__
352        timestamp = ("%d" % int(time()*10000))[1:]
353        session = str(container.year)
354        try:
355            session_config = grok.getSite()['configuration'][session]
356        except KeyError:
357            return _(u'Session configuration object is not available.'), None
358        payment.p_id = "p%s" % timestamp
359        payment.p_item = container.title
360        payment.p_session = container.year
361        payment.amount_auth = 0.0
362        payment.p_category = 'admission_checking'
363        payment.amount_auth = session_config.admchecking_fee
364        if payment.amount_auth in (0.0, None):
365            return _('Amount could not be determined.'), None
366        return
367
368    def update(self):
369        if self.context.admchecking_fee_paid():
370              self.flash(
371                  _('Admission checking payment has already been made.'),
372                  type='warning')
373              self.redirect(self.url(self.context))
374              return
375        payment = createObject(self.factory)
376        failure = self._setPaymentDetails(payment)
377        if failure is not None:
378            self.flash(failure[0], type='danger')
379            self.redirect(self.url(self.context))
380            return
381        self.context[payment.p_id] = payment
382        self.flash(_('Payment ticket created.'))
383        self.redirect(self.url(payment))
384        return
385
386    def render(self):
387        return
388
389
390class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
391
392    @property
393    def display_payments(self):
394        if self.context.special or self.target == 'ictwk':
395            return True
396        return getattr(self.context.__parent__, 'application_fee', None)
397
398    @property
399    def custom_upload_requirements(self):
400        if not checkPermission('waeup.uploadPassportPictures', self.context):
401            return _('You are not entitled to upload passport pictures.')
402
403    @property
404    def label(self):
405        if self.target == 'ictwk':
406            container_title = self.context.__parent__.title
407            return _('${a} <br /> Registration Record ${b}', mapping = {
408                'a':container_title, 'b':self.context.application_number})
409        return super(CustomApplicantManageFormPage, self).label
410
411    @property
412    def form_fields(self):
413        if self.target is not None and self.target == 'tscf':
414            form_fields = grok.AutoFields(ITranscriptApplicant)
415            for field in TRANS_OMIT_FIELDS:
416                form_fields = form_fields.omit(field)
417            return form_fields
418        if self.target is not None and self.target == 'tscs':
419            form_fields = grok.AutoFields(ITranscriptApplicant)
420            for field in TRANS_SHORT_OMIT_FIELDS:
421                form_fields = form_fields.omit(field)
422            return form_fields
423        if self.target == 'ictwk':
424            form_fields = grok.AutoFields(IUnibenRegistration)
425            for field in REGISTRATION_OMIT_MANAGE_FIELDS:
426                form_fields = form_fields.omit(field)
427            state = IWorkflowState(self.context).getState()
428            if state != STARTED:
429                form_fields['registration_cats'].for_display = True
430            return form_fields
431        if self.target is not None and self.target.startswith('pg'):
432            form_fields = grok.AutoFields(ICustomPGApplicant)
433            for field in PG_OMIT_MANAGE_FIELDS:
434                form_fields = form_fields.omit(field)
435        elif self.target is not None and self.target.startswith('pre'):
436            form_fields = grok.AutoFields(ICustomPGApplicant)
437            for field in PRE_OMIT_MANAGE_FIELDS:
438                form_fields = form_fields.omit(field)
439        elif self.target is not None and self.target.startswith('cbt'):
440            form_fields = grok.AutoFields(ICustomUGApplicant)
441            for field in CBT_OMIT_MANAGE_FIELDS:
442                form_fields = form_fields.omit(field)
443        elif self.target is not None and self.target.startswith('akj'):
444            form_fields = grok.AutoFields(ICustomPGApplicant)
445            for field in PRE_OMIT_MANAGE_FIELDS:
446                form_fields = form_fields.omit(field)
447        elif self.target is not None and self.target.startswith('ak'):
448            form_fields = grok.AutoFields(ICustomUGApplicant)
449            for field in AFFIL_OMIT_MANAGE_FIELDS:
450                form_fields = form_fields.omit(field)
451        elif self.target is not None and self.target.startswith('ase'): # was putme
452            form_fields = grok.AutoFields(ICustomUGApplicant)
453            for field in PUTME_OMIT_MANAGE_FIELDS:
454                form_fields = form_fields.omit(field)
455        elif self.target is not None and self.target.startswith('pude'):
456            form_fields = grok.AutoFields(ICustomUGApplicant)
457            for field in PUDE_OMIT_MANAGE_FIELDS:
458                form_fields = form_fields.omit(field)
459        else:
460            form_fields = grok.AutoFields(ICustomUGApplicant)
461            for field in UG_OMIT_MANAGE_FIELDS:
462                form_fields = form_fields.omit(field)
463        form_fields['student_id'].for_display = True
464        form_fields['applicant_id'].for_display = True
465        return form_fields
466
467
468class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
469    """An applicant-centered edit view for applicant data.
470    """
471
472    def unremovable(self, ticket):
473        return True
474
475    @property
476    def display_payments(self):
477        if self.context.special or self.target == 'ictwk':
478            return True
479        return getattr(self.context.__parent__, 'application_fee', None)
480
481    @property
482    def form_fields(self):
483        if self.target is not None and self.target == 'tscf':
484            form_fields = grok.AutoFields(ITranscriptApplicant)
485            for field in TRANS_OMIT_FIELDS:
486                form_fields = form_fields.omit(field)
487            return form_fields
488        if self.target is not None and self.target == 'tscs':
489            form_fields = grok.AutoFields(ITranscriptApplicant)
490            for field in TRANS_SHORT_OMIT_FIELDS:
491                form_fields = form_fields.omit(field)
492            return form_fields
493        if self.target == 'ictwk':
494            form_fields = grok.AutoFields(IUnibenRegistration)
495            for field in REGISTRATION_OMIT_EDIT_FIELDS:
496                form_fields = form_fields.omit(field)
497            state = IWorkflowState(self.context).getState()
498            if state != STARTED:
499                form_fields['registration_cats'].for_display = True
500            return form_fields
501        if self.target is not None and self.target.startswith('pg'):
502            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
503            for field in PG_OMIT_EDIT_FIELDS:
504                form_fields = form_fields.omit(field)
505        elif self.target is not None and self.target.startswith('pre'):
506            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
507            for field in PRE_OMIT_EDIT_FIELDS:
508                form_fields = form_fields.omit(field)
509        elif self.target is not None and self.target.startswith('cbt'):
510            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
511            for field in CBT_OMIT_EDIT_FIELDS:
512                form_fields = form_fields.omit(field)
513        elif self.target is not None and self.target.startswith('akj'):
514            form_fields = grok.AutoFields(ICustomPGApplicant)
515            for field in PRE_OMIT_EDIT_FIELDS:
516                form_fields = form_fields.omit(field)
517        elif self.target is not None and self.target.startswith('ak'):
518            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
519            for field in AFFIL_OMIT_EDIT_FIELDS:
520                form_fields = form_fields.omit(field)
521        elif self.target is not None and self.target.startswith('ase'): # was putme
522            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
523            for field in PUTME_OMIT_EDIT_FIELDS:
524                form_fields = form_fields.omit(field)
525        elif self.target is not None and self.target.startswith('pude'):
526            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
527            for field in PUDE_OMIT_EDIT_FIELDS:
528                form_fields = form_fields.omit(field)
529        else:
530            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
531            for field in UG_OMIT_EDIT_FIELDS:
532                form_fields = form_fields.omit(field)
533        form_fields['applicant_id'].for_display = True
534        form_fields['reg_number'].for_display = True
535        return form_fields
536
537    @property
538    def label(self):
539        if self.target == 'ictwk':
540            container_title = self.context.__parent__.title
541            return _('${a} <br /> Registration Record ${b}', mapping = {
542                'a':container_title, 'b':self.context.application_number})
543        return super(CustomApplicantEditFormPage, self).label
544
545    def display_fileupload(self, filename):
546        if filename[1] == 'res_stat.pdf' \
547            and self.target is not None \
548            and not self.target.startswith('tscf'):
549            return False
550        if filename[1] == 'eligibility.pdf' \
551            and self.target is not None \
552            and not self.target.startswith('tsc'):
553            return False
554        return True
555
556    def dataNotComplete(self, data):
557        store = getUtility(IExtFileStore)
558        if self.context.__parent__.with_picture \
559            and self.context.__parent__.picture_editable:
560            store = getUtility(IExtFileStore)
561            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
562                return _('No passport picture uploaded.')
563        if self.target is not None \
564            and self.target.startswith('tscf') \
565            and not store.getFileByContext(self.context, attr=u'res_stat.pdf'):
566            return _('No statement of result pdf file uploaded.')
567        #if self.target is not None \
568        #    and self.target.startswith('tsc') \
569        #    and not store.getFileByContext(self.context, attr=u'eligibility.pdf'):
570        #    return _('No eligibility form pdf file uploaded.')
571        return False
572
573class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage):
574    """ Approval view
575    """
576
577    def update(self):
578        if self.context.p_category == 'admission_checking':
579            if self.context.p_state == 'paid':
580                flashtype = 'warning'
581                msg = _('This ticket has already been paid.')
582                log = None
583            else:
584                self.context.approve()
585                log = 'payment approved: %s' % self.context.p_id
586                msg = _('Payment approved')
587                flashtype = 'success'
588        else:
589            flashtype, msg, log = self.context.approveApplicantPayment()
590        if log is not None:
591            applicant = self.context.__parent__
592            # Add log message to applicants.log
593            applicant.writeLogMessage(self, log)
594            # Add log message to payments.log
595            self.context.logger.info(
596                '%s,%s,%s,%s,%s,,,,,,' % (
597                applicant.applicant_id,
598                self.context.p_id, self.context.p_category,
599                self.context.amount_auth, self.context.r_code))
600        self.flash(msg, type=flashtype)
601        return
602
603class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
604    """Deliver a PDF slip of the context.
605    """
606
607    def update(self):
608        super(CustomExportPDFPageApplicationSlip, self).update()
609        if self.context.state == ADMITTED and \
610            not self.context.admchecking_fee_paid():
611            self.flash(
612                _('Please pay admission checking fee before trying to download '
613                  'the application slip.'), type='warning')
614            return self.redirect(self.url(self.context))
615        return
616
617class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
618
619    def _getPDFCreator(self):
620        if self.target.startswith('ak'):
621            return getUtility(IPDFCreator, name='akoka_pdfcreator')
622        return getUtility(IPDFCreator)
623
624    @property
625    def form_fields(self):
626        if self.target is not None and self.target == 'tscf':
627            form_fields = grok.AutoFields(ITranscriptApplicant)
628            for field in TRANS_OMIT_FIELDS:
629                form_fields = form_fields.omit(field)
630        elif self.target is not None and self.target == 'tscs':
631            form_fields = grok.AutoFields(ITranscriptApplicant)
632            for field in TRANS_SHORT_OMIT_FIELDS:
633                form_fields = form_fields.omit(field)
634        elif self.target is not None and self.target == 'ictwk':
635            form_fields = grok.AutoFields(IUnibenRegistration)
636            for field in REGISTRATION_OMIT_PDF_FIELDS:
637                form_fields = form_fields.omit(field)
638        elif self.target is not None and self.target.startswith('pg'):
639            form_fields = grok.AutoFields(ICustomPGApplicant)
640            for field in PG_OMIT_PDF_FIELDS:
641                form_fields = form_fields.omit(field)
642        elif self.target is not None and self.target.startswith('pre'):
643            form_fields = grok.AutoFields(ICustomPGApplicant)
644            for field in PRE_OMIT_PDF_FIELDS:
645                form_fields = form_fields.omit(field)
646        elif self.target is not None and self.target.startswith('cbt'): # uniben
647            form_fields = grok.AutoFields(ICustomUGApplicant)
648            for field in CBT_OMIT_PDF_FIELDS:
649                form_fields = form_fields.omit(field)
650        elif self.target is not None and self.target.startswith('akj'): # uniben
651            form_fields = grok.AutoFields(ICustomPGApplicant)
652            for field in PRE_OMIT_PDF_FIELDS:
653                form_fields = form_fields.omit(field)
654        elif self.target is not None and self.target.startswith('ak'): # uniben
655            form_fields = grok.AutoFields(ICustomUGApplicant)
656            for field in AFFIL_OMIT_PDF_FIELDS:
657                form_fields = form_fields.omit(field)
658        elif self.target is not None and self.target.startswith('ase'): # was putme
659            form_fields = grok.AutoFields(ICustomUGApplicant)
660            if self._reduced_slip():
661                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
662                    form_fields = form_fields.omit(field)
663            else:
664                for field in PUTME_OMIT_PDF_FIELDS:
665                    form_fields = form_fields.omit(field)
666        elif self.target is not None and self.target.startswith('pude'):
667            form_fields = grok.AutoFields(ICustomUGApplicant)
668            if self._reduced_slip():
669                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
670                    form_fields = form_fields.omit(field)
671            else:
672                for field in PUDE_OMIT_PDF_FIELDS:
673                    form_fields = form_fields.omit(field)
674        else:
675            form_fields = grok.AutoFields(ICustomUGApplicant)
676            for field in UG_OMIT_PDF_FIELDS:
677                form_fields = form_fields.omit(field)
678        if not getattr(self.context, 'student_id'):
679            form_fields = form_fields.omit('student_id')
680        if not getattr(self.context, 'screening_score'):
681            form_fields = form_fields.omit('screening_score')
682        if not getattr(self.context, 'screening_venue'):
683            form_fields = form_fields.omit('screening_venue')
684        if not getattr(self.context, 'screening_date'):
685            form_fields = form_fields.omit('screening_date')
686        return form_fields
687
688    @property
689    def title(self):
690        container_title = self.context.__parent__.title
691        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
692        ar_translation = translate(_('Application Record'),
693            'waeup.kofa', target_language=portal_language)
694        if self.target == 'ictwk':
695            return '%s - Registration Record %s' % (container_title,
696            self.context.application_number)
697        elif self.target.startswith('ab'):
698            return 'Federal College of Education (Technical) Asaba - %s %s %s' % (
699                container_title, ar_translation,
700                self.context.application_number)
701        elif self.target.startswith('ak'):
702            return 'Federal College of Education (Technical) Akoka - %s - %s %s' % (
703                container_title, ar_translation,
704                self.context.application_number)
705        elif self.target == 'pgn':
706            return 'National Institute for Legislative Studies (NILS) - %s %s %s' % (
707                container_title, ar_translation,
708                self.context.application_number)
709        return '%s - %s %s' % (container_title,
710            ar_translation, self.context.application_number)
711
712class ExportScreeningInvitationSlip(UtilityView, grok.View):
713    """Deliver a PDF slip of the context.
714    """
715    grok.context(ICustomApplicant)
716    grok.name('screening_invitation_slip.pdf')
717    grok.require('waeup.viewApplication')
718    form_fields = None
719    label = u'Invitation Letter for Pre-Admission Screening'
720
721
722    @property
723    def note(self):
724        notice = getattr(self.context.__parent__, 'application_slip_notice', None)
725        if self.context.screening_date:
726            return """
727<br /><br /><br /><br /><font size='12'>
728Dear %s,
729<br /><br /><br />
730You are invited for your Uniben Admission Screening Exercise on:
731<br /><br />
732<strong>%s</strong>.
733<br /><br />
734Please bring along this letter of invitation to the
735<br /><br />
736<strong>%s</strong>
737<br /><br />
738on your screening date.
739<br /><br /><br />
740Signed,
741<br /><br />
742The Registrar<br />
743<br /><br />
744<br /><br />
745%s
746</font>
747
748""" % (self.context.display_fullname, self.context.screening_date,
749       self.context.screening_venue, notice)
750        return
751
752    def update(self):
753        if not self.context.screening_date:
754            self.flash(_('Forbidden'), type="warning")
755            self.redirect(self.url(self.context))
756
757    def render(self):
758        applicantview = ApplicantBaseDisplayFormPage(self.context, self.request)
759        students_utils = getUtility(IStudentsUtils)
760        return students_utils.renderPDF(self,'screening_invitation_slip.pdf',
761            self.context, applicantview, note=self.note)
762
763class CustomCheckTranscriptStatus(CheckTranscriptStatus):
764    """A display page for checking transcript processing status.
765    """
766    websites = (('Uniben Alumni Portal', 'https://uniben-alumni.waeup.org/'),
767                ('Uniben Student Portal', 'https://uniben.waeup.org/'),)
768    appl_url1 = 'https://uniben-alumni.waeup.org/applicants/tscf1/register'
769    appl_url2 = 'https://uniben-alumni.waeup.org/applicants/tscs1/register'
770
771class ResultStatement(AdditionalFile):
772    grok.name('res_stat.pdf')
773
774class EligibilityForm(AdditionalFile):
775    grok.name('eligibility.pdf')
Note: See TracBrowser for help on using the repository browser.