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

Last change on this file since 14247 was 14168, checked in by Henrik Bettermann, 8 years ago

Put application_slip_notice onto invitation letter.

  • Property svn:keywords set to Id
File size: 26.5 KB
Line 
1## $Id: browser.py 14168 2016-09-13 13:30:05Z 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)
35from waeup.kofa.students.interfaces import IStudentsUtils
36from waeup.kofa.applicants.interfaces import (
37    ISpecialApplicant, IApplicantsUtils)
38from waeup.kofa.browser.interfaces import IPDFCreator
39from kofacustom.nigeria.applicants.browser import (
40    NigeriaApplicantDisplayFormPage,
41    NigeriaApplicantManageFormPage,
42    NigeriaApplicantEditFormPage,
43    NigeriaPDFApplicationSlip)
44from waeup.uniben.applicants.interfaces import (
45    ICustomApplicant,
46    IUnibenRegistration,
47    ICustomUGApplicant,
48    ICustomPGApplicant,
49    ICustomPGApplicantEdit,
50    ICustomUGApplicantEdit,
51    IPUTMEApplicantEdit)
52from waeup.kofa.applicants.workflow import ADMITTED, PAID, STARTED
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    )
85
86from waeup.uniben.interfaces import MessageFactory as _
87
88PASTQ_ALL = ['ADT','EPCS','ESM','HEK','VTE']
89
90PASTQ_AL = ['ENL','FAA','FOL','HIS','LAL',
91            'PHL','THR','BUL','JIL','LAW','PPL','PUL'] + PASTQ_ALL
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
99PASTQ_EPS = ['CHE','CVE','DMIC','EEE','MCH','PEE','PRE','CHM',
100             'CSC','GLY','MTH','PHY'] + PASTQ_ALL
101
102PASTQ_MSS = ['ACC','BNK','BUS','ECO','GEO','POL','SAA','SWK'] + PASTQ_ALL
103
104REGISTRATION_OMIT_DISPLAY_FIELDS = (
105    'locked',
106    'suspended',
107    )
108
109REGISTRATION_OMIT_EDIT_FIELDS = (
110    'locked',
111    'suspended',
112    'applicant_id',
113    )
114
115REGISTRATION_OMIT_MANAGE_FIELDS = (
116    'applicant_id',
117    )
118
119
120REGISTRATION_OMIT_PDF_FIELDS = (
121    'locked',
122    'suspended',
123    )
124class CustomApplicantsContainerPage(ApplicantsContainerPage):
125    """The standard view for regular applicant containers.
126    """
127
128    @property
129    def form_fields(self):
130        form_fields = super(CustomApplicantsContainerPage, self).form_fields
131        usertype = getattr(self.request.principal, 'user_type', None)
132        if self.request.principal.id == 'zope.anybody' or  \
133            usertype in ('applicant', 'student'):
134            return form_fields.omit('application_fee')
135        return form_fields
136
137class CustomApplicantRegistrationPage(ApplicantRegistrationPage):
138    """Captcha'd registration page for applicants.
139    """
140
141    def _redirect(self, email, password, applicant_id):
142        # Forward email and credentials to landing page.
143        self.redirect(self.url(self.context, 'registration_complete',
144            data = dict(email=email, password=password,
145            applicant_id=applicant_id)))
146        return
147
148class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
149    """A display view for applicant data.
150    """
151    grok.template('applicantdisplaypage')
152
153    @property
154    def display_payments(self):
155        if self.context.special or self.target == 'ictwk':
156            return True
157        return getattr(self.context.__parent__, 'application_fee', None)
158
159    def _show_pastq_putme(self):
160        #return self.target.startswith('ase') \
161        #       and self.context.state in ('paid', 'submitted') \
162        #       and getattr(self.context, 'course1') is not None
163        return False
164
165    @property
166    def depcode(self):
167        try:
168            code = self.context.course1.__parent__.__parent__.code
169            return code
170        except:
171            return
172
173    @property
174    def show_pastq_al(self):
175        return self._show_pastq_putme() and self.depcode in PASTQ_AL
176
177    @property
178    def show_pastq_bs(self):
179        return self._show_pastq_putme() and self.depcode in PASTQ_BS
180
181    @property
182    def show_pastq_eps(self):
183        return self._show_pastq_putme() and self.depcode in PASTQ_EPS
184
185    @property
186    def show_pastq_mss(self):
187        return self._show_pastq_putme() and self.depcode in PASTQ_MSS
188
189    @property
190    def show_pastq_pude(self):
191        return self.target.startswith('pude') \
192               and self.context.state in ('paid', 'submitted')
193
194    @property
195    def label(self):
196        if self.target == 'ictwk':
197            container_title = self.context.__parent__.title
198            return _('${a} <br /> Registration Record ${b}', mapping = {
199                'a':container_title, 'b':self.context.application_number})
200        return super(CustomApplicantDisplayFormPage, self).label
201
202    @property
203    def form_fields(self):
204        if self.target == 'ictwk':
205            form_fields = grok.AutoFields(IUnibenRegistration)
206            for field in REGISTRATION_OMIT_DISPLAY_FIELDS:
207                form_fields = form_fields.omit(field)
208            return form_fields
209        elif self.target is not None and self.target.startswith('pg'):
210            form_fields = grok.AutoFields(ICustomPGApplicant)
211            for field in PG_OMIT_DISPLAY_FIELDS:
212                form_fields = form_fields.omit(field)
213        elif self.target is not None and self.target.startswith('pre'):
214            form_fields = grok.AutoFields(ICustomPGApplicant)
215            for field in PRE_OMIT_DISPLAY_FIELDS:
216                form_fields = form_fields.omit(field)
217        elif self.target is not None and self.target.startswith('cbt'):
218            form_fields = grok.AutoFields(ICustomUGApplicant)
219            for field in CBT_OMIT_DISPLAY_FIELDS:
220                form_fields = form_fields.omit(field)
221        elif self.target is not None and self.target.startswith('akj'):
222            form_fields = grok.AutoFields(ICustomPGApplicant)
223            for field in PRE_OMIT_DISPLAY_FIELDS:
224                form_fields = form_fields.omit(field)
225        elif self.target is not None and self.target.startswith('ak'):
226            form_fields = grok.AutoFields(ICustomUGApplicant)
227            for field in AFFIL_OMIT_DISPLAY_FIELDS:
228                form_fields = form_fields.omit(field)
229        elif self.target is not None and self.target.startswith('ase'): # was putme
230            form_fields = grok.AutoFields(ICustomUGApplicant)
231            for field in PUTME_OMIT_DISPLAY_FIELDS:
232                form_fields = form_fields.omit(field)
233        elif self.target is not None and self.target.startswith('pude'):
234            form_fields = grok.AutoFields(ICustomUGApplicant)
235            for field in PUDE_OMIT_DISPLAY_FIELDS:
236                form_fields = form_fields.omit(field)
237        else:
238            form_fields = grok.AutoFields(ICustomUGApplicant)
239            for field in UG_OMIT_DISPLAY_FIELDS:
240                form_fields = form_fields.omit(field)
241        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
242        form_fields['notice'].custom_widget = BytesDisplayWidget
243        if not getattr(self.context, 'student_id'):
244            form_fields = form_fields.omit('student_id')
245        if not getattr(self.context, 'screening_score'):
246            form_fields = form_fields.omit('screening_score')
247        if not getattr(self.context, 'screening_venue') or self._not_paid():
248            form_fields = form_fields.omit('screening_venue')
249        if not getattr(self.context, 'screening_date') or self._not_paid():
250            form_fields = form_fields.omit('screening_date')
251        if not self.context.admchecking_fee_paid():
252            form_fields = form_fields.omit(
253                'screening_score', 'aggregate', 'student_id')
254        return form_fields
255
256    @property
257    def display_actions(self):
258        state = IWorkflowState(self.context).getState()
259        actions = []
260        if state == ADMITTED and not self.context.admchecking_fee_paid():
261            actions = [_('Add admission checking payment ticket')]
262        return actions
263
264
265    def getCourseAdmitted(self):
266        """Return link, title and code in html format to the certificate
267           admitted.
268        """
269        course_admitted = self.context.course_admitted
270        if getattr(course_admitted, '__parent__',None) and \
271            self.context.admchecking_fee_paid():
272            url = self.url(course_admitted)
273            title = course_admitted.title
274            code = course_admitted.code
275            return '<a href="%s">%s - %s</a>' %(url,code,title)
276        return ''
277
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 '
283                     'to view your screening results and course admitted.')
284        return
285
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
291class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
292    """ Page to add an online payment ticket
293    """
294
295    @property
296    def custom_requirements(self):
297        store = getUtility(IExtFileStore)
298        if not store.getFileByContext(self.context, attr=u'passport.jpg'):
299            return _('Upload your 1"x1" Red background passport photo before making payment.')
300        return ''
301
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
328    def update(self):
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
335        payment = createObject(self.factory)
336        failure = self._setPaymentDetails(payment)
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
345
346    def render(self):
347        return
348
349
350class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
351
352    @property
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
359    def custom_upload_requirements(self):
360        if not checkPermission('waeup.uploadPassportPictures', self.context):
361            return _('You are not entitled to upload passport pictures.')
362
363    @property
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
372    def form_fields(self):
373        if self.target == 'ictwk':
374            form_fields = grok.AutoFields(IUnibenRegistration)
375            for field in REGISTRATION_OMIT_MANAGE_FIELDS:
376                form_fields = form_fields.omit(field)
377            state = IWorkflowState(self.context).getState()
378            if state != STARTED:
379                form_fields['registration_cats'].for_display = True
380            return form_fields
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
415        return form_fields
416
417
418class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
419    """An applicant-centered edit view for applicant data.
420    """
421
422    @property
423    def display_payments(self):
424        if self.context.special or self.target == 'ictwk':
425            return True
426        return getattr(self.context.__parent__, 'application_fee', None)
427
428    @property
429    def form_fields(self):
430        if self.target == 'ictwk':
431            form_fields = grok.AutoFields(IUnibenRegistration)
432            for field in REGISTRATION_OMIT_EDIT_FIELDS:
433                form_fields = form_fields.omit(field)
434            state = IWorkflowState(self.context).getState()
435            if state != STARTED:
436                form_fields['registration_cats'].for_display = True
437            return form_fields
438        if self.target is not None and self.target.startswith('pg'):
439            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
440            for field in PG_OMIT_EDIT_FIELDS:
441                form_fields = form_fields.omit(field)
442        elif self.target is not None and self.target.startswith('pre'):
443            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
444            for field in PRE_OMIT_EDIT_FIELDS:
445                form_fields = form_fields.omit(field)
446        elif self.target is not None and self.target.startswith('cbt'):
447            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
448            for field in CBT_OMIT_EDIT_FIELDS:
449                form_fields = form_fields.omit(field)
450        elif self.target is not None and self.target.startswith('akj'):
451            form_fields = grok.AutoFields(ICustomPGApplicant)
452            for field in PRE_OMIT_EDIT_FIELDS:
453                form_fields = form_fields.omit(field)
454        elif self.target is not None and self.target.startswith('ak'):
455            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
456            for field in AFFIL_OMIT_EDIT_FIELDS:
457                form_fields = form_fields.omit(field)
458        elif self.target is not None and self.target.startswith('ase'): # was putme
459            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
460            for field in PUTME_OMIT_EDIT_FIELDS:
461                form_fields = form_fields.omit(field)
462        elif self.target is not None and self.target.startswith('pude'):
463            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
464            for field in PUDE_OMIT_EDIT_FIELDS:
465                form_fields = form_fields.omit(field)
466        else:
467            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
468            for field in UG_OMIT_EDIT_FIELDS:
469                form_fields = form_fields.omit(field)
470        form_fields['applicant_id'].for_display = True
471        form_fields['reg_number'].for_display = True
472        return form_fields
473
474    @property
475    def label(self):
476        if self.target == 'ictwk':
477            container_title = self.context.__parent__.title
478            return _('${a} <br /> Registration Record ${b}', mapping = {
479                'a':container_title, 'b':self.context.application_number})
480        return super(CustomApplicantEditFormPage, self).label
481
482class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage):
483    """ Approval view
484    """
485
486    def update(self):
487        if self.context.p_category == 'admission_checking':
488            if self.context.p_state == 'paid':
489                flashtype = 'warning'
490                msg = _('This ticket has already been paid.')
491                log = None
492            else:
493                self.context.approve()
494                log = 'payment approved: %s' % self.context.p_id
495                msg = _('Payment approved')
496                flashtype = 'success'
497        else:
498            flashtype, msg, log = self.context.approveApplicantPayment()
499        if log is not None:
500            applicant = self.context.__parent__
501            # Add log message to applicants.log
502            applicant.writeLogMessage(self, log)
503            # Add log message to payments.log
504            self.context.logger.info(
505                '%s,%s,%s,%s,%s,,,,,,' % (
506                applicant.applicant_id,
507                self.context.p_id, self.context.p_category,
508                self.context.amount_auth, self.context.r_code))
509        self.flash(msg, type=flashtype)
510        return
511
512class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
513    """Deliver a PDF slip of the context.
514    """
515
516    def update(self):
517        super(CustomExportPDFPageApplicationSlip, self).update()
518        if self.context.state == ADMITTED and \
519            not self.context.admchecking_fee_paid():
520            self.flash(
521                _('Please pay admission checking fee before trying to download '
522                  'the application slip.'), type='warning')
523            return self.redirect(self.url(self.context))
524        return
525
526class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
527
528    def _getPDFCreator(self):
529        if self.target.startswith('ak'):
530            return getUtility(IPDFCreator, name='akoka_pdfcreator')
531        return getUtility(IPDFCreator)
532
533    @property
534    def form_fields(self):
535        if self.target == 'ictwk':
536            form_fields = grok.AutoFields(IUnibenRegistration)
537            for field in REGISTRATION_OMIT_PDF_FIELDS:
538                form_fields = form_fields.omit(field)
539            return form_fields
540        if self.target is not None and self.target.startswith('pg'):
541            form_fields = grok.AutoFields(ICustomPGApplicant)
542            for field in PG_OMIT_PDF_FIELDS:
543                form_fields = form_fields.omit(field)
544        elif self.target is not None and self.target.startswith('pre'):
545            form_fields = grok.AutoFields(ICustomPGApplicant)
546            for field in PRE_OMIT_PDF_FIELDS:
547                form_fields = form_fields.omit(field)
548        elif self.target is not None and self.target.startswith('cbt'): # uniben
549            form_fields = grok.AutoFields(ICustomUGApplicant)
550            for field in CBT_OMIT_PDF_FIELDS:
551                form_fields = form_fields.omit(field)
552        elif self.target is not None and self.target.startswith('akj'): # uniben
553            form_fields = grok.AutoFields(ICustomPGApplicant)
554            for field in PRE_OMIT_PDF_FIELDS:
555                form_fields = form_fields.omit(field)
556        elif self.target is not None and self.target.startswith('ak'): # uniben
557            form_fields = grok.AutoFields(ICustomUGApplicant)
558            for field in AFFIL_OMIT_PDF_FIELDS:
559                form_fields = form_fields.omit(field)
560        elif self.target is not None and self.target.startswith('ase'): # was putme
561            form_fields = grok.AutoFields(ICustomUGApplicant)
562            if self._reduced_slip():
563                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
564                    form_fields = form_fields.omit(field)
565            else:
566                for field in PUTME_OMIT_PDF_FIELDS:
567                    form_fields = form_fields.omit(field)
568        elif self.target is not None and self.target.startswith('pude'):
569            form_fields = grok.AutoFields(ICustomUGApplicant)
570            if self._reduced_slip():
571                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
572                    form_fields = form_fields.omit(field)
573            else:
574                for field in PUDE_OMIT_PDF_FIELDS:
575                    form_fields = form_fields.omit(field)
576        else:
577            form_fields = grok.AutoFields(ICustomUGApplicant)
578            for field in UG_OMIT_PDF_FIELDS:
579                form_fields = form_fields.omit(field)
580        if not getattr(self.context, 'student_id'):
581            form_fields = form_fields.omit('student_id')
582        if not getattr(self.context, 'screening_score'):
583            form_fields = form_fields.omit('screening_score')
584        if not getattr(self.context, 'screening_venue'):
585            form_fields = form_fields.omit('screening_venue')
586        if not getattr(self.context, 'screening_date'):
587            form_fields = form_fields.omit('screening_date')
588        return form_fields
589
590    @property
591    def title(self):
592        container_title = self.context.__parent__.title
593        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
594        ar_translation = translate(_('Application Record'),
595            'waeup.kofa', target_language=portal_language)
596        if self.target == 'ictwk':
597            return '%s - Registration Record %s' % (container_title,
598            self.context.application_number)
599        elif self.target.startswith('ab'):
600            return 'Federal College of Education (Technical) Asaba - %s %s %s' % (
601                container_title, ar_translation,
602                self.context.application_number)
603        elif self.target.startswith('ak'):
604            return 'Federal College of Education (Technical) Akoka - %s - %s %s' % (
605                container_title, ar_translation,
606                self.context.application_number)
607        elif self.target == 'pgn':
608            return 'National Institute for Legislative Studies (NILS) - %s %s %s' % (
609                container_title, ar_translation,
610                self.context.application_number)
611        return '%s - %s %s' % (container_title,
612            ar_translation, self.context.application_number)
613
614class ExportScreeningInvitationSlip(UtilityView, grok.View):
615    """Deliver a PDF slip of the context.
616    """
617    grok.context(ICustomApplicant)
618    grok.name('screening_invitation_slip.pdf')
619    grok.require('waeup.viewApplication')
620    form_fields = None
621    label = u'Invitation Letter for Pre-Admission Screening'
622
623
624    @property
625    def note(self):
626        notice = getattr(self.context.__parent__, 'application_slip_notice', None)
627        if self.context.screening_date:
628            return """
629<br /><br /><br /><br /><font size='12'>
630Dear %s,
631<br /><br /><br />
632You are invited for your Uniben Admission Screening Exercise on:
633<br /><br />
634<strong>%s</strong>.
635<br /><br />
636Please bring along this letter of invitation to the
637<br /><br />
638<strong>%s</strong>
639<br /><br />
640on your screening date.
641<br /><br /><br />
642Signed,
643<br /><br />
644The Registrar<br />
645<br /><br />
646<br /><br />
647%s
648</font>
649
650""" % (self.context.display_fullname, self.context.screening_date,
651       self.context.screening_venue, notice)
652        return
653
654    def update(self):
655        if not self.context.screening_date:
656            self.flash(_('Forbidden'), type="warning")
657            self.redirect(self.url(self.context))
658
659    def render(self):
660        applicantview = ApplicantBaseDisplayFormPage(self.context, self.request)
661        students_utils = getUtility(IStudentsUtils)
662        return students_utils.renderPDF(self,'screening_invitation_slip.pdf',
663            self.context, applicantview, note=self.note)
Note: See TracBrowser for help on using the repository browser.