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