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

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

Change permissions for applicants exporters.

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