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

Last change on this file since 16924 was 16807, checked in by Henrik Bettermann, 3 years ago

Change flc application form.

  • Property svn:keywords set to Id
File size: 35.8 KB
Line 
1## $Id: browser.py 16807 2022-02-15 17:42:22Z 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,
36    AdditionalFile,)
37from waeup.kofa.students.interfaces import IStudentsUtils
38from waeup.kofa.applicants.interfaces import (
39    ISpecialApplicant, IApplicantsUtils)
40from waeup.kofa.browser.interfaces import IPDFCreator
41from kofacustom.nigeria.applicants.browser import (
42    NigeriaApplicantDisplayFormPage,
43    NigeriaApplicantManageFormPage,
44    NigeriaApplicantEditFormPage,
45    NigeriaPDFApplicationSlip,
46    NigeriaExportPDFPaymentSlipPage)
47from waeup.uniben.applicants.interfaces import (
48    ICustomApplicant,
49    IUnibenRegistration,
50    ICustomUGApplicant,
51    ICustomPGApplicant,
52    ICustomPGApplicantEdit,
53    ICustomUGApplicantEdit,
54    IPUTMEApplicantEdit,
55    ITranscriptApplicant,
56    IFrenchApplicant)
57from waeup.kofa.applicants.workflow import ADMITTED, PAID, STARTED
58from kofacustom.nigeria.applicants.interfaces import (
59    UG_OMIT_DISPLAY_FIELDS,
60    UG_OMIT_PDF_FIELDS,
61    UG_OMIT_MANAGE_FIELDS,
62    UG_OMIT_EDIT_FIELDS,
63    CBT_OMIT_DISPLAY_FIELDS,
64    CBT_OMIT_PDF_FIELDS,
65    CBT_OMIT_MANAGE_FIELDS,
66    CBT_OMIT_EDIT_FIELDS,
67    AFFIL_OMIT_DISPLAY_FIELDS,
68    AFFIL_OMIT_PDF_FIELDS,
69    AFFIL_OMIT_MANAGE_FIELDS,
70    AFFIL_OMIT_EDIT_FIELDS,
71    PG_OMIT_DISPLAY_FIELDS,
72    PG_OMIT_PDF_FIELDS,
73    PG_OMIT_MANAGE_FIELDS,
74    PG_OMIT_EDIT_FIELDS,
75    PUTME_OMIT_DISPLAY_FIELDS,
76    PUTME_OMIT_PDF_FIELDS,
77    PUTME_OMIT_MANAGE_FIELDS,
78    PUTME_OMIT_EDIT_FIELDS,
79    PUTME_OMIT_RESULT_SLIP_FIELDS,
80    PUDE_OMIT_DISPLAY_FIELDS,
81    PUDE_OMIT_PDF_FIELDS,
82    PUDE_OMIT_MANAGE_FIELDS,
83    PUDE_OMIT_EDIT_FIELDS,
84    PUDE_OMIT_RESULT_SLIP_FIELDS,
85    PRE_OMIT_DISPLAY_FIELDS,
86    PRE_OMIT_PDF_FIELDS,
87    PRE_OMIT_MANAGE_FIELDS,
88    PRE_OMIT_EDIT_FIELDS,
89    )
90
91from waeup.uniben.interfaces import MessageFactory as _
92
93PASTQ_ALL = ['ADT','CIT','DEF','DEM','EPCS','ESM','HEK','HSE','VTE']
94
95PASTQ_AL = ['ENL','FAA','FOL','HIS','LAL', 'PHL','THR','BUL','JIL',
96            'LAW','PPL','PUL'] + PASTQ_ALL
97
98PASTQ_BS = ['ANT','ANY','CHH','COH','HAE','MED','MEH','PHS','SUR',
99            'PCG','PCH','PCO', 'PCT','PHA','PHM','PMB','ANA','MBC',
100            'MLS','NSC','PSY','DPV','ODR','OSP','PER', 'RES','AEB',
101            'BCH','BOT','CED','EVL','MCB','OPT','PBB','SLT','ZOO',
102            'AEE','ANS', 'CRS','FIS','FOW','SOS'] + PASTQ_ALL
103
104PASTQ_EPS = ['ARC','CHE','CVE','DMIC','EEE','GEM','MCH','PEE','PRE','CHM',
105             'CSC','GLY','MTH','QSV','PHY','CPE','STR'] + PASTQ_ALL
106
107PASTQ_MSS = ['ACC','BNK','BUS','ECO','ESM','GEO','POL','SAA','SWK',
108             'ACT','ENT','HRM','INS','MKT'] + PASTQ_ALL
109
110REGISTRATION_OMIT_DISPLAY_FIELDS = (
111    'locked',
112    'suspended',
113    )
114
115REGISTRATION_OMIT_EDIT_FIELDS = (
116    'locked',
117    'suspended',
118    'applicant_id',
119    )
120
121REGISTRATION_OMIT_MANAGE_FIELDS = (
122    'applicant_id',
123    )
124
125
126REGISTRATION_OMIT_PDF_FIELDS = (
127    'locked',
128    'suspended',
129    )
130
131PUTME_OMIT_PDF_FIELDS = PUTME_OMIT_PDF_FIELDS + (
132    'fst_sit_results', 'scd_sit_results')
133
134TRANS_OMIT_FIELDS = ('suspended',)
135
136#TRANS_SHORT_OMIT_FIELDS = TRANS_OMIT_FIELDS + (
137#    'date_of_birth',
138#    'sex',
139#    #'nationality',
140#    'entry_mode',
141#    'entry_session',
142#    'end_session',
143#    'course_studied',
144#    'course_changed',
145#    #'change_level',
146#    )
147
148TRANS_SHORT_OMIT_FIELDS = TRANS_OMIT_FIELDS
149
150TRANS_OMIT_EDIT_FIELDS = TRANS_OMIT_FIELDS + ('applicant_id', )
151
152TRANS_SHORT_OMIT_EDIT_FIELDS = TRANS_SHORT_OMIT_FIELDS + ('applicant_id', )
153
154TRANS_OMIT_PDF_FIELDS = TRANS_OMIT_FIELDS + ('locked', )
155
156TRANS_SHORT_OMIT_PDF_FIELDS = TRANS_SHORT_OMIT_FIELDS + ('locked', )
157
158class CustomApplicantsContainerPage(ApplicantsContainerPage):
159    """The standard view for regular applicant containers.
160    """
161
162    @property
163    def form_fields(self):
164        form_fields = super(CustomApplicantsContainerPage, self).form_fields
165        usertype = getattr(self.request.principal, 'user_type', None)
166        if self.request.principal.id == 'zope.anybody' or  \
167            usertype in ('applicant', 'student'):
168            return form_fields.omit('application_fee')
169        return form_fields
170
171class CustomApplicantRegistrationPage(ApplicantRegistrationPage):
172    """Captcha'd registration page for applicants.
173    """
174
175    def _redirect(self, email, password, applicant_id):
176        # Forward email and credentials to landing page.
177        self.redirect(self.url(self.context, 'registration_complete',
178            data = dict(email=email, password=password,
179            applicant_id=applicant_id)))
180        return
181
182    @property
183    def label(self):
184        if self.context.prefix.startswith('tsc'):
185            return _('Request for ${a}',
186                mapping = {'a':self.context.title})
187        return _('Apply for ${a}',
188            mapping = {'a':self.context.title})
189
190class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
191    """A display view for applicant data.
192    """
193    grok.template('applicantdisplaypage')
194
195    @property
196    def display_payments(self):
197        if self.context.special or self.target == 'ictwk':
198            return True
199        return getattr(self.context.__parent__, 'application_fee', None)
200
201    def _show_pastq_putme(self):
202        return self.target.startswith('pre') \
203               and self.context.state in ('paid', 'submitted') \
204               and getattr(self.context, 'course1') is not None
205        # return False
206
207    @property
208    def depcode(self):
209        try:
210            code = self.context.course1.__parent__.__parent__.code
211            return code
212        except:
213            return
214
215    @property
216    def show_pastq_al(self):
217        return self._show_pastq_putme() # and self.depcode in PASTQ_AL
218
219    @property
220    def show_pastq_bs(self):
221        return self._show_pastq_putme() # and self.depcode in PASTQ_BS
222
223    @property
224    def show_pastq_eps(self):
225        return self._show_pastq_putme() # and self.depcode in PASTQ_EPS
226
227    @property
228    def show_pastq_mss(self):
229        return self._show_pastq_putme() # and self.depcode in PASTQ_MSS
230
231    @property
232    def show_pastq_pude(self):
233        return self.target.startswith('pude') \
234               and self.context.state in ('paid', 'submitted')
235
236    @property
237    def label(self):
238        if self.target == 'ictwk':
239            container_title = self.context.__parent__.title
240            return _('${a} <br /> Registration Record ${b}', mapping = {
241                'a':container_title, 'b':self.context.application_number})
242        return super(CustomApplicantDisplayFormPage, self).label
243
244    @property
245    def form_fields(self):
246        if self.target is not None and self.target == 'tscf':
247            form_fields = grok.AutoFields(ITranscriptApplicant)
248            for field in TRANS_OMIT_FIELDS:
249                form_fields = form_fields.omit(field)
250            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
251            #form_fields['perm_address'].custom_widget = BytesDisplayWidget
252            return form_fields
253        if self.target is not None and self.target == 'tscs':
254            form_fields = grok.AutoFields(ITranscriptApplicant)
255            for field in TRANS_SHORT_OMIT_FIELDS:
256                form_fields = form_fields.omit(field)
257            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
258            #form_fields['perm_address'].custom_widget = BytesDisplayWidget
259            return form_fields
260        if self.target is not None and self.target == 'flc':
261            form_fields = grok.AutoFields(IFrenchApplicant)
262            for field in REGISTRATION_OMIT_DISPLAY_FIELDS:
263                form_fields = form_fields.omit(field)
264            return form_fields
265        if self.target == 'ictwk':
266            form_fields = grok.AutoFields(IUnibenRegistration)
267            for field in REGISTRATION_OMIT_DISPLAY_FIELDS:
268                form_fields = form_fields.omit(field)
269            return form_fields
270        elif self.target is not None and self.target.startswith('pg'):
271            form_fields = grok.AutoFields(ICustomPGApplicant)
272            for field in PG_OMIT_DISPLAY_FIELDS:
273                form_fields = form_fields.omit(field)
274        elif self.target is not None and self.target.startswith('pre'):
275            form_fields = grok.AutoFields(ICustomPGApplicant)
276            for field in PRE_OMIT_DISPLAY_FIELDS:
277                form_fields = form_fields.omit(field)
278        elif self.target is not None and self.target.startswith('cbt'):
279            form_fields = grok.AutoFields(ICustomUGApplicant)
280            for field in CBT_OMIT_DISPLAY_FIELDS:
281                form_fields = form_fields.omit(field)
282        elif self.target is not None and self.target.startswith('akj'):
283            form_fields = grok.AutoFields(ICustomPGApplicant)
284            for field in PRE_OMIT_DISPLAY_FIELDS:
285                form_fields = form_fields.omit(field)
286        elif self.target is not None and self.target.startswith('ak'):
287            form_fields = grok.AutoFields(ICustomUGApplicant)
288            for field in AFFIL_OMIT_DISPLAY_FIELDS:
289                form_fields = form_fields.omit(field)
290        elif self.target is not None and self.target.startswith('ase'): # was putme
291            form_fields = grok.AutoFields(ICustomUGApplicant)
292            for field in PUTME_OMIT_DISPLAY_FIELDS:
293                form_fields = form_fields.omit(field)
294        elif self.target is not None and self.target.startswith('pude'):
295            form_fields = grok.AutoFields(ICustomUGApplicant)
296            for field in PUDE_OMIT_DISPLAY_FIELDS:
297                form_fields = form_fields.omit(field)
298        else:
299            form_fields = grok.AutoFields(ICustomUGApplicant)
300            for field in UG_OMIT_DISPLAY_FIELDS:
301                form_fields = form_fields.omit(field)
302        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
303        form_fields['notice'].custom_widget = BytesDisplayWidget
304        if not getattr(self.context, 'student_id'):
305            form_fields = form_fields.omit('student_id')
306        if not getattr(self.context, 'screening_score'):
307            form_fields = form_fields.omit('screening_score')
308        if not getattr(self.context, 'screening_venue') or self._not_paid():
309            form_fields = form_fields.omit('screening_venue')
310        if not getattr(self.context, 'screening_date') or self._not_paid():
311            form_fields = form_fields.omit('screening_date')
312        if not self.context.admchecking_fee_paid():
313            form_fields = form_fields.omit(
314                'screening_score', 'aggregate', 'student_id')
315        return form_fields
316
317    @property
318    def display_actions(self):
319        state = IWorkflowState(self.context).getState()
320        actions = []
321        if state == ADMITTED and not self.context.admchecking_fee_paid():
322            actions = [_('Add admission checking payment ticket')]
323        return actions
324
325
326    def getCourseAdmitted(self):
327        """Return link, title and code in html format to the certificate
328           admitted.
329        """
330        if self.admission_checking_info:
331            return '<span class="hint">%s</span>' % self.admission_checking_info
332        return super(CustomApplicantDisplayFormPage, self).getCourseAdmitted()
333
334    @property
335    def admission_checking_info(self):
336        if self.context.state == ADMITTED and \
337            not self.context.admchecking_fee_paid():
338            return _('You must pay the admission checking fee '
339                     'to view your screening results and your course admitted.')
340        return
341
342    @action(_('Add admission checking payment ticket'), style='primary')
343    def addPaymentTicket(self, **data):
344        self.redirect(self.url(self.context, '@@addacp'))
345        return
346
347class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
348    """ Page to add an online payment ticket
349    """
350
351    @property
352    def custom_requirements(self):
353        if self.context.__parent__.with_picture:
354            store = getUtility(IExtFileStore)
355            if self.context.__parent__.picture_editable \
356                and not store.getFileByContext(self.context, attr=u'passport.jpg'):
357                return _('Upload your 1"x1" Red background passport photo before making payment.')
358        return ''
359
360class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View):
361    """ Page to add an admission checking online payment ticket.
362    """
363    grok.context(ICustomApplicant)
364    grok.name('addacp')
365    grok.require('waeup.payApplicant')
366    factory = u'waeup.ApplicantOnlinePayment'
367
368    def _setPaymentDetails(self, payment):
369        container = self.context.__parent__
370        timestamp = ("%d" % int(time()*10000))[1:]
371        session = str(container.year)
372        try:
373            session_config = grok.getSite()['configuration'][session]
374        except KeyError:
375            return _(u'Session configuration object is not available.'), None
376        payment.p_id = "p%s" % timestamp
377        payment.p_item = container.title
378        payment.p_session = container.year
379        payment.amount_auth = 0.0
380        payment.p_category = 'admission_checking'
381        payment.amount_auth = session_config.admchecking_fee
382        if payment.amount_auth in (0.0, None):
383            return _('Amount could not be determined.'), None
384        return
385
386    def update(self):
387        if self.context.admchecking_fee_paid():
388              self.flash(
389                  _('Admission checking payment has already been made.'),
390                  type='warning')
391              self.redirect(self.url(self.context))
392              return
393        payment = createObject(self.factory)
394        failure = self._setPaymentDetails(payment)
395        if failure is not None:
396            self.flash(failure[0], type='danger')
397            self.redirect(self.url(self.context))
398            return
399        self.context[payment.p_id] = payment
400        self.flash(_('Payment ticket created.'))
401        self.redirect(self.url(payment))
402        return
403
404    def render(self):
405        return
406
407
408class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
409
410    @property
411    def display_payments(self):
412        if self.context.special or self.target == 'ictwk':
413            return True
414        return getattr(self.context.__parent__, 'application_fee', None)
415
416    @property
417    def custom_upload_requirements(self):
418        if not checkPermission('waeup.uploadPassportPictures', self.context):
419            return _('You are not entitled to upload passport pictures.')
420
421    def display_fileupload(self, filename):
422        if filename[1] == 'res_stat' \
423            and self.target is not None \
424            and not self.target.startswith('tsc'):
425            return False
426        if filename[1] == 'eligibility' \
427            and self.target is not None \
428            and not self.target.startswith('tsc'):
429            return False
430        return True
431
432    @property
433    def label(self):
434        if self.target == 'ictwk':
435            container_title = self.context.__parent__.title
436            return _('${a} <br /> Registration Record ${b}', mapping = {
437                'a':container_title, 'b':self.context.application_number})
438        return super(CustomApplicantManageFormPage, self).label
439
440    @property
441    def form_fields(self):
442        if self.target is not None and self.target == 'tscf':
443            form_fields = grok.AutoFields(ITranscriptApplicant)
444            for field in TRANS_OMIT_EDIT_FIELDS:
445                form_fields = form_fields.omit(field)
446            return form_fields
447        if self.target is not None and self.target == 'tscs':
448            form_fields = grok.AutoFields(ITranscriptApplicant)
449            for field in TRANS_SHORT_OMIT_EDIT_FIELDS:
450                form_fields = form_fields.omit(field)
451            return form_fields
452        if self.target == 'ictwk':
453            form_fields = grok.AutoFields(IUnibenRegistration)
454            for field in REGISTRATION_OMIT_MANAGE_FIELDS:
455                form_fields = form_fields.omit(field)
456            state = IWorkflowState(self.context).getState()
457            if state != STARTED:
458                form_fields['registration_cats'].for_display = True
459            return form_fields
460        if self.target is not None and self.target == 'flc':
461            form_fields = grok.AutoFields(IFrenchApplicant)
462            for field in REGISTRATION_OMIT_MANAGE_FIELDS:
463                form_fields = form_fields.omit(field)
464            return form_fields
465        if self.target is not None and self.target.startswith('pg'):
466            form_fields = grok.AutoFields(ICustomPGApplicant)
467            for field in PG_OMIT_MANAGE_FIELDS:
468                form_fields = form_fields.omit(field)
469        elif self.target is not None and self.target.startswith('pre'):
470            form_fields = grok.AutoFields(ICustomPGApplicant)
471            for field in PRE_OMIT_MANAGE_FIELDS:
472                form_fields = form_fields.omit(field)
473        elif self.target is not None and self.target.startswith('cbt'):
474            form_fields = grok.AutoFields(ICustomUGApplicant)
475            for field in CBT_OMIT_MANAGE_FIELDS:
476                form_fields = form_fields.omit(field)
477        elif self.target is not None and self.target.startswith('akj'):
478            form_fields = grok.AutoFields(ICustomPGApplicant)
479            for field in PRE_OMIT_MANAGE_FIELDS:
480                form_fields = form_fields.omit(field)
481        elif self.target is not None and self.target.startswith('ak'):
482            form_fields = grok.AutoFields(ICustomUGApplicant)
483            for field in AFFIL_OMIT_MANAGE_FIELDS:
484                form_fields = form_fields.omit(field)
485        elif self.target is not None and self.target.startswith('ase'): # was putme
486            form_fields = grok.AutoFields(ICustomUGApplicant)
487            for field in PUTME_OMIT_MANAGE_FIELDS:
488                form_fields = form_fields.omit(field)
489        elif self.target is not None and self.target.startswith('pude'):
490            form_fields = grok.AutoFields(ICustomUGApplicant)
491            for field in PUDE_OMIT_MANAGE_FIELDS:
492                form_fields = form_fields.omit(field)
493        else:
494            form_fields = grok.AutoFields(ICustomUGApplicant)
495            for field in UG_OMIT_MANAGE_FIELDS:
496                form_fields = form_fields.omit(field)
497        form_fields['student_id'].for_display = True
498        form_fields['applicant_id'].for_display = True
499        return form_fields
500
501
502class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
503    """An applicant-centered edit view for applicant data.
504    """
505
506    def unremovable(self, ticket):
507        return True
508
509    @property
510    def display_payments(self):
511        if self.context.special or self.target == 'ictwk':
512            return True
513        return getattr(self.context.__parent__, 'application_fee', None)
514
515    @property
516    def form_fields(self):
517        state = IWorkflowState(self.context).getState()
518        if self.target is not None and self.target == 'tscf':
519            form_fields = grok.AutoFields(ITranscriptApplicant)
520            form_fields['courier_tno'].for_display = True
521            form_fields['proc_date'].for_display = True
522            for field in TRANS_OMIT_EDIT_FIELDS:
523                form_fields = form_fields.omit(field)
524            if state == PAID:
525                form_fields['order'].for_display = True
526            form_fields = form_fields.omit('locked')
527            return form_fields
528        if self.target is not None and self.target == 'tscs':
529            form_fields = grok.AutoFields(ITranscriptApplicant)
530            form_fields['courier_tno'].for_display = True
531            form_fields['proc_date'].for_display = True
532            for field in TRANS_SHORT_OMIT_EDIT_FIELDS:
533                form_fields = form_fields.omit(field)
534            form_fields = form_fields.omit('locked')
535            if state == PAID:
536                form_fields['order'].for_display = True
537            return form_fields
538        if self.target == 'ictwk':
539            form_fields = grok.AutoFields(IUnibenRegistration)
540            for field in REGISTRATION_OMIT_EDIT_FIELDS:
541                form_fields = form_fields.omit(field)
542            if state != STARTED:
543                form_fields['registration_cats'].for_display = True
544            return form_fields
545        if self.target is not None and self.target == 'flc':
546            form_fields = grok.AutoFields(IFrenchApplicant)
547            for field in REGISTRATION_OMIT_EDIT_FIELDS:
548                form_fields = form_fields.omit(field)
549            return form_fields
550        if self.target is not None and self.target.startswith('pg'):
551            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
552            for field in PG_OMIT_EDIT_FIELDS:
553                form_fields = form_fields.omit(field)
554        elif self.target is not None and self.target.startswith('pre'):
555            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
556            for field in PRE_OMIT_EDIT_FIELDS:
557                form_fields = form_fields.omit(field)
558        elif self.target is not None and self.target.startswith('cbt'):
559            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
560            for field in CBT_OMIT_EDIT_FIELDS:
561                form_fields = form_fields.omit(field)
562        elif self.target is not None and self.target.startswith('akj'):
563            form_fields = grok.AutoFields(ICustomPGApplicant)
564            for field in PRE_OMIT_EDIT_FIELDS:
565                form_fields = form_fields.omit(field)
566        elif self.target is not None and self.target.startswith('ak'):
567            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
568            for field in AFFIL_OMIT_EDIT_FIELDS:
569                form_fields = form_fields.omit(field)
570        elif self.target is not None and self.target.startswith('ase'): # was putme
571            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
572            for field in PUTME_OMIT_EDIT_FIELDS:
573                form_fields = form_fields.omit(field)
574        elif self.target is not None and self.target.startswith('pude'):
575            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
576            for field in PUDE_OMIT_EDIT_FIELDS:
577                form_fields = form_fields.omit(field)
578        else:
579            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
580            for field in UG_OMIT_EDIT_FIELDS:
581                form_fields = form_fields.omit(field)
582        form_fields['applicant_id'].for_display = True
583        form_fields['reg_number'].for_display = True
584        return form_fields
585
586    @property
587    def label(self):
588        if self.target == 'ictwk':
589            container_title = self.context.__parent__.title
590            return _('${a} <br /> Registration Record ${b}', mapping = {
591                'a':container_title, 'b':self.context.application_number})
592        return super(CustomApplicantEditFormPage, self).label
593
594    def display_fileupload(self, filename):
595        if filename[1] == 'res_stat' \
596            and self.target is not None \
597            and not self.target.startswith('tsc'):
598            return False
599        if filename[1] == 'eligibility' \
600            and self.target is not None \
601            and not self.target.startswith('tsc'):
602            return False
603        return True
604
605    def dataNotComplete(self, data):
606        store = getUtility(IExtFileStore)
607        if self.context.__parent__.with_picture \
608            and self.context.__parent__.picture_editable:
609            store = getUtility(IExtFileStore)
610            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
611                return _('No passport picture uploaded.')
612        if self.target is not None \
613            and self.target.startswith('tscf') \
614            and not store.getFileByContext(self.context, attr=u'res_stat.pdf'):
615            return _('No statement of result pdf file uploaded.')
616        #if self.target is not None \
617        #    and self.target.startswith('tsc') \
618        #    and not store.getFileByContext(self.context, attr=u'eligibility.pdf'):
619        #    return _('No eligibility form pdf file uploaded.')
620        return False
621
622class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage):
623    """ Approval view
624    """
625
626    def update(self):
627        if self.context.p_category == 'admission_checking':
628            if self.context.p_state == 'paid':
629                flashtype = 'warning'
630                msg = _('This ticket has already been paid.')
631                log = None
632            else:
633                self.context.approve()
634                log = 'payment approved: %s' % self.context.p_id
635                msg = _('Payment approved')
636                flashtype = 'success'
637        else:
638            flashtype, msg, log = self.context.approveApplicantPayment()
639        if log is not None:
640            applicant = self.context.__parent__
641            # Add log message to applicants.log
642            applicant.writeLogMessage(self, log)
643            # Add log message to payments.log
644            self.context.logger.info(
645                '%s,%s,%s,%s,%s,,,,,,' % (
646                applicant.applicant_id,
647                self.context.p_id, self.context.p_category,
648                self.context.amount_auth, self.context.r_code))
649        self.flash(msg, type=flashtype)
650        return
651
652class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
653    """Deliver a PDF slip of the context.
654    """
655
656    def update(self):
657        super(CustomExportPDFPageApplicationSlip, self).update()
658        if self.context.state == ADMITTED and \
659            not self.context.admchecking_fee_paid():
660            self.flash(
661                _('Please pay admission checking fee before trying to download '
662                  'the application slip.'), type='warning')
663            return self.redirect(self.url(self.context))
664        return
665
666class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
667
668    def _getPDFCreator(self):
669        if self.target.startswith('ak'):
670            return getUtility(IPDFCreator, name='akoka_pdfcreator')
671        return getUtility(IPDFCreator)
672
673    @property
674    def form_fields(self):
675        if self.target is not None and self.target == 'tscf':
676            form_fields = grok.AutoFields(ITranscriptApplicant)
677            for field in TRANS_OMIT_PDF_FIELDS:
678                form_fields = form_fields.omit(field)
679        elif self.target is not None and self.target == 'tscs':
680            form_fields = grok.AutoFields(ITranscriptApplicant)
681            for field in TRANS_SHORT_OMIT_PDF_FIELDS:
682                form_fields = form_fields.omit(field)
683        elif self.target is not None and self.target == 'ictwk':
684            form_fields = grok.AutoFields(IUnibenRegistration)
685            for field in REGISTRATION_OMIT_PDF_FIELDS:
686                form_fields = form_fields.omit(field)
687        elif self.target is not None and self.target.startswith('pg'):
688            form_fields = grok.AutoFields(ICustomPGApplicant)
689            for field in PG_OMIT_PDF_FIELDS:
690                form_fields = form_fields.omit(field)
691        elif self.target is not None and self.target.startswith('pre'):
692            form_fields = grok.AutoFields(ICustomPGApplicant)
693            for field in PRE_OMIT_PDF_FIELDS:
694                form_fields = form_fields.omit(field)
695        elif self.target is not None and self.target.startswith('cbt'): # uniben
696            form_fields = grok.AutoFields(ICustomUGApplicant)
697            for field in CBT_OMIT_PDF_FIELDS:
698                form_fields = form_fields.omit(field)
699        elif self.target is not None and self.target.startswith('akj'): # uniben
700            form_fields = grok.AutoFields(ICustomPGApplicant)
701            for field in PRE_OMIT_PDF_FIELDS:
702                form_fields = form_fields.omit(field)
703        elif self.target is not None and self.target.startswith('ak'): # uniben
704            form_fields = grok.AutoFields(ICustomUGApplicant)
705            for field in AFFIL_OMIT_PDF_FIELDS:
706                form_fields = form_fields.omit(field)
707        elif self.target is not None and self.target.startswith('ase'): # was putme
708            form_fields = grok.AutoFields(ICustomUGApplicant)
709            if self._reduced_slip():
710                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
711                    form_fields = form_fields.omit(field)
712            else:
713                for field in PUTME_OMIT_PDF_FIELDS:
714                    form_fields = form_fields.omit(field)
715        elif self.target is not None and self.target.startswith('pude'):
716            form_fields = grok.AutoFields(ICustomUGApplicant)
717            if self._reduced_slip():
718                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
719                    form_fields = form_fields.omit(field)
720            else:
721                for field in PUDE_OMIT_PDF_FIELDS:
722                    form_fields = form_fields.omit(field)
723        elif self.target is not None and self.target == 'flc':
724            form_fields = grok.AutoFields(IFrenchApplicant)
725            for field in REGISTRATION_OMIT_PDF_FIELDS:
726                form_fields = form_fields.omit(field)
727        else:
728            form_fields = grok.AutoFields(ICustomUGApplicant)
729            for field in UG_OMIT_PDF_FIELDS:
730                form_fields = form_fields.omit(field)
731        if not getattr(self.context, 'student_id'):
732            form_fields = form_fields.omit('student_id')
733        if not getattr(self.context, 'screening_score'):
734            form_fields = form_fields.omit('screening_score')
735        if not getattr(self.context, 'screening_venue'):
736            form_fields = form_fields.omit('screening_venue')
737        if not getattr(self.context, 'screening_date'):
738            form_fields = form_fields.omit('screening_date')
739        return form_fields
740
741    @property
742    def title(self):
743        container_title = self.context.__parent__.title
744        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
745        ar_translation = translate(_('Application Record'),
746            'waeup.kofa', target_language=portal_language)
747        if self.target == 'ictwk':
748            return '%s - Registration Record %s' % (container_title,
749            self.context.application_number)
750        elif self.target.startswith('ab'):
751            return 'Federal College of Education (Technical) Asaba - %s %s %s' % (
752                container_title, ar_translation,
753                self.context.application_number)
754        elif self.target.startswith('ak'):
755            return 'Federal College of Education (Technical) Akoka - %s - %s %s' % (
756                container_title, ar_translation,
757                self.context.application_number)
758        elif self.target == 'pgn':
759            return 'National Institute for Legislative Studies (NILS) - %s %s %s' % (
760                container_title, ar_translation,
761                self.context.application_number)
762        return '%s - %s %s' % (container_title,
763            ar_translation, self.context.application_number)
764
765class CustomApplicantBaseDisplayFormPage(ApplicantBaseDisplayFormPage):
766
767    @property
768    def form_fields(self):
769        target = getattr(self.context.__parent__, 'prefix', None)
770        if target.startswith('tsc'):
771            form_fields = grok.AutoFields(ICustomApplicant).select(
772                'applicant_id', 'email', 'dispatch_address')
773        else:
774            form_fields = grok.AutoFields(ICustomApplicant).select(
775                'applicant_id', 'reg_number', 'email', 'course1')
776        if self.context.__parent__.prefix in ('special',):
777            form_fields['reg_number'].field.title = u'Identification Number'
778            return form_fields
779        return form_fields
780
781class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
782    """Deliver a PDF slip of the context.
783    """
784
785    @property
786    def omit_fields(self):
787        target = getattr(self.context.__parent__.__parent__, 'prefix', None)
788        if target.startswith('tsc'):
789            return ('date_of_birth', 'course1')
790        return ()
791
792    @property
793    def note(self):
794        return
795
796    def render(self):
797        if self.payment_slip_download_warning:
798            self.flash(self.payment_slip_download_warning, type='danger')
799            self.redirect(self.url(self.context))
800            return
801        applicantview = CustomApplicantBaseDisplayFormPage(self.context.__parent__,
802            self.request)
803        students_utils = getUtility(IStudentsUtils)
804        return students_utils.renderPDF(self,'payment_slip.pdf',
805            self.context.__parent__, applicantview,
806            note=self.note, omit_fields=self.omit_fields)
807
808class ExportScreeningInvitationSlip(UtilityView, grok.View):
809    """Deliver a PDF slip of the context.
810    """
811    grok.context(ICustomApplicant)
812    grok.name('screening_invitation_slip.pdf')
813    grok.require('waeup.viewApplication')
814    form_fields = None
815    label = u'Invitation Letter for Pre-Admission Screening'
816
817
818    @property
819    def note(self):
820        notice = getattr(self.context.__parent__, 'application_slip_notice')
821        if notice is None:
822            notice = ''
823        if self.context.screening_date:
824            return """
825<br /><br /><br /><br /><font size='12'>
826Dear %s,
827<br /><br /><br />
828You are invited for your Uniben Admission Screening Exercise on:
829<br /><br />
830<strong>%s</strong>.
831<br /><br />
832Please bring along this letter of invitation to the
833<br /><br />
834<strong>%s</strong>
835<br /><br />
836on your screening date.
837<br /><br /><br />
838Signed,
839<br /><br />
840The Registrar<br />
841<br /><br />
842<br /><br />
843%s
844</font>
845
846""" % (self.context.display_fullname, self.context.screening_date,
847       self.context.screening_venue, notice)
848        return
849
850    def update(self):
851        if not self.context.screening_date:
852            self.flash(_('Forbidden'), type="warning")
853            self.redirect(self.url(self.context))
854
855    def render(self):
856        applicantview = ApplicantBaseDisplayFormPage(self.context, self.request)
857        students_utils = getUtility(IStudentsUtils)
858        return students_utils.renderPDF(self,'screening_invitation_slip.pdf',
859            self.context, applicantview, note=self.note)
860
861class CustomCheckTranscriptStatus(CheckTranscriptStatus):
862    """A display page for checking transcript processing status.
863    """
864    grok.template('checktranscriptstatus')
865
866    websites = (('Uniben Alumni Portal', 'https://alumni.uniben.edu/'),
867                ('Uniben Student Portal', 'https://waeup.uniben.edu/'),)
868    appl_url1 = 'https://alumni.uniben.edu/applicants/tscf1/register'
869    appl_url2 = 'https://alumni.uniben.edu/applicants/tscs1/register'
870
871class CreateGraduatedPage(UtilityView, grok.View):
872    """Create a student object from transcript application data.
873    """
874    grok.context(ICustomApplicant)
875    grok.name('creategraduated')
876    grok.require('waeup.createStudents')
877
878    def update(self):
879        success, msg = self.context.createStudent(view=self, graduated=True)
880        if success:
881            self.flash(msg)
882        else:
883            self.flash(msg, type='warning')
884        self.redirect(self.url(self.context))
885        return
886
887    def render(self):
888        return
889
890class ResultStatement(AdditionalFile):
891    grok.name('res_stat')
892
893class EligibilityForm(AdditionalFile):
894    grok.name('eligibility')
Note: See TracBrowser for help on using the repository browser.