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

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

Implement transcript applications.

  • Property svn:keywords set to Id
File size: 28.3 KB
Line 
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"""
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,
52    ITranscriptApplicant)
53from waeup.kofa.applicants.workflow import ADMITTED, PAID, STARTED
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    )
86
87from waeup.uniben.interfaces import MessageFactory as _
88
89PASTQ_ALL = ['ADT','CIT','DEF','DEM','EPCS','ESM','HEK','HSE','VTE']
90
91PASTQ_AL = ['ENL','FAA','FOL','HIS','LAL', 'PHL','THR','BUL','JIL',
92            'LAW','PPL','PUL'] + PASTQ_ALL
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
100PASTQ_EPS = ['ARC','CHE','CVE','DMIC','EEE','GEM','MCH','PEE','PRE','CHM',
101             'CSC','GLY','MTH','QSV','PHY','CPE','STR'] + PASTQ_ALL
102
103PASTQ_MSS = ['ACC','BNK','BUS','ECO','ESM','GEO','POL','SAA','SWK',
104             'ACT','ENT','HRM','INS','MKT'] + PASTQ_ALL
105
106REGISTRATION_OMIT_DISPLAY_FIELDS = (
107    'locked',
108    'suspended',
109    )
110
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    )
126
127PUTME_OMIT_PDF_FIELDS = PUTME_OMIT_PDF_FIELDS + (
128    'fst_sit_results', 'scd_sit_results')
129
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
137        usertype = getattr(self.request.principal, 'user_type', None)
138        if self.request.principal.id == 'zope.anybody' or  \
139            usertype in ('applicant', 'student'):
140            return form_fields.omit('application_fee')
141        return form_fields
142
143class CustomApplicantRegistrationPage(ApplicantRegistrationPage):
144    """Captcha'd registration page for applicants.
145    """
146
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
153
154class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
155    """A display view for applicant data.
156    """
157    grok.template('applicantdisplaypage')
158
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
165    def _show_pastq_putme(self):
166        return self.target.startswith('pre') \
167               and self.context.state in ('paid', 'submitted') \
168               and getattr(self.context, 'course1') is not None
169        # return False
170
171    @property
172    def depcode(self):
173        try:
174            code = self.context.course1.__parent__.__parent__.code
175            return code
176        except:
177            return
178
179    @property
180    def show_pastq_al(self):
181        return self._show_pastq_putme() # and self.depcode in PASTQ_AL
182
183    @property
184    def show_pastq_bs(self):
185        return self._show_pastq_putme() # and self.depcode in PASTQ_BS
186
187    @property
188    def show_pastq_eps(self):
189        return self._show_pastq_putme() # and self.depcode in PASTQ_EPS
190
191    @property
192    def show_pastq_mss(self):
193        return self._show_pastq_putme() # and self.depcode in PASTQ_MSS
194
195    @property
196    def show_pastq_pude(self):
197        return self.target.startswith('pude') \
198               and self.context.state in ('paid', 'submitted')
199
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
207
208    @property
209    def form_fields(self):
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
216        if self.target == 'ictwk':
217            form_fields = grok.AutoFields(IUnibenRegistration)
218            for field in REGISTRATION_OMIT_DISPLAY_FIELDS:
219                form_fields = form_fields.omit(field)
220            return form_fields
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')
263        if not self.context.admchecking_fee_paid():
264            form_fields = form_fields.omit(
265                'screening_score', 'aggregate', 'student_id')
266        return form_fields
267
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        """
281        if self.admission_checking_info:
282            return '<span class="hint">%s</span>' % self.admission_checking_info
283        return super(CustomApplicantDisplayFormPage, self).getCourseAdmitted()
284
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 '
290                     'to view your screening results and your course admitted.')
291        return
292
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
298class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
299    """ Page to add an online payment ticket
300    """
301
302    @property
303    def custom_requirements(self):
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.')
308        return ''
309
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
336    def update(self):
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
343        payment = createObject(self.factory)
344        failure = self._setPaymentDetails(payment)
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
353
354    def render(self):
355        return
356
357
358class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
359
360    @property
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
367    def custom_upload_requirements(self):
368        if not checkPermission('waeup.uploadPassportPictures', self.context):
369            return _('You are not entitled to upload passport pictures.')
370
371    @property
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
380    def form_fields(self):
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
385        if self.target == 'ictwk':
386            form_fields = grok.AutoFields(IUnibenRegistration)
387            for field in REGISTRATION_OMIT_MANAGE_FIELDS:
388                form_fields = form_fields.omit(field)
389            state = IWorkflowState(self.context).getState()
390            if state != STARTED:
391                form_fields['registration_cats'].for_display = True
392            return form_fields
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
427        return form_fields
428
429
430class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
431    """An applicant-centered edit view for applicant data.
432    """
433
434    def unremovable(self, ticket):
435        return True
436
437    @property
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
444    def form_fields(self):
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
462        if self.target == 'ictwk':
463            form_fields = grok.AutoFields(IUnibenRegistration)
464            for field in REGISTRATION_OMIT_EDIT_FIELDS:
465                form_fields = form_fields.omit(field)
466            state = IWorkflowState(self.context).getState()
467            if state != STARTED:
468                form_fields['registration_cats'].for_display = True
469            return form_fields
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
504        return form_fields
505
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
514class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage):
515    """ Approval view
516    """
517
518    def update(self):
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()
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
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
557
558class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
559
560    def _getPDFCreator(self):
561        if self.target.startswith('ak'):
562            return getUtility(IPDFCreator, name='akoka_pdfcreator')
563        return getUtility(IPDFCreator)
564
565    @property
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
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')
620        return form_fields
621
622    @property
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)
628        if self.target == 'ictwk':
629            return '%s - Registration Record %s' % (container_title,
630            self.context.application_number)
631        elif self.target.startswith('ab'):
632            return 'Federal College of Education (Technical) Asaba - %s %s %s' % (
633                container_title, ar_translation,
634                self.context.application_number)
635        elif self.target.startswith('ak'):
636            return 'Federal College of Education (Technical) Akoka - %s - %s %s' % (
637                container_title, ar_translation,
638                self.context.application_number)
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)
643        return '%s - %s %s' % (container_title,
644            ar_translation, self.context.application_number)
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
653    label = u'Invitation Letter for Pre-Admission Screening'
654
655
656    @property
657    def note(self):
658        notice = getattr(self.context.__parent__, 'application_slip_notice', None)
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 />
668Please bring along this letter of invitation to the
669<br /><br />
670<strong>%s</strong>
671<br /><br />
672on your screening date.
673<br /><br /><br />
674Signed,
675<br /><br />
676The Registrar<br />
677<br /><br />
678<br /><br />
679%s
680</font>
681
682""" % (self.context.display_fullname, self.context.screening_date,
683       self.context.screening_venue, notice)
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.