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