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

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

Display warning message as hint.

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