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

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

Implement transcript applications.

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