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

Last change on this file since 13808 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
Line 
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"""
20import grok
21from time import time
22from zope.component import getUtility, createObject
23from zope.security import checkPermission
24from zope.i18n import translate
25from hurry.workflow.interfaces import IWorkflowState
26from waeup.kofa.browser.layout import action, UtilityView
27from waeup.kofa.interfaces import IExtFileStore, IKofaUtils
28from waeup.kofa.applicants.browser import (
29    ApplicantRegistrationPage, ApplicantsContainerPage,
30    ApplicationFeePaymentAddPage,
31    OnlinePaymentApprovePage,
32    ExportPDFPageApplicationSlip)
33from waeup.kofa.applicants.interfaces import (
34    ISpecialApplicant, IApplicantsUtils)
35from waeup.kofa.browser.interfaces import IPDFCreator
36from kofacustom.nigeria.applicants.browser import (
37    NigeriaApplicantDisplayFormPage,
38    NigeriaApplicantManageFormPage,
39    NigeriaApplicantEditFormPage,
40    NigeriaPDFApplicationSlip)
41from waeup.uniben.applicants.interfaces import (
42    ICustomApplicant)
43from waeup.kofa.applicants.workflow import ADMITTED, PAID
44
45from waeup.uniben.interfaces import MessageFactory as _
46
47PASTQ_ALL = ['ADT','EPCS','ESM','HEK','VTE']
48
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
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
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
90        usertype = getattr(self.request.principal, 'user_type', None)
91        if self.request.principal.id == 'zope.anybody' or  \
92            usertype in ('applicant', 'student'):
93            return form_fields.omit('application_fee')
94        return form_fields
95
96class CustomApplicantRegistrationPage(ApplicantRegistrationPage):
97    """Captcha'd registration page for applicants.
98    """
99
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
106
107class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
108    """A display view for applicant data.
109    """
110    grok.template('applicantdisplaypage')
111
112    def _show_pastq_putme(self):
113        return self.target.startswith('putme') \
114               and self.context.state in ('paid', 'submitted') \
115               and getattr(self.context, 'course1') is not None
116
117    @property
118    def show_pastq_al(self):
119        return self._show_pastq_putme() \
120               and self.context.course1.__parent__.__parent__.code in PASTQ_AL
121
122    @property
123    def show_pastq_bs(self):
124        return self._show_pastq_putme() \
125               and self.context.course1.__parent__.__parent__.code in PASTQ_BS
126
127    @property
128    def show_pastq_eps(self):
129        return self._show_pastq_putme() \
130               and self.context.course1.__parent__.__parent__.code in PASTQ_EPS
131
132    @property
133    def show_pastq_mss(self):
134        return self._show_pastq_putme() \
135               and self.context.course1.__parent__.__parent__.code in PASTQ_MSS
136
137    @property
138    def show_pastq_pude(self):
139        return self.target.startswith('pude') \
140               and self.context.state in ('paid', 'submitted')
141
142    # Customizations for admission checking payments
143
144    @property
145    def form_fields(self):
146        form_fields = super(CustomApplicantDisplayFormPage, self).form_fields
147        if self.target == 'ictwk':
148            for field in ICT_WEEK_FIELDS:
149                form_fields = form_fields.omit(field)
150            return form_fields
151        if not self.context.admchecking_fee_paid():
152            form_fields = form_fields.omit(
153                'screening_score', 'aggregate', 'student_id')
154        return form_fields
155
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
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
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
191class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
192    """ Page to add an online payment ticket
193    """
194
195    @property
196    def custom_requirements(self):
197        store = getUtility(IExtFileStore)
198        if not store.getFileByContext(self.context, attr=u'passport.jpg'):
199            return _('Upload your 1"x1" Red background passport photo before making payment.')
200        return ''
201
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
228    def update(self):
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
235        payment = createObject(self.factory)
236        failure = self._setPaymentDetails(payment)
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
245
246    def render(self):
247        return
248
249
250class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
251
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.')
256
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
278class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage):
279    """ Approval view
280    """
281
282    def update(self):
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()
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
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
321
322class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
323
324    def _getPDFCreator(self):
325        if 'afak' in self.target:
326            return getUtility(IPDFCreator, name='akoka_pdfcreator')
327        return getUtility(IPDFCreator)
328
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)
335        if 'afas' in self.target:
336            return 'Federal College of Education (Technical) Asaba - %s %s %s' % (
337                container_title, ar_translation,
338                self.context.application_number)
339        elif 'afak' in self.target:
340            return 'Federal College of Education (Technical) Akoka - %s %s %s' % (
341                container_title, ar_translation,
342                self.context.application_number)
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)
347        return '%s - %s %s' % (container_title,
348            ar_translation, self.context.application_number)
Note: See TracBrowser for help on using the repository browser.