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

Last change on this file since 13802 was 13796, checked in by Henrik Bettermann, 9 years ago

Add application type and customize pages for ICT Week Registration application.

  • Property svn:keywords set to Id
File size: 12.7 KB
RevLine 
[8012]1## $Id: browser.py 13796 2016-04-03 19:14: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"""
[10287]20import grok
[11784]21from time import time
[11782]22from zope.component import getUtility, createObject
[11736]23from zope.security import checkPermission
[13552]24from zope.i18n import translate
[11784]25from hurry.workflow.interfaces import IWorkflowState
26from waeup.kofa.browser.layout import action, UtilityView
[13552]27from waeup.kofa.interfaces import IExtFileStore, IKofaUtils
[10587]28from waeup.kofa.applicants.browser import (
[11728]29    ApplicantRegistrationPage, ApplicantsContainerPage,
[11782]30    ApplicationFeePaymentAddPage,
[11784]31    OnlinePaymentApprovePage,
32    ExportPDFPageApplicationSlip)
[11782]33from waeup.kofa.applicants.interfaces import (
34    ISpecialApplicant, IApplicantsUtils)
[13558]35from waeup.kofa.browser.interfaces import IPDFCreator
[10378]36from kofacustom.nigeria.applicants.browser import (
37    NigeriaApplicantDisplayFormPage,
[11736]38    NigeriaApplicantManageFormPage,
[13796]39    NigeriaApplicantEditFormPage,
[10378]40    NigeriaPDFApplicationSlip)
[11782]41from waeup.uniben.applicants.interfaces import (
42    ICustomApplicant)
[11784]43from waeup.kofa.applicants.workflow import ADMITTED, PAID
[8012]44
[10378]45from waeup.uniben.interfaces import MessageFactory as _
46
[10338]47PASTQ_ALL = ['ADT','EPCS','ESM','HEK','VTE']
[8012]48
[10338]49PASTQ_AL = ['ENL','FAA','FOL','HIS','LAL',
50            'PHL','THR','BUL','JIL','LAW','PPL','PUL'] + PASTQ_ALL
51
52PASTQ_BS = ['ANT','ANY','CHH','COH','HAE','MED','MEH','PHS','SUR',
53            'PCG','PCH','PCO', 'PCT','PHA','PHM','PMB','ANA','MBC',
54            'MLS','NSC','PSY','DPV','ODR','OSP','PER', 'RES','AEB',
55            'BCH','BOT','CED','EVL','MCB','OPT','PBB','SLT','ZOO',
56            'AEE','ANS', 'CRS','FIS','FOW','SOS'] + PASTQ_ALL
57
58PASTQ_EPS = ['CHE','CVE','DMIC','EEE','MCH','PEE','PRE','CHM',
59             'CSC','GLY','MTH','PHY'] + PASTQ_ALL
60
61PASTQ_MSS = ['ACC','BNK','BUS','ECO','GEO','POL','SAA','SWK'] + PASTQ_ALL
62
[13796]63ICT_WEEK_FIELDS = (
64    'course1',
65    'course2',
66    'aggregate',
67    'screening_score',
68    'screening_venue',
69    'screening_date',
70    'jamb_subjects',
71    'jamb_score',
72    'jamb_reg_number',
73    'hq_type',
74    'hq_matric_no',
75    'hq_degree',
76    'hq_school',
77    'hq_session',
78    'hq_disc',
79    'student_id',
80    'course_admitted',
81    )
82
[10587]83class CustomApplicantsContainerPage(ApplicantsContainerPage):
84    """The standard view for regular applicant containers.
85    """
86
87    @property
88    def form_fields(self):
89        form_fields = super(CustomApplicantsContainerPage, self).form_fields
[10589]90        usertype = getattr(self.request.principal, 'user_type', None)
91        if self.request.principal.id == 'zope.anybody' or  \
92            usertype in ('applicant', 'student'):
[10587]93            return form_fields.omit('application_fee')
94        return form_fields
95
[8630]96class CustomApplicantRegistrationPage(ApplicantRegistrationPage):
97    """Captcha'd registration page for applicants.
98    """
99
[10337]100    def _redirect(self, email, password, applicant_id):
101        # Forward email and credentials to landing page.
102        self.redirect(self.url(self.context, 'registration_complete',
103            data = dict(email=email, password=password,
104            applicant_id=applicant_id)))
105        return
[10287]106
[10375]107class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
108    """A display view for applicant data.
[10287]109    """
[10375]110    grok.template('applicantdisplaypage')
[10338]111
[10622]112    def _show_pastq_putme(self):
[10338]113        return self.target.startswith('putme') \
[10375]114               and self.context.state in ('paid', 'submitted') \
[10338]115               and getattr(self.context, 'course1') is not None
116
117    @property
118    def show_pastq_al(self):
[10622]119        return self._show_pastq_putme() \
[10338]120               and self.context.course1.__parent__.__parent__.code in PASTQ_AL
121
122    @property
123    def show_pastq_bs(self):
[10622]124        return self._show_pastq_putme() \
[10338]125               and self.context.course1.__parent__.__parent__.code in PASTQ_BS
126
127    @property
128    def show_pastq_eps(self):
[10622]129        return self._show_pastq_putme() \
[10338]130               and self.context.course1.__parent__.__parent__.code in PASTQ_EPS
131
132    @property
133    def show_pastq_mss(self):
[10622]134        return self._show_pastq_putme() \
[10338]135               and self.context.course1.__parent__.__parent__.code in PASTQ_MSS
136
[10622]137    @property
138    def show_pastq_pude(self):
139        return self.target.startswith('pude') \
140               and self.context.state in ('paid', 'submitted')
141
[11784]142    # Customizations for admission checking payments
143
[11782]144    @property
145    def form_fields(self):
[11784]146        form_fields = super(CustomApplicantDisplayFormPage, self).form_fields
[13796]147        if self.target == 'ictwk':
148            for field in ICT_WEEK_FIELDS:
149                form_fields = form_fields.omit(field)
150            return form_fields
[11784]151        if not self.context.admchecking_fee_paid():
152            form_fields = form_fields.omit(
153                'screening_score', 'aggregate', 'student_id')
[11782]154        return form_fields
155
[11784]156    @property
157    def display_actions(self):
158        state = IWorkflowState(self.context).getState()
159        actions = []
160        if state == ADMITTED and not self.context.admchecking_fee_paid():
161            actions = [_('Add admission checking payment ticket')]
162        return actions
163
164
165    def getCourseAdmitted(self):
166        """Return link, title and code in html format to the certificate
167           admitted.
168        """
169        course_admitted = self.context.course_admitted
170        if getattr(course_admitted, '__parent__',None) and \
171            self.context.admchecking_fee_paid():
172            url = self.url(course_admitted)
173            title = course_admitted.title
174            code = course_admitted.code
175            return '<a href="%s">%s - %s</a>' %(url,code,title)
176        return ''
177
[11786]178    @property
179    def admission_checking_info(self):
180        if self.context.state == ADMITTED and \
181            not self.context.admchecking_fee_paid():
182            return _('You must pay the admission checking fee '
183                     'to view your screening results and course admitted.')
184        return
185
[11784]186    @action(_('Add admission checking payment ticket'), style='primary')
187    def addPaymentTicket(self, **data):
188        self.redirect(self.url(self.context, '@@addacp'))
189        return
190
[11728]191class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
192    """ Page to add an online payment ticket
193    """
[10378]194
[11728]195    @property
196    def custom_requirements(self):
197        store = getUtility(IExtFileStore)
198        if not store.getFileByContext(self.context, attr=u'passport.jpg'):
[11782]199            return _('Upload your 1"x1" Red background passport photo before making payment.')
[11728]200        return ''
201
[11784]202class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View):
203    """ Page to add an admission checking online payment ticket.
204    """
205    grok.context(ICustomApplicant)
206    grok.name('addacp')
207    grok.require('waeup.payApplicant')
208    factory = u'waeup.ApplicantOnlinePayment'
209
210    def _setPaymentDetails(self, payment):
211        container = self.context.__parent__
212        timestamp = ("%d" % int(time()*10000))[1:]
213        session = str(container.year)
214        try:
215            session_config = grok.getSite()['configuration'][session]
216        except KeyError:
217            return _(u'Session configuration object is not available.'), None
218        payment.p_id = "p%s" % timestamp
219        payment.p_item = container.title
220        payment.p_session = container.year
221        payment.amount_auth = 0.0
222        payment.p_category = 'admission_checking'
223        payment.amount_auth = session_config.admchecking_fee
224        if payment.amount_auth in (0.0, None):
225            return _('Amount could not be determined.'), None
226        return
227
[11782]228    def update(self):
[11784]229        if self.context.admchecking_fee_paid():
230              self.flash(
231                  _('Admission checking payment has already been made.'),
232                  type='warning')
233              self.redirect(self.url(self.context))
234              return
[11782]235        payment = createObject(self.factory)
[11784]236        failure = self._setPaymentDetails(payment)
[11782]237        if failure is not None:
238            self.flash(failure[0], type='danger')
239            self.redirect(self.url(self.context))
240            return
241        self.context[payment.p_id] = payment
242        self.flash(_('Payment ticket created.'))
243        self.redirect(self.url(payment))
244        return
[11736]245
[11784]246    def render(self):
247        return
[11736]248
[11784]249
[11782]250class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
251
[11736]252    @property
253    def custom_upload_requirements(self):
254        if not checkPermission('waeup.uploadPassportPictures', self.context):
255            return _('You are not entitled to upload passport pictures.')
[11782]256
[13796]257    @property
258    def form_fields(self):
259        form_fields = super(CustomApplicantManageFormPage, self).form_fields
260        if self.target == 'ictwk':
261            for field in ICT_WEEK_FIELDS:
262                form_fields = form_fields.omit(field)
263        return form_fields
264
265
266class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
267    """An applicant-centered edit view for applicant data.
268    """
269
270    @property
271    def form_fields(self):
272        form_fields = super(CustomApplicantEditFormPage, self).form_fields
273        if self.target == 'ictwk':
274            for field in ICT_WEEK_FIELDS:
275                form_fields = form_fields.omit(field)
276        return form_fields
277
[11782]278class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage):
279    """ Approval view
280    """
281
282    def update(self):
[11784]283        if self.context.p_category == 'admission_checking':
284            if self.context.p_state == 'paid':
285                flashtype = 'warning'
286                msg = _('This ticket has already been paid.')
287                log = None
288            else:
289                self.context.approve()
290                log = 'payment approved: %s' % self.context.p_id
291                msg = _('Payment approved')
292                flashtype = 'success'
293        else:
294            flashtype, msg, log = self.context.approveApplicantPayment()
[11782]295        if log is not None:
296            applicant = self.context.__parent__
297            # Add log message to applicants.log
298            applicant.writeLogMessage(self, log)
299            # Add log message to payments.log
300            self.context.logger.info(
301                '%s,%s,%s,%s,%s,,,,,,' % (
302                applicant.applicant_id,
303                self.context.p_id, self.context.p_category,
304                self.context.amount_auth, self.context.r_code))
305        self.flash(msg, type=flashtype)
306        return
[11784]307
308class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
309    """Deliver a PDF slip of the context.
310    """
311
312    def update(self):
313        super(CustomExportPDFPageApplicationSlip, self).update()
314        if self.context.state == ADMITTED and \
315            not self.context.admchecking_fee_paid():
316            self.flash(
317                _('Please pay admission checking fee before trying to download '
318                  'the application slip.'), type='warning')
319            return self.redirect(self.url(self.context))
320        return
[13552]321
[13557]322class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
[13552]323
[13558]324    def _getPDFCreator(self):
325        if 'afak' in self.target:
326            return getUtility(IPDFCreator, name='akoka_pdfcreator')
327        return getUtility(IPDFCreator)
328
[13552]329    @property
330    def title(self):
331        container_title = self.context.__parent__.title
332        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
333        ar_translation = translate(_('Application Record'),
334            'waeup.kofa', target_language=portal_language)
[13557]335        if 'afas' in self.target:
[13552]336            return 'Federal College of Education (Technical) Asaba - %s %s %s' % (
337                container_title, ar_translation,
338                self.context.application_number)
[13615]339        elif 'afak' in self.target:
[13552]340            return 'Federal College of Education (Technical) Akoka - %s %s %s' % (
341                container_title, ar_translation,
342                self.context.application_number)
[13615]343        elif self.target == 'pgn':
344            return 'National Institute for Legislative Studies (NILS) - %s %s %s' % (
345                container_title, ar_translation,
346                self.context.application_number)
[13552]347        return '%s - %s %s' % (container_title,
348            ar_translation, self.context.application_number)
Note: See TracBrowser for help on using the repository browser.