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

Last change on this file since 16281 was 16229, checked in by Henrik Bettermann, 4 years ago

Enable graduated student record creation from transcript application data.

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