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