Ignore:
Timestamp:
16 Jan 2016, 15:01:09 (9 years ago)
Author:
Henrik Bettermann
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/browser.py

    r13458 r13620  
    2020from zope.component import getUtility
    2121from zope.i18n import translate
     22from datetime import datetime
    2223from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
    23 from waeup.kofa.interfaces import IExtFileStore
    24 from waeup.kofa.browser.layout import action
     24from waeup.kofa.interfaces import IExtFileStore, IObjectHistory
     25from waeup.kofa.browser.layout import action, UtilityView
     26from waeup.kofa.utils.helpers import get_current_principal
    2527from waeup.kofa.students.browser import (
    2628    StudentPersonalDisplayFormPage, StudentPersonalManageFormPage,
     
    6264    form_fields = grok.AutoFields(INigeriaStudentBase).omit(
    6365        'password', 'suspended', 'suspended_comment')
     66    form_fields[
     67        'financial_clearance_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    6468
    6569class NigeriaStudentBaseManageFormPage(StudentBaseManageFormPage):
     
    6771    """
    6872    form_fields = grok.AutoFields(INigeriaStudentBase).omit(
    69         'student_id', 'adm_code', 'suspended')
     73        'student_id', 'adm_code', 'suspended',
     74        'financially_cleared_by', 'financial_clearance_date')
    7075
    7176class NigeriaStudentBaseEditFormPage(StudentBaseEditFormPage):
     
    252257        super(StudentFilesUploadPage, self).update()
    253258        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 TracChangeset for help on using the changeset viewer.