## $Id: browser.py 16031 2020-03-09 16:27:25Z henrik $
##
## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
import grok
from zope.i18n import translate
from zope.schema.interfaces import ConstraintNotSatisfied
from zope.component import getUtility
from hurry.workflow.interfaces import IWorkflowInfo
from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils
from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
from waeup.kofa.browser.layout import (
action, jsaction, UtilityView, KofaEditFormPage)
from waeup.kofa.students.browser import (
StudyLevelEditFormPage, StudyLevelDisplayFormPage,
StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip,
CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage,
StartClearancePage, BalancePaymentAddFormPage,
msave, emit_lock_message)
from waeup.kofa.students.interfaces import (
IStudentsUtils, ICourseTicket, IStudent)
from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
from kofacustom.nigeria.students.browser import (
NigeriaOnlinePaymentDisplayFormPage,
NigeriaStudentBaseDisplayFormPage,
NigeriaStudentBaseManageFormPage,
NigeriaStudentClearanceEditFormPage,
NigeriaOnlinePaymentAddFormPage,
NigeriaExportPDFPaymentSlip,
NigeriaExportPDFClearanceSlip,
NigeriaExportPDFCourseRegistrationSlip,
NigeriaStudentBaseEditFormPage,
NigeriaBedTicketAddPage,
NigeriaAccommodationManageFormPage,
NigeriaAccommodationDisplayFormPage,
)
from kofacustom.iuokada.students.interfaces import (
ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
ICustomStudentStudyLevel, ICustomStudentBase, ICustomStudent)
from kofacustom.iuokada.interfaces import MessageFactory as _
class CustomStudentBaseDisplayFormPage(NigeriaStudentBaseDisplayFormPage):
""" Page to display student base data
"""
form_fields = grok.AutoFields(ICustomStudentBase).omit(
'password', 'suspended', 'suspended_comment', 'flash_notice')
class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage):
""" View to manage student base data
"""
form_fields = grok.AutoFields(ICustomStudentBase).omit(
'student_id', 'adm_code', 'suspended',
'financially_cleared_by', 'financial_clearance_date')
class StudentBaseEditFormPage(NigeriaStudentBaseEditFormPage):
""" View to edit student base data
"""
form_fields = grok.AutoFields(ICustomStudentBase).select(
'email', 'email2', 'parents_email', 'phone',)
class CustomExportPDFCourseRegistrationSlip(
NigeriaExportPDFCourseRegistrationSlip):
"""Deliver a PDF slip of the context.
"""
def _signatures(self):
return (
['Student Signature'],
['HoD / Course Adviser Signature'],
['College Officer Signature'],
['Dean Signature']
)
#def _sigsInFooter(self):
# return (_('Student'),
# _('HoD / Course Adviser'),
# _('College Officer'),
# _('Dean'),
# )
# return ()
class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage):
""" Page to view bed tickets.
"""
with_hostel_selection = True
class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage):
""" Page to manage bed tickets.
This manage form page is for both students and students officers.
"""
with_hostel_selection = True
class CustomBedTicketAddPage(NigeriaBedTicketAddPage):
""" Page to add a bed ticket
"""
with_ac = False
with_bedselection = True
class StudentGetMatricNumberPage(UtilityView, grok.View):
""" Construct and set the matriculation number.
"""
grok.context(IStudent)
grok.name('get_matric_number')
grok.require('waeup.manageStudent')
def update(self):
students_utils = getUtility(IStudentsUtils)
msg, mnumber = students_utils.setMatricNumber(self.context)
if msg:
self.flash(msg, type="danger")
else:
self.flash(_('Matriculation number %s assigned.' % mnumber))
self.context.writeLogMessage(self, '%s assigned' % mnumber)
self.redirect(self.url(self.context))
return
def render(self):
return
class SwitchLibraryAccessView(UtilityView, grok.View):
""" Switch the library attribute
"""
grok.context(ICustomStudent)
grok.name('switch_library_access')
grok.require('waeup.switchLibraryAccess')
def update(self):
if self.context.library:
self.context.library = False
self.context.writeLogMessage(self, 'library access disabled')
self.flash(_('Library access disabled'))
else:
self.context.library = True
self.context.writeLogMessage(self, 'library access enabled')
self.flash(_('Library access enabled'))
self.redirect(self.url(self.context))
return
def render(self):
return
class ExportLibIdCard(UtilityView, grok.View):
"""Deliver an id card for the library.
"""
grok.context(ICustomStudent)
grok.name('lib_idcard.pdf')
grok.require('waeup.viewStudent')
prefix = 'form'
label = u"Library Clearance"
omit_fields = (
'suspended', 'email', 'phone',
'adm_code', 'suspended_comment',
'date_of_birth',
'current_mode', 'certificate',
'entry_session',
'flash_notice')
form_fields = []
def _sigsInFooter(self):
isStudent = getattr(
self.request.principal, 'user_type', None) == 'student'
if isStudent:
return ''
return (_("Date, Reader's Signature"),
_("Date, Circulation Librarian's Signature"),
)
def update(self):
if not self.context.library:
self.flash(_('Forbidden!'), type="danger")
self.redirect(self.url(self.context))
return
@property
def note(self):
return """
This is to certify that the bearer whose photograph and other details appear
overleaf is a registered user of the University Library.
The card is not transferable. A replacement fee is charged for a loss,
mutilation or otherwise. If found, please, return to the University Library,
Igbinedion University, Okada.
"""
return
def render(self):
studentview = StudentBasePDFFormPage(self.context.student,
self.request, self.omit_fields)
students_utils = getUtility(IStudentsUtils)
return students_utils.renderPDF(
self, 'lib_idcard',
self.context.student, studentview,
omit_fields=self.omit_fields,
sigs_in_footer=self._sigsInFooter(),
note=self.note)
class CustomStartClearancePage(StartClearancePage):
with_ac = False
class CustomBalancePaymentAddFormPage(BalancePaymentAddFormPage):
grok.require('waeup.payStudent')