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

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

Implement special application (for supplementary payments).

  • Property svn:keywords set to Id
File size: 9.7 KB
Line 
1## $Id: browser.py 15218 2018-11-08 12:45:03Z 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, ICustomSpecialApplicant,)
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',
65    'programme_type',)
66UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',)
67UG_OMIT_MANAGE_FIELDS = (
68    'special_application',
69    #'jamb_subjects',
70    'programme_type')
71UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + UG_OMIT_DISPLAY_FIELDS + (
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    """
82    grok.template('applicantdisplaypage')
83
84    @property
85    def form_fields(self):
86        target = getattr(self.context.__parent__, 'prefix', None)
87        if self.context.special:
88            return grok.AutoFields(ICustomSpecialApplicant)
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 in (ADMITTED, NOT_ADMITTED, CREATED) 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 in (ADMITTED, NOT_ADMITTED, CREATED) \
119            and not self.context.admchecking_fee_paid():
120            actions = [_('Add admission checking payment ticket')]
121        return actions
122
123    def getCourseAdmitted(self):
124        """Return link, title and code in html format to the certificate
125           admitted.
126        """
127        if self.admission_checking_info:
128            return '<span class="hint">%s</span>' % self.admission_checking_info
129        return super(CustomApplicantDisplayFormPage, self).getCourseAdmitted()
130
131    @action(_('Add admission checking payment ticket'), style='primary')
132    def addPaymentTicket(self, **data):
133        self.redirect(self.url(self.context, '@@addacp'))
134        return
135
136class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View):
137    """ Page to add an admission checking online payment ticket.
138    """
139    grok.context(ICustomApplicant)
140    grok.name('addacp')
141    grok.require('waeup.payApplicant')
142    factory = u'waeup.ApplicantOnlinePayment'
143
144    def _setPaymentDetails(self, payment):
145        container = self.context.__parent__
146        timestamp = ("%d" % int(time()*10000))[1:]
147        session = str(container.year)
148        try:
149            session_config = grok.getSite()['configuration'][session]
150        except KeyError:
151            return _(u'Session configuration object is not available.'), None
152        payment.p_id = "p%s" % timestamp
153        payment.p_item = container.title
154        payment.p_session = container.year
155        payment.amount_auth = 0.0
156        payment.p_category = 'admission_checking'
157        payment.amount_auth = session_config.admchecking_fee
158        if payment.amount_auth in (0.0, None):
159            return _('Amount could not be determined.'), None
160        return
161
162    def update(self):
163        if self.context.admchecking_fee_paid():
164              self.flash(
165                  _('Admission checking payment has already been made.'),
166                  type='warning')
167              self.redirect(self.url(self.context))
168              return
169        payment = createObject(self.factory)
170        failure = self._setPaymentDetails(payment)
171        if failure is not None:
172            self.flash(failure[0], type='danger')
173            self.redirect(self.url(self.context))
174            return
175        self.context[payment.p_id] = payment
176        self.flash(_('Payment ticket created.'))
177        self.redirect(self.url(payment))
178        return
179
180    def render(self):
181        return
182
183class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip):
184    """Deliver a PDF slip of the context.
185    """
186
187    def update(self):
188        super(CustomExportPDFPageApplicationSlip, self).update()
189        if self.context.state in (ADMITTED, NOT_ADMITTED, CREATED) and \
190            not self.context.admchecking_fee_paid():
191            self.flash(
192                _('Please pay admission checking fee before trying to download '
193                  'the application slip.'), type='warning')
194            return self.redirect(self.url(self.context))
195        return
196
197class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
198
199    @property
200    def form_fields(self):
201        target = getattr(self.context.__parent__, 'prefix', None)
202        form_fields = grok.AutoFields(ICustomUGApplicant)
203        for field in UG_OMIT_PDF_FIELDS:
204            form_fields = form_fields.omit(field)
205        if not getattr(self.context, 'student_id'):
206            form_fields = form_fields.omit('student_id')
207        if not getattr(self.context, 'screening_score'):
208            form_fields = form_fields.omit('screening_score')
209        if not getattr(self.context, 'screening_venue'):
210            form_fields = form_fields.omit('screening_venue')
211        if not getattr(self.context, 'screening_date'):
212            form_fields = form_fields.omit('screening_date')
213        return form_fields
214
215class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
216    """A full edit view for applicant data.
217    """
218
219    @property
220    def form_fields(self):
221        if self.context.special:
222            form_fields = grok.AutoFields(ICustomSpecialApplicant)
223            form_fields['applicant_id'].for_display = True
224            return form_fields
225        target = getattr(self.context.__parent__, 'prefix', None)
226        form_fields = grok.AutoFields(ICustomUGApplicant)
227        for field in UG_OMIT_MANAGE_FIELDS:
228            form_fields = form_fields.omit(field)
229        form_fields['student_id'].for_display = True
230        form_fields['applicant_id'].for_display = True
231        return form_fields
232
233class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
234    """An applicant-centered edit view for applicant data.
235    """
236
237    @property
238    def form_fields(self):
239        if self.context.special:
240            form_fields = grok.AutoFields(ICustomSpecialApplicant).omit(
241                'locked', 'suspended')
242            form_fields['applicant_id'].for_display = True
243            return form_fields
244        target = getattr(self.context.__parent__, 'prefix', None)
245        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
246        for field in UG_OMIT_EDIT_FIELDS:
247            form_fields = form_fields.omit(field)
248        form_fields['applicant_id'].for_display = True
249        form_fields['reg_number'].for_display = True
250        return form_fields
Note: See TracBrowser for help on using the repository browser.