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

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

Add NILS application type and category and customize slip.

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