source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/browser.py @ 13620

Last change on this file since 13620 was 13620, checked in by Henrik Bettermann, 9 years ago

Add fields, permissions, browser views and buttons to enable financial clearance by bursory officers.

  • Property svn:keywords set to Id
File size: 12.4 KB
Line 
1## $Id: browser.py 13620 2016-01-16 15:01:09Z henrik $
2##
3## Copyright (C) 2012 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##
18import grok
19from zope.formlib.textwidgets import BytesDisplayWidget
20from zope.component import getUtility
21from zope.i18n import translate
22from datetime import datetime
23from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
24from waeup.kofa.interfaces import IExtFileStore, IObjectHistory
25from waeup.kofa.browser.layout import action, UtilityView
26from waeup.kofa.utils.helpers import get_current_principal
27from waeup.kofa.students.browser import (
28    StudentPersonalDisplayFormPage, StudentPersonalManageFormPage,
29    StudentClearanceManageFormPage, StudentClearanceEditFormPage,
30    StudentClearanceDisplayFormPage, OnlinePaymentFakeApproveView,
31    ExportPDFClearanceSlip, StudentBaseManageFormPage,
32    StudentBaseDisplayFormPage,
33    StudentBaseEditFormPage, StudentPersonalEditFormPage,
34    OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage,
35    OnlinePaymentBreadcrumb, ExportPDFPaymentSlip,
36    ExportPDFCourseRegistrationSlip,
37    ExportPDFBedTicketSlip,
38    StudentFilesUploadPage, emit_lock_message,
39    AccommodationManageFormPage)
40from waeup.kofa.students.interfaces import IStudentsUtils
41from waeup.kofa.students.viewlets import (
42    PaymentReceiptActionButton, StudentPassportActionButton)
43from kofacustom.nigeria.students.interfaces import (
44    INigeriaStudentBase, INigeriaStudent, INigeriaStudentPersonal,
45    INigeriaStudentPersonalEdit,
46    INigeriaUGStudentClearance,INigeriaPGStudentClearance,
47    INigeriaStudentOnlinePayment
48    )
49from waeup.kofa.students.workflow import ADMITTED
50from kofacustom.nigeria.interfaces import MessageFactory as _
51
52class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
53    """A breadcrumb for payments.
54    """
55    grok.context(INigeriaStudentOnlinePayment)
56
57class PaymentReceiptActionButton(PaymentReceiptActionButton):
58    grok.order(4)
59    grok.context(INigeriaStudentOnlinePayment)
60
61class NigeriaStudentBaseDisplayFormPage(StudentBaseDisplayFormPage):
62    """ Page to display student base data
63    """
64    form_fields = grok.AutoFields(INigeriaStudentBase).omit(
65        'password', 'suspended', 'suspended_comment')
66    form_fields[
67        'financial_clearance_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
68
69class NigeriaStudentBaseManageFormPage(StudentBaseManageFormPage):
70    """ View to manage student base data
71    """
72    form_fields = grok.AutoFields(INigeriaStudentBase).omit(
73        'student_id', 'adm_code', 'suspended',
74        'financially_cleared_by', 'financial_clearance_date')
75
76class NigeriaStudentBaseEditFormPage(StudentBaseEditFormPage):
77    """ View to edit student base data
78    """
79    form_fields = grok.AutoFields(INigeriaStudentBase).select(
80        'email', 'phone')
81
82class NigeriaStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage):
83    """ Page to display student personal data
84    """
85    form_fields = grok.AutoFields(INigeriaStudentPersonal)
86    form_fields['perm_address'].custom_widget = BytesDisplayWidget
87    form_fields['next_kin_address'].custom_widget = BytesDisplayWidget
88    form_fields[
89        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
90
91class NigeriaStudentPersonalEditFormPage(StudentPersonalEditFormPage):
92    """ Page to edit personal data
93    """
94    form_fields = grok.AutoFields(INigeriaStudentPersonalEdit).omit('personal_updated')
95
96class NigeriaStudentPersonalManageFormPage(StudentPersonalManageFormPage):
97    """ Page to edit personal data
98    """
99    form_fields = grok.AutoFields(INigeriaStudentPersonal)
100    form_fields['personal_updated'].for_display = True
101    form_fields[
102        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
103
104class NigeriaStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage):
105    """ Page to display student clearance data
106    """
107
108    @property
109    def form_fields(self):
110        if self.context.is_postgrad:
111            form_fields = grok.AutoFields(
112                INigeriaPGStudentClearance).omit('clearance_locked')
113        else:
114            form_fields = grok.AutoFields(
115                INigeriaUGStudentClearance).omit('clearance_locked')
116        if not getattr(self.context, 'officer_comment'):
117            form_fields = form_fields.omit('officer_comment')
118        else:
119            form_fields['officer_comment'].custom_widget = BytesDisplayWidget
120        return form_fields
121
122class NigeriaExportPDFClearanceSlip(ExportPDFClearanceSlip):
123    """Deliver a PDF slip of the context.
124    """
125    omit_fields = ('password', 'suspended', 'suspended_comment',
126        'phone', 'adm_code', 'email', 'date_of_birth', 'current_level')
127
128    @property
129    def form_fields(self):
130        if self.context.is_postgrad:
131            form_fields = grok.AutoFields(
132                INigeriaPGStudentClearance).omit('clearance_locked')
133        else:
134            form_fields = grok.AutoFields(
135                INigeriaUGStudentClearance).omit('clearance_locked')
136        if not getattr(self.context, 'officer_comment'):
137            form_fields = form_fields.omit('officer_comment')
138        return form_fields
139
140class NigeriaStudentClearanceManageFormPage(StudentClearanceManageFormPage):
141    """ Page to edit student clearance data
142    """
143
144    @property
145    def form_fields(self):
146        if self.context.is_postgrad:
147            form_fields = grok.AutoFields(
148                INigeriaPGStudentClearance).omit('clr_code')
149        else:
150            form_fields = grok.AutoFields(
151                INigeriaUGStudentClearance).omit('clr_code')
152        return form_fields
153
154class NigeriaStudentClearanceEditFormPage(StudentClearanceEditFormPage):
155    """ View to edit student clearance data by student
156    """
157
158    @property
159    def form_fields(self):
160        if self.context.is_postgrad:
161            form_fields = grok.AutoFields(INigeriaPGStudentClearance).omit(
162            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
163            'physical_clearance_date')
164        else:
165            form_fields = grok.AutoFields(INigeriaUGStudentClearance).omit(
166            'clearance_locked', 'clr_code', 'officer_comment',
167            'physical_clearance_date')
168        return form_fields
169
170class NigeriaExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip):
171    """Deliver a PDF slip of the context.
172    """
173    omit_fields = ('password', 'suspended', 'suspended_comment',
174        'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level')
175
176class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
177    """ Page to view an online payment ticket
178    """
179    grok.context(INigeriaStudentOnlinePayment)
180    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).omit(
181        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
182    form_fields[
183        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
184    form_fields[
185        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
186
187class NigeriaOnlinePaymentAddFormPage(OnlinePaymentAddFormPage):
188    """ Page to add an online payment ticket
189    """
190    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).select(
191        'p_category')
192
193class NigeriaOnlinePaymentFakeApproveView(OnlinePaymentFakeApproveView):
194    """ Disable payment approval view for students.
195
196    This view is used for browser tests only and
197    has to be neutralized here!
198    """
199    grok.name('fake_approve')
200    grok.require('waeup.managePortal')
201
202    def update(self):
203        return
204
205class NigeriaExportPDFPaymentSlip(ExportPDFPaymentSlip):
206    """Deliver a PDF slip of the context.
207    """
208    grok.context(INigeriaStudentOnlinePayment)
209    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).omit(
210        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
211    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
212    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
213    omit_fields = ('password', 'suspended', 'suspended_comment', 'phone',
214        'adm_code', 'sex', 'email', 'date_of_birth', 'current_level')
215
216class NigeriaAccommodationManageFormPage(AccommodationManageFormPage):
217    """ Page to manage bed tickets.
218    This manage form page is for both students and students officers.
219    """
220    with_hostel_selection = False
221
222class NigeriaExportPDFBedTicketSlip(ExportPDFBedTicketSlip):
223    """Deliver a PDF slip of the context.
224    """
225    omit_fields = ('password', 'suspended', 'suspended_comment',
226        'phone', 'adm_code', 'email', 'date_of_birth', 'current_level')
227
228class StudentPassportActionButton(StudentPassportActionButton):
229
230    @property
231    def target_url(self):
232        # Passport pictures must not be editable if application slip
233        # exists.
234        slip = getUtility(IExtFileStore).getFileByContext(
235            self.context, 'application_slip')
236        PORTRAIT_CHANGE_STATES = getUtility(IStudentsUtils).PORTRAIT_CHANGE_STATES
237        if self.context.state not in PORTRAIT_CHANGE_STATES or slip is not None:
238            return ''
239        return self.view.url(self.view.context, self.target)
240
241class NigeriaStudentFilesUploadPage(StudentFilesUploadPage):
242    """ View to upload passport picture.
243
244    Students are not allowed to change the picture if they
245    passed the regular Kofa application.
246    """
247
248    def update(self):
249        # Passport pictures must not be editable if application slip
250        # exists.
251        slip = getUtility(IExtFileStore).getFileByContext(
252            self.context, 'application_slip')
253        PORTRAIT_CHANGE_STATES = getUtility(IStudentsUtils).PORTRAIT_CHANGE_STATES
254        if self.context.state not in PORTRAIT_CHANGE_STATES or slip is not None:
255            emit_lock_message(self)
256            return
257        super(StudentFilesUploadPage, self).update()
258        return
259
260class ClearStudentFinancially(UtilityView, grok.View):
261    """ Clear student financially by bursary officer
262    """
263    grok.context(INigeriaStudent)
264    grok.name('clear_financially')
265    grok.require('waeup.clearStudentFinancially')
266
267    def update(self):
268        if self.context.financially_cleared_by:
269            self.flash(_('This student has already been financially cleared.'),
270                       type="danger")
271            self.redirect(self.url(self.context))
272            return
273        user = get_current_principal()
274        if user is None:
275            usertitle = 'system'
276        else:
277            usertitle = getattr(user, 'public_name', None)
278            if not usertitle:
279                usertitle = user.title
280        self.context.financially_cleared_by = usertitle
281        self.context.financial_clearance_date = datetime.utcnow()
282        self.context.writeLogMessage(self,'financially cleared')
283        history = IObjectHistory(self.context)
284        history.addMessage('Financially cleared')
285        self.flash(_('Student has been financially cleared.'))
286        self.redirect(self.url(self.context))
287        return
288
289    def render(self):
290        return
291
292class WithdrawFinancialClearance(UtilityView, grok.View):
293    """ Withdraw financial clearance by bursary officer
294    """
295    grok.context(INigeriaStudent)
296    grok.name('withdraw_financial_clearance')
297    grok.require('waeup.clearStudentFinancially')
298
299    def update(self):
300        if not self.context.financially_cleared_by:
301            self.flash(_('This student has not yet been financially cleared.'),
302                       type="danger")
303            self.redirect(self.url(self.context))
304            return
305        self.context.financially_cleared_by = None
306        self.context.financial_clearance_date = None
307        self.context.writeLogMessage(self,'financial clearance withdrawn')
308        history = IObjectHistory(self.context)
309        history.addMessage('Financial clearance withdrawn')
310        self.flash(_('Financial clearance withdrawn.'))
311        self.redirect(self.url(self.context))
312        return
313
314    def render(self):
315        return
Note: See TracBrowser for help on using the repository browser.