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

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

Configure transcript applications.

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