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

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

Hide workflow state and history if admission checking fee has not been paid.

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