source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/students/browser.py @ 16012

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

Some adjustments to base package.

  • Property svn:keywords set to Id
File size: 7.4 KB
RevLine 
[10765]1## $Id: browser.py 15999 2020-02-11 09:51:47Z 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.i18n import translate
20from zope.schema.interfaces import ConstraintNotSatisfied
21from zope.component import getUtility
22from hurry.workflow.interfaces import IWorkflowInfo
23from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils
24from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
[15802]25from waeup.kofa.browser.layout import (
26    action, jsaction, UtilityView, KofaEditFormPage)
[10765]27from waeup.kofa.students.browser import (
28    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
[13062]29    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip,
[10765]30    CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage,
[15937]31    StartClearancePage,
[10765]32    msave, emit_lock_message)
[15802]33from waeup.kofa.students.interfaces import (
34    IStudentsUtils, ICourseTicket, IStudent)
[10765]35from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
36from kofacustom.nigeria.students.browser import (
37    NigeriaOnlinePaymentDisplayFormPage,
[15704]38    NigeriaStudentBaseDisplayFormPage,
[10765]39    NigeriaStudentBaseManageFormPage,
40    NigeriaStudentClearanceEditFormPage,
41    NigeriaOnlinePaymentAddFormPage,
[13062]42    NigeriaExportPDFPaymentSlip,
43    NigeriaExportPDFClearanceSlip,
[15696]44    NigeriaExportPDFCourseRegistrationSlip,
[15704]45    NigeriaStudentBaseEditFormPage,
[15722]46    NigeriaBedTicketAddPage,
[15999]47    NigeriaAccommodationManageFormPage,
48    NigeriaAccommodationDisplayFormPage,
[10765]49    )
50
[15563]51from kofacustom.iuokada.students.interfaces import (
[10765]52    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
[15859]53    ICustomStudentStudyLevel, ICustomStudentBase, ICustomStudent)
[15563]54from kofacustom.iuokada.interfaces import MessageFactory as _
[10765]55
[15704]56class CustomStudentBaseDisplayFormPage(NigeriaStudentBaseDisplayFormPage):
57    """ Page to display student base data
58    """
59    form_fields = grok.AutoFields(ICustomStudentBase).omit(
60        'password', 'suspended', 'suspended_comment', 'flash_notice')
61
62class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage):
63    """ View to manage student base data
64    """
65    form_fields = grok.AutoFields(ICustomStudentBase).omit(
[15870]66        'student_id', 'adm_code', 'suspended',
67        'financially_cleared_by', 'financial_clearance_date')
[15704]68
69class StudentBaseEditFormPage(NigeriaStudentBaseEditFormPage):
70    """ View to edit student base data
71    """
72    form_fields = grok.AutoFields(ICustomStudentBase).select(
73        'email', 'email2', 'parents_email', 'phone',)
74
[15696]75class CustomExportPDFCourseRegistrationSlip(
76    NigeriaExportPDFCourseRegistrationSlip):
77    """Deliver a PDF slip of the context.
78    """
79
80    def _signatures(self):
81        return (
82                ['Student Signature'],
83                ['HoD / Course Adviser Signature'],
84                ['College Officer Signature'],
85                ['Dean Signature']
86                )
87
88    #def _sigsInFooter(self):
89    #    return (_('Student'),
90    #            _('HoD / Course Adviser'),
91    #            _('College Officer'),
92    #            _('Dean'),
93    #            )
[15720]94    #    return ()
95
[15999]96class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage):
97    """ Page to view bed tickets.
98    """
99    with_hostel_selection = True
100
[15722]101class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage):
102    """ Page to manage bed tickets.
103    This manage form page is for both students and students officers.
104    """
105    with_hostel_selection = True
106
[15720]107class CustomBedTicketAddPage(NigeriaBedTicketAddPage):
108    """ Page to add a bed ticket
109    """
110    with_ac = False
[15802]111    with_bedselection = True
112
113class StudentGetMatricNumberPage(UtilityView, grok.View):
114    """ Construct and set the matriculation number.
115    """
116    grok.context(IStudent)
117    grok.name('get_matric_number')
[15805]118    grok.require('waeup.manageStudent')
[15802]119
120    def update(self):
121        students_utils = getUtility(IStudentsUtils)
122        msg, mnumber = students_utils.setMatricNumber(self.context)
123        if msg:
124            self.flash(msg, type="danger")
125        else:
126            self.flash(_('Matriculation number %s assigned.' % mnumber))
127            self.context.writeLogMessage(self, '%s assigned' % mnumber)
128        self.redirect(self.url(self.context))
129        return
130
131    def render(self):
[15859]132        return
133
134class SwitchLibraryAccessView(UtilityView, grok.View):
135    """ Switch the library attribute
136    """
137    grok.context(ICustomStudent)
138    grok.name('switch_library_access')
139    grok.require('waeup.switchLibraryAccess')
140
141    def update(self):
142        if self.context.library:
143            self.context.library = False
144            self.context.writeLogMessage(self, 'library access disabled')
145            self.flash(_('Library access disabled'))
146        else:
147            self.context.library = True
148            self.context.writeLogMessage(self, 'library access enabled')
149            self.flash(_('Library access enabled'))
150        self.redirect(self.url(self.context))
151        return
152
153    def render(self):
154        return
155
156class ExportLibIdCard(UtilityView, grok.View):
157    """Deliver an id card for the library.
158    """
159    grok.context(ICustomStudent)
160    grok.name('lib_idcard.pdf')
161    grok.require('waeup.viewStudent')
162    prefix = 'form'
163
164    label = u"Library Clearance"
165
166    omit_fields = (
167        'suspended', 'email', 'phone',
168        'adm_code', 'suspended_comment',
169        'date_of_birth',
170        'current_mode', 'certificate',
171        'entry_session',
172        'flash_notice')
173
174    form_fields = []
175
176    def _sigsInFooter(self):
177        isStudent = getattr(
178            self.request.principal, 'user_type', None) == 'student'
179        if isStudent:
180            return ''
181        return (_("Date, Reader's Signature"),
182                _("Date, Circulation Librarian's Signature"),
183                )
184
185    def update(self):
186        if not self.context.library:
187            self.flash(_('Forbidden!'), type="danger")
188            self.redirect(self.url(self.context))
189        return
190
191    @property
192    def note(self):
193        return """
194<br /><br /><br /><br /><font size='12'>
195This is to certify that the bearer whose photograph and other details appear
196 overleaf is a registered user of the <b>University Library</b>.
197 The card is not transferable. A replacement fee is charged for a loss,
198 mutilation or otherwise. If found, please, return to the University Library,
199 Igbinedion University, Okada.
200</font>
201
202"""
203        return
204
205    def render(self):
206        studentview = StudentBasePDFFormPage(self.context.student,
207            self.request, self.omit_fields)
208        students_utils = getUtility(IStudentsUtils)
209        return students_utils.renderPDF(
210            self, 'lib_idcard',
211            self.context.student, studentview,
212            omit_fields=self.omit_fields,
213            sigs_in_footer=self._sigsInFooter(),
[15937]214            note=self.note)
215
216class CustomStartClearancePage(StartClearancePage):
217    with_ac = False
Note: See TracBrowser for help on using the repository browser.