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