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

Last change on this file since 15711 was 15711, checked in by Henrik Bettermann, 5 years ago

Customize BedTicketAddPage?

  • Property svn:keywords set to Id
File size: 16.5 KB
RevLine 
[8862]1## $Id: browser.py 15711 2019-10-29 06:06:52Z 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
[13856]21from zope.security import checkPermission
[8862]22from zope.i18n import translate
[13620]23from datetime import datetime
[8862]24from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
[13623]25from waeup.kofa.interfaces import IExtFileStore, IObjectHistory, IKofaUtils
[13620]26from waeup.kofa.browser.layout import action, UtilityView
[13623]27from waeup.kofa.utils.helpers import get_current_principal, to_timezone
[8862]28from waeup.kofa.students.browser import (
[8904]29    StudentPersonalDisplayFormPage, StudentPersonalManageFormPage,
[8862]30    StudentClearanceManageFormPage, StudentClearanceEditFormPage,
[13058]31    StudentClearanceDisplayFormPage, OnlinePaymentFakeApproveView,
32    ExportPDFClearanceSlip, StudentBaseManageFormPage,
[8966]33    StudentBaseDisplayFormPage,
[13623]34    StudentBasePDFFormPage,
[8862]35    StudentBaseEditFormPage, StudentPersonalEditFormPage,
36    OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage,
[13058]37    OnlinePaymentBreadcrumb, ExportPDFPaymentSlip,
38    ExportPDFCourseRegistrationSlip,
39    ExportPDFBedTicketSlip,
[13458]40    StudentFilesUploadPage, emit_lock_message,
[15711]41    AccommodationManageFormPage,
42    BedTicketAddPage)
[10707]43from waeup.kofa.students.interfaces import IStudentsUtils
[8862]44from waeup.kofa.students.viewlets import (
45    PaymentReceiptActionButton, StudentPassportActionButton)
46from kofacustom.nigeria.students.interfaces import (
[8863]47    INigeriaStudentBase, INigeriaStudent, INigeriaStudentPersonal,
[9564]48    INigeriaStudentPersonalEdit,
[8863]49    INigeriaUGStudentClearance,INigeriaPGStudentClearance,
[8904]50    INigeriaStudentOnlinePayment
[8862]51    )
52from waeup.kofa.students.workflow import ADMITTED
53from kofacustom.nigeria.interfaces import MessageFactory as _
54
[8863]55class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
[8862]56    """A breadcrumb for payments.
57    """
[8863]58    grok.context(INigeriaStudentOnlinePayment)
[8862]59
60class PaymentReceiptActionButton(PaymentReceiptActionButton):
61    grok.order(4)
[8863]62    grok.context(INigeriaStudentOnlinePayment)
[8862]63
[8966]64class NigeriaStudentBaseDisplayFormPage(StudentBaseDisplayFormPage):
65    """ Page to display student base data
66    """
[9704]67    form_fields = grok.AutoFields(INigeriaStudentBase).omit(
[14274]68        'password', 'suspended', 'suspended_comment',
69        'flash_notice', 'provisionally_cleared')
[13620]70    form_fields[
71        'financial_clearance_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[8966]72
[8863]73class NigeriaStudentBaseManageFormPage(StudentBaseManageFormPage):
[8862]74    """ View to manage student base data
75    """
[9144]76    form_fields = grok.AutoFields(INigeriaStudentBase).omit(
[13620]77        'student_id', 'adm_code', 'suspended',
78        'financially_cleared_by', 'financial_clearance_date')
[8862]79
[8863]80class NigeriaStudentBaseEditFormPage(StudentBaseEditFormPage):
[8862]81    """ View to edit student base data
82    """
[8863]83    form_fields = grok.AutoFields(INigeriaStudentBase).select(
[8862]84        'email', 'phone')
85
[8863]86class NigeriaStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage):
[8862]87    """ Page to display student personal data
88    """
[9562]89    form_fields = grok.AutoFields(INigeriaStudentPersonal)
[8862]90    form_fields['perm_address'].custom_widget = BytesDisplayWidget
[9053]91    form_fields['next_kin_address'].custom_widget = BytesDisplayWidget
[9562]92    form_fields[
93        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[8862]94
[8863]95class NigeriaStudentPersonalEditFormPage(StudentPersonalEditFormPage):
[8862]96    """ Page to edit personal data
97    """
[9564]98    form_fields = grok.AutoFields(INigeriaStudentPersonalEdit).omit('personal_updated')
[8862]99
[8904]100class NigeriaStudentPersonalManageFormPage(StudentPersonalManageFormPage):
101    """ Page to edit personal data
102    """
103    form_fields = grok.AutoFields(INigeriaStudentPersonal)
[9554]104    form_fields['personal_updated'].for_display = True
[9572]105    form_fields[
106        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[8904]107
[8863]108class NigeriaStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage):
[8862]109    """ Page to display student clearance data
110    """
111
112    @property
113    def form_fields(self):
[9248]114        if self.context.is_postgrad:
[8862]115            form_fields = grok.AutoFields(
[8863]116                INigeriaPGStudentClearance).omit('clearance_locked')
[8862]117        else:
118            form_fields = grok.AutoFields(
[8863]119                INigeriaUGStudentClearance).omit('clearance_locked')
[9535]120        if not getattr(self.context, 'officer_comment'):
121            form_fields = form_fields.omit('officer_comment')
122        else:
123            form_fields['officer_comment'].custom_widget = BytesDisplayWidget
[8862]124        return form_fields
125
[13058]126class NigeriaExportPDFClearanceSlip(ExportPDFClearanceSlip):
[8862]127    """Deliver a PDF slip of the context.
128    """
[9704]129    omit_fields = ('password', 'suspended', 'suspended_comment',
[13712]130        'phone', 'adm_code', 'email', 'date_of_birth', 'current_level',
131        'flash_notice')
[8862]132
133    @property
134    def form_fields(self):
[9248]135        if self.context.is_postgrad:
[8862]136            form_fields = grok.AutoFields(
[8863]137                INigeriaPGStudentClearance).omit('clearance_locked')
[8862]138        else:
139            form_fields = grok.AutoFields(
[8863]140                INigeriaUGStudentClearance).omit('clearance_locked')
[9535]141        if not getattr(self.context, 'officer_comment'):
142            form_fields = form_fields.omit('officer_comment')
[8862]143        return form_fields
144
[8863]145class NigeriaStudentClearanceManageFormPage(StudentClearanceManageFormPage):
[8862]146    """ Page to edit student clearance data
147    """
148
149    @property
150    def form_fields(self):
[9248]151        if self.context.is_postgrad:
[9249]152            form_fields = grok.AutoFields(
153                INigeriaPGStudentClearance).omit('clr_code')
[8862]154        else:
[9249]155            form_fields = grok.AutoFields(
156                INigeriaUGStudentClearance).omit('clr_code')
[8862]157        return form_fields
158
[8863]159class NigeriaStudentClearanceEditFormPage(StudentClearanceEditFormPage):
[8862]160    """ View to edit student clearance data by student
161    """
162
163    @property
164    def form_fields(self):
[9248]165        if self.context.is_postgrad:
[8946]166            form_fields = grok.AutoFields(INigeriaPGStudentClearance).omit(
[12107]167            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
[12120]168            'physical_clearance_date')
[8862]169        else:
[8946]170            form_fields = grok.AutoFields(INigeriaUGStudentClearance).omit(
[12107]171            'clearance_locked', 'clr_code', 'officer_comment',
[12120]172            'physical_clearance_date')
[8862]173        return form_fields
174
[13058]175class NigeriaExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip):
[9376]176    """Deliver a PDF slip of the context.
177    """
[9704]178    omit_fields = ('password', 'suspended', 'suspended_comment',
[13712]179        'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level',
180        'flash_notice')
[9376]181
[8863]182class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
[8862]183    """ Page to view an online payment ticket
184    """
[8863]185    grok.context(INigeriaStudentOnlinePayment)
[9774]186    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).omit(
[15687]187        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item','p_combi')
[8862]188    form_fields[
189        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
190    form_fields[
191        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
192
[8863]193class NigeriaOnlinePaymentAddFormPage(OnlinePaymentAddFormPage):
[8862]194    """ Page to add an online payment ticket
195    """
[8863]196    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).select(
[15665]197        'p_combi')
[8862]198
[13058]199class NigeriaOnlinePaymentFakeApproveView(OnlinePaymentFakeApproveView):
[8862]200    """ Disable payment approval view for students.
201
202    This view is used for browser tests only and
203    has to be neutralized here!
204    """
205    grok.name('fake_approve')
206    grok.require('waeup.managePortal')
207
208    def update(self):
209        return
210
[13058]211class NigeriaExportPDFPaymentSlip(ExportPDFPaymentSlip):
[8862]212    """Deliver a PDF slip of the context.
213    """
[8863]214    grok.context(INigeriaStudentOnlinePayment)
[9774]215    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).omit(
[15470]216        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item',
[15687]217        'p_split_data','p_combi')
[8862]218    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
219    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[9704]220    omit_fields = ('password', 'suspended', 'suspended_comment', 'phone',
[13712]221        'adm_code', 'sex', 'email', 'date_of_birth', 'current_level',
222        'flash_notice')
[8862]223
[13458]224class NigeriaAccommodationManageFormPage(AccommodationManageFormPage):
225    """ Page to manage bed tickets.
226    This manage form page is for both students and students officers.
227    """
228    with_hostel_selection = False
229
[15711]230class NigeriaBedTicketAddPage(BedTicketAddPage):
231    """ Page to add a bed ticket
232    """
233    with_ac = True
234    with_bedselection = False
235
[13058]236class NigeriaExportPDFBedTicketSlip(ExportPDFBedTicketSlip):
[9376]237    """Deliver a PDF slip of the context.
238    """
[9704]239    omit_fields = ('password', 'suspended', 'suspended_comment',
[13712]240        'phone', 'adm_code', 'email', 'date_of_birth', 'current_level',
241        'flash_notice')
[9376]242
[8862]243class StudentPassportActionButton(StudentPassportActionButton):
244
245    @property
246    def target_url(self):
[10707]247        # Passport pictures must not be editable if application slip
248        # exists.
[8862]249        slip = getUtility(IExtFileStore).getFileByContext(
250            self.context, 'application_slip')
[13130]251        PORTRAIT_CHANGE_STATES = getUtility(IStudentsUtils).PORTRAIT_CHANGE_STATES
252        if self.context.state not in PORTRAIT_CHANGE_STATES or slip is not None:
[8862]253            return ''
254        return self.view.url(self.view.context, self.target)
255
[8863]256class NigeriaStudentFilesUploadPage(StudentFilesUploadPage):
[8862]257    """ View to upload passport picture.
258
259    Students are not allowed to change the picture if they
260    passed the regular Kofa application.
261    """
262
263    def update(self):
[10707]264        # Passport pictures must not be editable if application slip
265        # exists.
[8862]266        slip = getUtility(IExtFileStore).getFileByContext(
267            self.context, 'application_slip')
[13130]268        PORTRAIT_CHANGE_STATES = getUtility(IStudentsUtils).PORTRAIT_CHANGE_STATES
269        if self.context.state not in PORTRAIT_CHANGE_STATES or slip is not None:
[8862]270            emit_lock_message(self)
271            return
272        super(StudentFilesUploadPage, self).update()
[13620]273        return
274
275class ClearStudentFinancially(UtilityView, grok.View):
[13634]276    """ Clear student financially by financial clearance officer
[13620]277    """
278    grok.context(INigeriaStudent)
279    grok.name('clear_financially')
280    grok.require('waeup.clearStudentFinancially')
281
282    def update(self):
283        if self.context.financially_cleared_by:
284            self.flash(_('This student has already been financially cleared.'),
285                       type="danger")
286            self.redirect(self.url(self.context))
287            return
288        user = get_current_principal()
289        if user is None:
290            usertitle = 'system'
291        else:
292            usertitle = getattr(user, 'public_name', None)
293            if not usertitle:
294                usertitle = user.title
295        self.context.financially_cleared_by = usertitle
296        self.context.financial_clearance_date = datetime.utcnow()
297        self.context.writeLogMessage(self,'financially cleared')
298        history = IObjectHistory(self.context)
299        history.addMessage('Financially cleared')
300        self.flash(_('Student has been financially cleared.'))
301        self.redirect(self.url(self.context))
302        return
303
304    def render(self):
305        return
306
307class WithdrawFinancialClearance(UtilityView, grok.View):
[13634]308    """ Withdraw financial clearance by financial clearance officer
[13620]309    """
310    grok.context(INigeriaStudent)
311    grok.name('withdraw_financial_clearance')
312    grok.require('waeup.clearStudentFinancially')
313
314    def update(self):
315        if not self.context.financially_cleared_by:
316            self.flash(_('This student has not yet been financially cleared.'),
317                       type="danger")
318            self.redirect(self.url(self.context))
319            return
320        self.context.financially_cleared_by = None
321        self.context.financial_clearance_date = None
322        self.context.writeLogMessage(self,'financial clearance withdrawn')
323        history = IObjectHistory(self.context)
324        history.addMessage('Financial clearance withdrawn')
325        self.flash(_('Financial clearance withdrawn.'))
326        self.redirect(self.url(self.context))
327        return
328
329    def render(self):
[13623]330        return
331
332cleared_note = """
333<br /><br /><br />
334<strong>Financially cleared on %s by %s.</strong>
335
336"""
337
[13634]338class NigeriaExportPDFFinancialClearancePage(UtilityView, grok.View):
339    """Deliver a PDF financial clearance slip.
[13623]340    """
341    grok.context(INigeriaStudent)
[13781]342    grok.name('fee_payment_history.pdf')
[13623]343    grok.require('waeup.viewStudent')
344    prefix = 'form'
345
346    omit_fields = (
347        'suspended', 'phone',
348        'adm_code', 'suspended_comment',
[13712]349        'date_of_birth', 'current_level',
350        'flash_notice')
[13623]351
352    form_fields = None
353
354    @property
355    def label(self):
356        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[13787]357        return translate(_('Fee Payment History for'),
[13623]358            'waeup.kofa', target_language=portal_language) \
359            + ' %s' % self.context.display_fullname
360
361    def _sigsInFooter(self):
[14163]362        if not checkPermission('waeup.clearStudentFinancially', self.context):
363            return ()
[13642]364        return (_('Date, Checking Officer Signature'),
365                _('Date, Approving Officer Signature'),
[13623]366                )
367
368    @property
369    def note(self):
370        if self.context.financially_cleared_by:
371            tz = getUtility(IKofaUtils).tzinfo
372            try:
373                timestamp = to_timezone(
374                    self.context.financial_clearance_date, tz).strftime(
375                        "%Y-%m-%d %H:%M:%S")
376            except ValueError:
[13760]377                return
[13623]378            return cleared_note % (
379                timestamp, self.context.financially_cleared_by)
[13760]380        return
[13623]381
382    @property
383    def tabletitle(self):
384        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
385        tabletitle = []
386        tabletitle.append(translate(_('Successful Payments'), 'waeup.kofa',
387            target_language=portal_language))
388        return tabletitle
389
390    def render(self):
391        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
392        P_ID = translate(_('Payment Id'), 'waeup.kofa', target_language=portal_language)
393        #CD = translate(_('Creation Date'), 'waeup.kofa', target_language=portal_language)
394        PD = translate(_('Payment Date'), 'waeup.kofa', target_language=portal_language)
395        CAT = translate(_('Payment Category'), 'waeup.kofa', target_language=portal_language)
396        ITEM = translate(_('Payment Item'), 'waeup.kofa', target_language=portal_language)
397        AMT = translate(_('Amount (Naira)'), 'waeup.kofa', target_language=portal_language)
398        SSS = translate(_('Payment Session'), 'waeup.kofa', target_language=portal_language)
399        studentview = StudentBasePDFFormPage(self.context.student,
400            self.request, self.omit_fields)
401        students_utils = getUtility(IStudentsUtils)
402
403        tabledata = []
404        tableheader = []
405        tabledata.append(sorted(
406            [value for value in self.context['payments'].values()
[14279]407             if value.p_state in ('paid', 'waived')], key=lambda value: value.p_session))
[13634]408        tableheader.append([(P_ID,'p_id', 4.2),
[13623]409                         #(CD,'creation_date', 3),
410                         (PD,'formatted_p_date', 3),
411                         (CAT,'category', 3),
412                         (ITEM, 'p_item', 3),
413                         (AMT, 'amount_auth', 2),
414                         (SSS, 'p_session', 2),
415                         ])
416        return students_utils.renderPDF(
[13634]417            self, 'financial_clearance_slip.pdf',
[13623]418            self.context.student, studentview,
419            tableheader=tableheader,
420            tabledata=tabledata,
421            signatures=None,
422            sigs_in_footer=self._sigsInFooter(),
423            omit_fields=self.omit_fields,
424            note=self.note
425            )
Note: See TracBrowser for help on using the repository browser.