source: main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/applicants/browser.py @ 15185

Last change on this file since 15185 was 15171, checked in by Henrik Bettermann, 6 years ago

Fix bug.

  • Property svn:keywords set to Id
File size: 9.1 KB
RevLine 
[10765]1## $Id: browser.py 15171 2018-09-24 07:48:54Z 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
[15123]21from time import time
[15087]22from zope.formlib.textwidgets import BytesDisplayWidget
[15123]23from zope.component import getUtility, createObject
24from hurry.workflow.interfaces import IWorkflowState
[10765]25from waeup.kofa.applicants.browser import (
[15123]26    ApplicantRegistrationPage, ApplicantsContainerPage,
27    ExportPDFPageApplicationSlip)
28from waeup.kofa.browser.layout import action, UtilityView
[10765]29from kofacustom.nigeria.applicants.browser import (
30    NigeriaApplicantDisplayFormPage,
[15087]31    NigeriaPDFApplicationSlip,
32    NigeriaApplicantManageFormPage,
33    NigeriaApplicantEditFormPage)
34from kofacustom.nigeria.applicants.interfaces import (
35    UG_OMIT_DISPLAY_FIELDS,
36    UG_OMIT_PDF_FIELDS,
37    UG_OMIT_MANAGE_FIELDS,
38    UG_OMIT_EDIT_FIELDS,
39    PG_OMIT_DISPLAY_FIELDS,
40    PG_OMIT_PDF_FIELDS,
41    PG_OMIT_MANAGE_FIELDS,
42    PG_OMIT_EDIT_FIELDS,
43    )
[15131]44from waeup.kofa.applicants.workflow import (
45    ADMITTED, PAID, STARTED, NOT_ADMITTED, CREATED)
[15087]46from kofacustom.edopoly.applicants.interfaces import (
47    ICustomUGApplicantEdit, ICustomUGApplicant,
[15123]48    ICustomPGApplicantEdit, ICustomPGApplicant,
49    ICustomApplicant,)
[10765]50
[15000]51from kofacustom.edopoly.interfaces import MessageFactory as _
[10765]52
[15087]53# Fields to be omitted in all display forms. course_admitted is
54# rendered separately.
55
56OMIT_DISPLAY_FIELDS = ('locked', 'course_admitted',
57    'result_uploaded', 'suspended', 'special_application',
58    'bank_account_number',
59    'bank_account_name',
60    'bank_name')
61
62# UG students are all undergraduate students.
63UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
[15170]64    #'jamb_subjects',
[15171]65    'programme_type',)
[15087]66UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',)
67UG_OMIT_MANAGE_FIELDS = (
68    'special_application',
[15170]69    #'jamb_subjects',
[15087]70    'programme_type')
[15169]71UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + UG_OMIT_DISPLAY_FIELDS + (
[15087]72    'student_id',
73    'notice',
74    'screening_score',
75    'screening_venue',
76    'screening_date',
77    'aggregate')
78
79class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
80    """A display view for applicant data.
81    """
[15123]82    grok.template('applicantdisplaypage')
[15087]83
84    @property
85    def form_fields(self):
86        target = getattr(self.context.__parent__, 'prefix', None)
87        form_fields = grok.AutoFields(ICustomUGApplicant)
[15123]88        for field in UG_OMIT_DISPLAY_FIELDS:
89            form_fields = form_fields.omit(field)
[15087]90        form_fields['notice'].custom_widget = BytesDisplayWidget
[15169]91        #form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
[15087]92        if not getattr(self.context, 'student_id'):
93            form_fields = form_fields.omit('student_id')
94        if not getattr(self.context, 'screening_score'):
95            form_fields = form_fields.omit('screening_score')
96        if not getattr(self.context, 'screening_venue'):
97            form_fields = form_fields.omit('screening_venue')
98        if not getattr(self.context, 'screening_date'):
99            form_fields = form_fields.omit('screening_date')
[15123]100        if not self.context.admchecking_fee_paid():
101            form_fields = form_fields.omit(
102                'screening_score', 'aggregate', 'student_id')
[15087]103        return form_fields
104
[15123]105    @property
106    def admission_checking_info(self):
[15131]107        if self.context.state in (ADMITTED, NOT_ADMITTED, CREATED) and \
[15123]108            not self.context.admchecking_fee_paid():
109            return _('You must pay the admission checking fee '
[15124]110                     'to view your screening results and your course admitted.')
[15123]111
112    @property
113    def display_actions(self):
114        state = IWorkflowState(self.context).getState()
115        actions = []
[15131]116        if state in (ADMITTED, NOT_ADMITTED, CREATED) \
117            and not self.context.admchecking_fee_paid():
[15123]118            actions = [_('Add admission checking payment ticket')]
119        return actions
120
121    def getCourseAdmitted(self):
122        """Return link, title and code in html format to the certificate
123           admitted.
124        """
125        if self.admission_checking_info:
[15124]126            return '<span class="hint">%s</span>' % self.admission_checking_info
[15123]127        return super(CustomApplicantDisplayFormPage, self).getCourseAdmitted()
128
129    @action(_('Add admission checking payment ticket'), style='primary')
130    def addPaymentTicket(self, **data):
131        self.redirect(self.url(self.context, '@@addacp'))
132        return
133
134class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View):
135    """ Page to add an admission checking online payment ticket.
136    """
137    grok.context(ICustomApplicant)
138    grok.name('addacp')
139    grok.require('waeup.payApplicant')
140    factory = u'waeup.ApplicantOnlinePayment'
141
142    def _setPaymentDetails(self, payment):
143        container = self.context.__parent__
144        timestamp = ("%d" % int(time()*10000))[1:]
145        session = str(container.year)
146        try:
147            session_config = grok.getSite()['configuration'][session]
148        except KeyError:
149            return _(u'Session configuration object is not available.'), None
150        payment.p_id = "p%s" % timestamp
151        payment.p_item = container.title
152        payment.p_session = container.year
153        payment.amount_auth = 0.0
154        payment.p_category = 'admission_checking'
155        payment.amount_auth = session_config.admchecking_fee
156        if payment.amount_auth in (0.0, None):
157            return _('Amount could not be determined.'), None
158        return
159
160    def update(self):
161        if self.context.admchecking_fee_paid():
162              self.flash(
163                  _('Admission checking payment has already been made.'),
164                  type='warning')
165              self.redirect(self.url(self.context))
166              return
167        payment = createObject(self.factory)
168        failure = self._setPaymentDetails(payment)
169        if failure is not None:
170            self.flash(failure[0], type='danger')
171            self.redirect(self.url(self.context))
172            return
173        self.context[payment.p_id] = payment
174        self.flash(_('Payment ticket created.'))
175        self.redirect(self.url(payment))
176        return
177
178    def render(self):
179        return
180
181class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
182    """Deliver a PDF slip of the context.
183    """
184
185    def update(self):
186        super(CustomExportPDFPageApplicationSlip, self).update()
[15131]187        if self.context.state in (ADMITTED, NOT_ADMITTED, CREATED) and \
[15123]188            not self.context.admchecking_fee_paid():
189            self.flash(
190                _('Please pay admission checking fee before trying to download '
191                  'the application slip.'), type='warning')
192            return self.redirect(self.url(self.context))
193        return
194
[15087]195class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
196
197    @property
198    def form_fields(self):
199        target = getattr(self.context.__parent__, 'prefix', None)
200        form_fields = grok.AutoFields(ICustomUGApplicant)
201        for field in UG_OMIT_PDF_FIELDS:
202            form_fields = form_fields.omit(field)
203        if not getattr(self.context, 'student_id'):
204            form_fields = form_fields.omit('student_id')
205        if not getattr(self.context, 'screening_score'):
206            form_fields = form_fields.omit('screening_score')
207        if not getattr(self.context, 'screening_venue'):
208            form_fields = form_fields.omit('screening_venue')
209        if not getattr(self.context, 'screening_date'):
210            form_fields = form_fields.omit('screening_date')
211        return form_fields
212
213class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
214    """A full edit view for applicant data.
215    """
216
217    @property
218    def form_fields(self):
219        target = getattr(self.context.__parent__, 'prefix', None)
220        form_fields = grok.AutoFields(ICustomUGApplicant)
221        for field in UG_OMIT_MANAGE_FIELDS:
222            form_fields = form_fields.omit(field)
223        form_fields['student_id'].for_display = True
224        form_fields['applicant_id'].for_display = True
225        return form_fields
226
227class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
228    """An applicant-centered edit view for applicant data.
229    """
230
231    @property
232    def form_fields(self):
233        target = getattr(self.context.__parent__, 'prefix', None)
234        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
235        for field in UG_OMIT_EDIT_FIELDS:
236            form_fields = form_fields.omit(field)
237        form_fields['applicant_id'].for_display = True
238        form_fields['reg_number'].for_display = True
239        return form_fields
Note: See TracBrowser for help on using the repository browser.