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

Last change on this file since 15362 was 15125, checked in by Henrik Bettermann, 6 years ago

Simplify pagetemplate.

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