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