1 | ## $Id: browser.py 15975 2020-01-31 21:52: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.security import checkPermission |
---|
21 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
22 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
23 | from zope.component import getUtility |
---|
24 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
25 | from waeup.kofa.interfaces import ( |
---|
26 | REQUESTED, IExtFileStore, IKofaUtils, IObjectHistory) |
---|
27 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
28 | from waeup.kofa.browser.layout import action, KofaEditFormPage, UtilityView |
---|
29 | from waeup.kofa.students.browser import ( |
---|
30 | StudentBaseEditFormPage, |
---|
31 | StudyLevelEditFormPage, StudyLevelDisplayFormPage, |
---|
32 | StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip, |
---|
33 | CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage, |
---|
34 | msave, emit_lock_message, |
---|
35 | StudentActivateView, StudentDeactivateView, |
---|
36 | ExportPDFTranscriptSlip, |
---|
37 | PaymentsManageFormPage, |
---|
38 | StartClearancePage) |
---|
39 | from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID, |
---|
40 | CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED, |
---|
41 | GRADUATED, FORBIDDEN_POSTGRAD_TRANS) |
---|
42 | from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket |
---|
43 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS |
---|
44 | from kofacustom.nigeria.students.browser import ( |
---|
45 | NigeriaOnlinePaymentDisplayFormPage, |
---|
46 | NigeriaStudentBaseManageFormPage, |
---|
47 | NigeriaStudentClearanceEditFormPage, |
---|
48 | NigeriaOnlinePaymentAddFormPage, |
---|
49 | NigeriaExportPDFPaymentSlip, |
---|
50 | NigeriaExportPDFClearanceSlip, |
---|
51 | NigeriaExportPDFBedTicketSlip, |
---|
52 | NigeriaStudentPersonalDisplayFormPage, |
---|
53 | NigeriaStudentPersonalManageFormPage, |
---|
54 | NigeriaStudentPersonalEditFormPage, |
---|
55 | NigeriaAccommodationManageFormPage, |
---|
56 | NigeriaAccommodationDisplayFormPage, |
---|
57 | NigeriaStudentBaseDisplayFormPage, |
---|
58 | ) |
---|
59 | |
---|
60 | from waeup.uniben.students.interfaces import ( |
---|
61 | ICustomStudent, |
---|
62 | ICustomStudentBase, |
---|
63 | ICustomStudentOnlinePayment, |
---|
64 | ICustomStudentStudyCourse, |
---|
65 | ICustomStudentStudyLevel, |
---|
66 | ICustomUGStudentClearance, |
---|
67 | ICustomPGStudentClearance, |
---|
68 | ICustomStudentPersonal, |
---|
69 | ICustomStudentPersonalEdit) |
---|
70 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
71 | |
---|
72 | class CustomStudentBaseDisplayFormPage(NigeriaStudentBaseDisplayFormPage): |
---|
73 | """ Page to display student base data |
---|
74 | """ |
---|
75 | form_fields = grok.AutoFields(ICustomStudentBase).omit( |
---|
76 | 'password', 'suspended', 'suspended_comment', |
---|
77 | 'flash_notice', 'provisionally_cleared') |
---|
78 | form_fields[ |
---|
79 | 'financial_clearance_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
80 | |
---|
81 | #class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage): |
---|
82 | # """ View to manage student base data |
---|
83 | # """ |
---|
84 | # form_fields = grok.AutoFields(ICustomStudentBase).omit( |
---|
85 | # 'student_id', 'adm_code', 'suspended', |
---|
86 | # 'financially_cleared_by', 'financial_clearance_date') |
---|
87 | |
---|
88 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
89 | """ Page to view an online payment ticket |
---|
90 | """ |
---|
91 | grok.context(ICustomStudentOnlinePayment) |
---|
92 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
93 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
94 | form_fields[ |
---|
95 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
96 | form_fields[ |
---|
97 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
98 | |
---|
99 | class CustomStartClearancePage(StartClearancePage): |
---|
100 | |
---|
101 | @property |
---|
102 | def with_ac(self): |
---|
103 | if self.context.faccode == 'DCOEM': |
---|
104 | return False |
---|
105 | return True |
---|
106 | |
---|
107 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
108 | """ View to edit student clearance data by student |
---|
109 | """ |
---|
110 | |
---|
111 | @property |
---|
112 | def form_fields(self): |
---|
113 | if self.context.is_postgrad: |
---|
114 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit( |
---|
115 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment', |
---|
116 | 'physical_clearance_date') |
---|
117 | else: |
---|
118 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit( |
---|
119 | 'clearance_locked', 'clr_code', 'officer_comment', |
---|
120 | 'physical_clearance_date') |
---|
121 | form_fields['date_of_birth'].for_display = True |
---|
122 | form_fields['nationality'].for_display = True |
---|
123 | form_fields['lga'].for_display = True |
---|
124 | return form_fields |
---|
125 | |
---|
126 | def dataNotComplete(self): |
---|
127 | store = getUtility(IExtFileStore) |
---|
128 | if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'): |
---|
129 | return _('No birth certificate uploaded.') |
---|
130 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
131 | return _('No guarantor/referee letter uploaded.') |
---|
132 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
133 | return _('No acceptance letter uploaded.') |
---|
134 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
135 | return _('No first sitting result uploaded.') |
---|
136 | #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'): |
---|
137 | # return _('No second sitting result uploaded.') |
---|
138 | if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'): |
---|
139 | return _('No affidavit of non-membership of secret cults uploaded.') |
---|
140 | return False |
---|
141 | |
---|
142 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
143 | """ Page to add an online payment ticket |
---|
144 | """ |
---|
145 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
146 | 'p_combi') |
---|
147 | |
---|
148 | class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip): |
---|
149 | """Deliver a PDF slip of the context. |
---|
150 | """ |
---|
151 | grok.context(ICustomStudentOnlinePayment) |
---|
152 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
153 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi') |
---|
154 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
155 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
156 | |
---|
157 | |
---|
158 | class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip): |
---|
159 | """Deliver a PDF slip of the context. |
---|
160 | """ |
---|
161 | |
---|
162 | @property |
---|
163 | def omit_fields(self): |
---|
164 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
165 | 'phone', 'adm_code', 'email', 'date_of_birth', |
---|
166 | 'flash_notice') |
---|
167 | if self.context.is_jupeb: |
---|
168 | omit_fields += ('faculty', 'department') |
---|
169 | return omit_fields |
---|
170 | |
---|
171 | @property |
---|
172 | def label(self): |
---|
173 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
174 | line0 = '' |
---|
175 | if self.context.is_jupeb: |
---|
176 | line0 = 'Joint Universities Preliminary Examinations Board (JUPEB)\n' |
---|
177 | line1 = translate(_('Clearance Slip of'), |
---|
178 | 'waeup.kofa', target_language=portal_language) \ |
---|
179 | + ' %s' % self.context.display_fullname |
---|
180 | return '%s%s' % (line0, line1) |
---|
181 | |
---|
182 | def _sigsInFooter(self): |
---|
183 | isStudent = getattr( |
---|
184 | self.request.principal, 'user_type', None) == 'student' |
---|
185 | if not isStudent and self.context.state in (CLEARED, RETURNING): |
---|
186 | return (_('Date, Student Signature'), |
---|
187 | _('Date, Clearance Officer Signature'), |
---|
188 | ) |
---|
189 | return () |
---|
190 | |
---|
191 | def render(self): |
---|
192 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
193 | self.request, self.omit_fields) |
---|
194 | students_utils = getUtility(IStudentsUtils) |
---|
195 | return students_utils.renderPDF( |
---|
196 | self, 'clearance_slip.pdf', |
---|
197 | self.context.student, studentview, signatures=self._signatures(), |
---|
198 | sigs_in_footer=self._sigsInFooter(), show_scans=False, |
---|
199 | omit_fields=self.omit_fields) |
---|
200 | |
---|
201 | |
---|
202 | class ExportClearanceInvitationSlip(UtilityView, grok.View): |
---|
203 | """Deliver an invitation letter to physical clearance. |
---|
204 | |
---|
205 | This form page is available only in Uniben. |
---|
206 | """ |
---|
207 | grok.context(ICustomStudent) |
---|
208 | grok.name('clearance_invitation_slip.pdf') |
---|
209 | grok.require('waeup.viewStudent') |
---|
210 | prefix = 'form' |
---|
211 | |
---|
212 | label = u'Invitation Letter for Physical Clearance' |
---|
213 | |
---|
214 | omit_fields = ( |
---|
215 | 'suspended', 'phone', 'email', |
---|
216 | 'adm_code', 'suspended_comment', |
---|
217 | 'date_of_birth', 'current_level', |
---|
218 | 'department', 'current_mode', |
---|
219 | 'entry_session', 'matric_number', 'sex', |
---|
220 | 'flash_notice') |
---|
221 | |
---|
222 | form_fields = [] |
---|
223 | |
---|
224 | @property |
---|
225 | def note(self): |
---|
226 | if self.context.physical_clearance_date: |
---|
227 | return """ |
---|
228 | <br /><br /><br /><br /><font size='12'> |
---|
229 | Dear %s, |
---|
230 | <br /><br /><br /> |
---|
231 | You are invited for your physical clearance on: |
---|
232 | <br /><br /> |
---|
233 | <strong>%s</strong>. |
---|
234 | <br /><br /> |
---|
235 | Please bring along this letter of invitation to the University Main Auditorium |
---|
236 | <br /><br /> |
---|
237 | on your clearance date. |
---|
238 | <br /><br /><br /> |
---|
239 | Signed, |
---|
240 | <br /><br /> |
---|
241 | The Registrar<br /> |
---|
242 | </font> |
---|
243 | |
---|
244 | """ % (self.context.display_fullname, self.context.physical_clearance_date) |
---|
245 | return |
---|
246 | |
---|
247 | |
---|
248 | def update(self): |
---|
249 | if self.context.student.state != REQUESTED \ |
---|
250 | or not self.context.student.physical_clearance_date: |
---|
251 | self.flash(_('Forbidden'), type="warning") |
---|
252 | self.redirect(self.url(self.context)) |
---|
253 | |
---|
254 | def render(self): |
---|
255 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
256 | self.request, self.omit_fields) |
---|
257 | students_utils = getUtility(IStudentsUtils) |
---|
258 | return students_utils.renderPDF( |
---|
259 | self, 'clearance_invitation_slip', |
---|
260 | self.context.student, studentview, |
---|
261 | omit_fields=self.omit_fields, |
---|
262 | note=self.note) |
---|
263 | |
---|
264 | class ExportExaminationScheduleSlip(UtilityView, grok.View): |
---|
265 | """Deliver a examination schedule slip. |
---|
266 | |
---|
267 | This form page is available only in Uniben and AAUE. |
---|
268 | """ |
---|
269 | grok.context(ICustomStudent) |
---|
270 | grok.name('examination_schedule_slip.pdf') |
---|
271 | grok.require('waeup.viewStudent') |
---|
272 | prefix = 'form' |
---|
273 | |
---|
274 | label = u'Examination Schedule Slip' |
---|
275 | |
---|
276 | omit_fields = ( |
---|
277 | 'suspended', 'phone', 'email', |
---|
278 | 'adm_code', 'suspended_comment', |
---|
279 | 'date_of_birth', 'current_level', |
---|
280 | 'current_mode', |
---|
281 | 'entry_session', |
---|
282 | 'flash_notice') |
---|
283 | |
---|
284 | form_fields = [] |
---|
285 | |
---|
286 | @property |
---|
287 | def note(self): |
---|
288 | return """ |
---|
289 | <br /><br /><br /><br /><font size='12'> |
---|
290 | Your examination date, time and venue is scheduled as follows: |
---|
291 | <br /><br /> |
---|
292 | <strong>%s</strong> |
---|
293 | </font> |
---|
294 | |
---|
295 | """ % self.context.flash_notice |
---|
296 | return |
---|
297 | |
---|
298 | |
---|
299 | def update(self): |
---|
300 | if not self.context.flash_notice \ |
---|
301 | or not 'exam' in self.context.flash_notice.lower(): |
---|
302 | self.flash(_('Forbidden'), type="warning") |
---|
303 | self.redirect(self.url(self.context)) |
---|
304 | |
---|
305 | def render(self): |
---|
306 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
307 | self.request, self.omit_fields) |
---|
308 | students_utils = getUtility(IStudentsUtils) |
---|
309 | return students_utils.renderPDF( |
---|
310 | self, 'examination_schedule_slip', |
---|
311 | self.context.student, studentview, |
---|
312 | omit_fields=self.omit_fields, |
---|
313 | note=self.note) |
---|
314 | |
---|
315 | class SwitchLibraryAccessView(UtilityView, grok.View): |
---|
316 | """ Switch the library attribute |
---|
317 | """ |
---|
318 | grok.context(ICustomStudent) |
---|
319 | grok.name('switch_library_access') |
---|
320 | grok.require('waeup.switchLibraryAccess') |
---|
321 | |
---|
322 | def update(self): |
---|
323 | if self.context.library: |
---|
324 | self.context.library = False |
---|
325 | self.context.writeLogMessage(self, 'library access disabled') |
---|
326 | self.flash(_('Library access disabled')) |
---|
327 | else: |
---|
328 | self.context.library = True |
---|
329 | self.context.writeLogMessage(self, 'library access enabled') |
---|
330 | self.flash(_('Library access enabled')) |
---|
331 | self.redirect(self.url(self.context)) |
---|
332 | return |
---|
333 | |
---|
334 | def render(self): |
---|
335 | return |
---|
336 | |
---|
337 | class ExportJHLIdCard(UtilityView, grok.View): |
---|
338 | """Deliver an id card for the John Harris Library. |
---|
339 | """ |
---|
340 | grok.context(ICustomStudent) |
---|
341 | grok.name('jhl_idcard.pdf') |
---|
342 | grok.require('waeup.viewStudent') |
---|
343 | prefix = 'form' |
---|
344 | |
---|
345 | label = u"John Harris Library Clearance" |
---|
346 | |
---|
347 | omit_fields = ( |
---|
348 | 'suspended', 'email', 'phone', |
---|
349 | 'adm_code', 'suspended_comment', |
---|
350 | 'date_of_birth', |
---|
351 | 'current_mode', 'certificate', |
---|
352 | 'entry_session', |
---|
353 | 'flash_notice') |
---|
354 | |
---|
355 | form_fields = [] |
---|
356 | |
---|
357 | def _sigsInFooter(self): |
---|
358 | isStudent = getattr( |
---|
359 | self.request.principal, 'user_type', None) == 'student' |
---|
360 | if isStudent: |
---|
361 | return '' |
---|
362 | return (_("Date, Reader's Signature"), |
---|
363 | _("Date, Circulation Librarian's Signature"), |
---|
364 | ) |
---|
365 | |
---|
366 | def update(self): |
---|
367 | if not self.context.library: |
---|
368 | self.flash(_('Forbidden!'), type="danger") |
---|
369 | self.redirect(self.url(self.context)) |
---|
370 | return |
---|
371 | |
---|
372 | @property |
---|
373 | def note(self): |
---|
374 | return """ |
---|
375 | <br /><br /><br /><br /><font size='12'> |
---|
376 | This is to certify that the bearer whose photograph and other details appear |
---|
377 | overleaf is a registered user of <b>John Harris Library, University of Benin</b>. |
---|
378 | The card is not transferable. A replacement fee is charged for a loss, |
---|
379 | mutilation or otherwise. If found, please, return to John Harris Library, |
---|
380 | University of Benin, Benin City. |
---|
381 | </font> |
---|
382 | |
---|
383 | """ |
---|
384 | return |
---|
385 | |
---|
386 | def render(self): |
---|
387 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
388 | self.request, self.omit_fields) |
---|
389 | students_utils = getUtility(IStudentsUtils) |
---|
390 | return students_utils.renderPDF( |
---|
391 | self, 'jhl_idcard', |
---|
392 | self.context.student, studentview, |
---|
393 | omit_fields=self.omit_fields, |
---|
394 | sigs_in_footer=self._sigsInFooter(), |
---|
395 | note=self.note) |
---|
396 | |
---|
397 | class ExportJUPEBResultSlip(ExportExaminationScheduleSlip): |
---|
398 | """Deliver a JUPEB result slip. |
---|
399 | |
---|
400 | This form page is available only in Uniben. |
---|
401 | """ |
---|
402 | |
---|
403 | grok.name('jupeb_result_slip.pdf') |
---|
404 | label = u'JUPEB Result Slip' |
---|
405 | |
---|
406 | @property |
---|
407 | def note(self): |
---|
408 | return """ |
---|
409 | <br /><br /><br /><br /><font size='12'> |
---|
410 | <strong>%s</strong> |
---|
411 | </font> |
---|
412 | <br /><br /><br /><br /> |
---|
413 | <font size='8'> |
---|
414 | Key: A = 5, B = 4, C = 3, D = 2, E = 1, F = 0, X = Absent, Q = Cancelled |
---|
415 | </font> |
---|
416 | |
---|
417 | """ % self.context.flash_notice |
---|
418 | return |
---|
419 | |
---|
420 | def update(self): |
---|
421 | if not self.context.flash_notice or not self.context.is_jupeb \ |
---|
422 | or not 'results' in self.context.flash_notice.lower(): |
---|
423 | self.flash(_('Forbidden'), type="warning") |
---|
424 | self.redirect(self.url(self.context)) |
---|
425 | |
---|
426 | class CustomStudentPersonalDisplayFormPage( |
---|
427 | NigeriaStudentPersonalDisplayFormPage): |
---|
428 | """ Page to display student personal data |
---|
429 | """ |
---|
430 | |
---|
431 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
432 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
433 | form_fields['next_kin_address'].custom_widget = BytesDisplayWidget |
---|
434 | form_fields[ |
---|
435 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
436 | |
---|
437 | class CustomStudentPersonalManageFormPage( |
---|
438 | NigeriaStudentPersonalManageFormPage): |
---|
439 | """ Page to manage personal data |
---|
440 | """ |
---|
441 | |
---|
442 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
443 | form_fields['personal_updated'].for_display = True |
---|
444 | form_fields[ |
---|
445 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
446 | |
---|
447 | class CstomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage): |
---|
448 | """ Page to edit personal data |
---|
449 | """ |
---|
450 | form_fields = grok.AutoFields( |
---|
451 | ICustomStudentPersonalEdit).omit('personal_updated') |
---|
452 | |
---|
453 | class StudyCourseCOEditFormPage(KofaEditFormPage): |
---|
454 | """ Page to edit the student study course data by clearance officers. |
---|
455 | |
---|
456 | This form page is available only in Uniben. |
---|
457 | """ |
---|
458 | grok.context(ICustomStudentStudyCourse) |
---|
459 | grok.name('edit_level') |
---|
460 | grok.require('waeup.clearStudent') |
---|
461 | label = _('Edit current level') |
---|
462 | pnav = 4 |
---|
463 | form_fields = grok.AutoFields( |
---|
464 | ICustomStudentStudyCourse).select('current_level') |
---|
465 | |
---|
466 | def update(self): |
---|
467 | if not (self.context.is_current and |
---|
468 | self.context.student.state == REQUESTED): |
---|
469 | emit_lock_message(self) |
---|
470 | return |
---|
471 | super(StudyCourseCOEditFormPage, self).update() |
---|
472 | return |
---|
473 | |
---|
474 | @action(_('Save'), style='primary') |
---|
475 | def save(self, **data): |
---|
476 | try: |
---|
477 | msave(self, **data) |
---|
478 | except ConstraintNotSatisfied: |
---|
479 | # The selected level might not exist in certificate |
---|
480 | self.flash(_('Current level not available for certificate.')) |
---|
481 | return |
---|
482 | #notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
---|
483 | return |
---|
484 | |
---|
485 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
486 | """ Page to edit the student study level data by students. |
---|
487 | |
---|
488 | """ |
---|
489 | grok.template('studyleveleditpage') |
---|
490 | |
---|
491 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
492 | """ Page to display student study levels |
---|
493 | """ |
---|
494 | grok.template('studylevelpage') |
---|
495 | |
---|
496 | class CustomExportPDFCourseRegistrationSlip( |
---|
497 | ExportPDFCourseRegistrationSlip): |
---|
498 | """Deliver a PDF slip of the context. |
---|
499 | """ |
---|
500 | |
---|
501 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
502 | 'level_verdict', 'gpa', 'level', 'transcript_remark') |
---|
503 | |
---|
504 | def update(self): |
---|
505 | if self.context.student.state != REGISTERED \ |
---|
506 | or self.context.student.current_level != self.context.level: |
---|
507 | self.flash(_('Forbidden'), type="warning") |
---|
508 | self.redirect(self.url(self.context)) |
---|
509 | |
---|
510 | @property |
---|
511 | def tabletitle(self): |
---|
512 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
513 | tabletitle = [] |
---|
514 | tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa', |
---|
515 | target_language=portal_language)) |
---|
516 | tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa', |
---|
517 | target_language=portal_language)) |
---|
518 | tabletitle.append(translate(_('Level Courses'), 'waeup.kofa', |
---|
519 | target_language=portal_language)) |
---|
520 | tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa', |
---|
521 | target_language=portal_language)) |
---|
522 | tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa', |
---|
523 | target_language=portal_language)) |
---|
524 | tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa', |
---|
525 | target_language=portal_language)) |
---|
526 | return tabletitle |
---|
527 | |
---|
528 | def render(self): |
---|
529 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
530 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
531 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
532 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
533 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
534 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
535 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
536 | self.request, self.omit_fields) |
---|
537 | students_utils = getUtility(IStudentsUtils) |
---|
538 | |
---|
539 | tabledata = [] |
---|
540 | tableheader = [] |
---|
541 | for i in range(1,7): |
---|
542 | tabledata.append(sorted( |
---|
543 | [value for value in self.context.values() if value.semester == i], |
---|
544 | key=lambda value: str(value.semester) + value.code)) |
---|
545 | tableheader.append([(Code,'code', 2.5), |
---|
546 | (Title,'title', 5), |
---|
547 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
548 | (Cred, 'credits', 1.5), |
---|
549 | ]) |
---|
550 | return students_utils.renderPDF( |
---|
551 | self, 'course_registration_slip.pdf', |
---|
552 | self.context.student, studentview, |
---|
553 | tableheader=tableheader, |
---|
554 | tabledata=tabledata, |
---|
555 | omit_fields=self.omit_fields |
---|
556 | ) |
---|
557 | |
---|
558 | class ExportPDFCourseResultSlip(ExportPDFCourseRegistrationSlip): |
---|
559 | """Deliver a PDF slip of the context. |
---|
560 | """ |
---|
561 | |
---|
562 | grok.name('course_result_slip.pdf') |
---|
563 | |
---|
564 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit('level') |
---|
565 | |
---|
566 | @property |
---|
567 | def tabletitle(self): |
---|
568 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
569 | tabletitle = [] |
---|
570 | tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa', |
---|
571 | target_language=portal_language)) |
---|
572 | tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa', |
---|
573 | target_language=portal_language)) |
---|
574 | tabletitle.append(translate(_('Level Courses'), 'waeup.kofa', |
---|
575 | target_language=portal_language)) |
---|
576 | tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa', |
---|
577 | target_language=portal_language)) |
---|
578 | tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa', |
---|
579 | target_language=portal_language)) |
---|
580 | tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa', |
---|
581 | target_language=portal_language)) |
---|
582 | return tabletitle |
---|
583 | |
---|
584 | @property |
---|
585 | def label(self): |
---|
586 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
587 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
588 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
589 | target_language=lang) |
---|
590 | return translate(_('Course Result Slip'), |
---|
591 | 'waeup.uniben', target_language=portal_language) \ |
---|
592 | + ' %s' % level_title |
---|
593 | |
---|
594 | def render(self): |
---|
595 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
596 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
597 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
598 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
599 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
600 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
601 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
602 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
603 | self.request, self.omit_fields) |
---|
604 | students_utils = getUtility(IStudentsUtils) |
---|
605 | |
---|
606 | tabledata = [] |
---|
607 | tableheader = [] |
---|
608 | for i in range(1,7): |
---|
609 | tabledata.append(sorted( |
---|
610 | [value for value in self.context.values() if value.semester == i], |
---|
611 | key=lambda value: str(value.semester) + value.code)) |
---|
612 | tableheader.append([(Code,'code', 2.5), |
---|
613 | (Title,'title', 5), |
---|
614 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
615 | (Cred, 'credits', 1.5), |
---|
616 | (Grade, 'grade', 1.5), |
---|
617 | ]) |
---|
618 | return students_utils.renderPDF( |
---|
619 | self, 'course_result_slip.pdf', |
---|
620 | self.context.student, studentview, |
---|
621 | tableheader=tableheader, |
---|
622 | tabledata=tabledata, |
---|
623 | omit_fields=self.omit_fields |
---|
624 | ) |
---|
625 | |
---|
626 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
627 | """ Page to display course tickets |
---|
628 | """ |
---|
629 | form_fields = grok.AutoFields(ICourseTicket).omit('score') |
---|
630 | |
---|
631 | class CustomStudentActivateView(StudentActivateView): |
---|
632 | """ Activate student account |
---|
633 | """ |
---|
634 | |
---|
635 | def update(self): |
---|
636 | self.context.suspended = False |
---|
637 | self.context.writeLogMessage(self, 'account activated') |
---|
638 | history = IObjectHistory(self.context) |
---|
639 | history.addMessage('Student account activated', user='undisclosed') |
---|
640 | self.flash(_('Student account has been activated.')) |
---|
641 | self.redirect(self.url(self.context)) |
---|
642 | return |
---|
643 | |
---|
644 | class CustomStudentDeactivateView(StudentDeactivateView): |
---|
645 | """ Deactivate student account |
---|
646 | """ |
---|
647 | def update(self): |
---|
648 | self.context.suspended = True |
---|
649 | self.context.writeLogMessage(self, 'account deactivated') |
---|
650 | history = IObjectHistory(self.context) |
---|
651 | history.addMessage('Student account deactivated', user='undisclosed') |
---|
652 | self.flash(_('Student account has been deactivated.')) |
---|
653 | self.redirect(self.url(self.context)) |
---|
654 | return |
---|
655 | |
---|
656 | class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip): |
---|
657 | """Deliver a PDF slip of the context. |
---|
658 | """ |
---|
659 | |
---|
660 | #def _sigsInFooter(self): |
---|
661 | # isStudent = getattr( |
---|
662 | # self.request.principal, 'user_type', None) == 'student' |
---|
663 | # if not isStudent: |
---|
664 | # return (_('D. R. (Exams & Records)'),_('Current Dean of Faculty'),) |
---|
665 | # return () |
---|
666 | |
---|
667 | #def _signatures(self): |
---|
668 | # return ([( |
---|
669 | # 'Current HD<br /> D. R. (Exams & Records)<br /> ' |
---|
670 | # 'For: Registrar')],) |
---|
671 | |
---|
672 | def render(self): |
---|
673 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
674 | Term = translate(_('Term'), 'waeup.kofa', target_language=portal_language) |
---|
675 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
676 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
677 | Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language) |
---|
678 | #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
679 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
---|
680 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
681 | self.request, self.omit_fields) |
---|
682 | students_utils = getUtility(IStudentsUtils) |
---|
683 | |
---|
684 | tableheader = [(Code,'code', 2.5), |
---|
685 | (Title,'title', 8.5), |
---|
686 | (Term, 'semester', 1.5), |
---|
687 | (Cred, 'credits', 1.5), |
---|
688 | #(Score, 'score', 1.5), |
---|
689 | (Grade, 'grade', 1.5), |
---|
690 | ] |
---|
691 | |
---|
692 | pdfstream = students_utils.renderPDFTranscript( |
---|
693 | self, 'transcript.pdf', |
---|
694 | self.context.student, studentview, |
---|
695 | omit_fields=self.omit_fields, |
---|
696 | tableheader=tableheader, |
---|
697 | signatures=self._signatures(), |
---|
698 | sigs_in_footer=self._sigsInFooter(), |
---|
699 | digital_sigs=self._digital_sigs(), |
---|
700 | save_file=self._save_file(), |
---|
701 | ) |
---|
702 | if not pdfstream: |
---|
703 | self.redirect(self.url(self.context.student)) |
---|
704 | return |
---|
705 | return pdfstream |
---|
706 | |
---|
707 | class CustomExportPDFBedTicketSlip(NigeriaExportPDFBedTicketSlip): |
---|
708 | """Deliver a PDF slip of the context. |
---|
709 | """ |
---|
710 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
711 | 'phone', 'adm_code', 'email', 'date_of_birth', 'flash_notice') |
---|
712 | |
---|
713 | class CustomPaymentsManageFormPage(PaymentsManageFormPage): |
---|
714 | """ Page to manage the student payments. This manage form page is for |
---|
715 | both students and students officers. Uniben does not allow students |
---|
716 | to remove any payment ticket. |
---|
717 | """ |
---|
718 | @property |
---|
719 | def manage_payments_allowed(self): |
---|
720 | return checkPermission('waeup.manageStudent', self.context) |
---|
721 | |
---|
722 | class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage): |
---|
723 | """ Page to view bed tickets. |
---|
724 | """ |
---|
725 | with_hostel_selection = True |
---|
726 | |
---|
727 | class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage): |
---|
728 | """ Page to manage bed tickets. |
---|
729 | This manage form page is for both students and students officers. |
---|
730 | """ |
---|
731 | with_hostel_selection = True |
---|
732 | |
---|
733 | class CustomStudentBaseEditFormPage(StudentBaseEditFormPage): |
---|
734 | """ View to edit student base data |
---|
735 | """ |
---|
736 | form_fields = grok.AutoFields(ICustomStudentBase).select( |
---|
737 | 'email', 'phone') |
---|
738 | form_fields['email'].field.required = True |
---|