[8911] | 1 | ## $Id: browser.py 15404 2019-05-08 12:58:00Z 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, |
---|
[15371] | 54 | NigeriaAccommodationManageFormPage, |
---|
| 55 | NigeriaStudentBaseDisplayFormPage, |
---|
[9281] | 56 | ) |
---|
[8911] | 57 | |
---|
[9210] | 58 | from waeup.uniben.students.interfaces import ( |
---|
[12121] | 59 | ICustomStudent, |
---|
[15352] | 60 | ICustomStudentBase, |
---|
[12856] | 61 | ICustomStudentOnlinePayment, |
---|
| 62 | ICustomStudentStudyCourse, |
---|
[11552] | 63 | ICustomStudentStudyLevel, |
---|
| 64 | ICustomUGStudentClearance, |
---|
[12856] | 65 | ICustomPGStudentClearance, |
---|
[13085] | 66 | ICustomStudentPersonal, |
---|
| 67 | ICustomStudentPersonalEdit) |
---|
[9210] | 68 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[8911] | 69 | |
---|
[15371] | 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 | |
---|
[8911] | 86 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
| 87 | """ Page to view an online payment ticket |
---|
| 88 | """ |
---|
| 89 | grok.context(ICustomStudentOnlinePayment) |
---|
[9775] | 90 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9993] | 91 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 92 | form_fields[ |
---|
| 93 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 94 | form_fields[ |
---|
| 95 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 96 | |
---|
[9380] | 97 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
| 98 | """ View to edit student clearance data by student |
---|
| 99 | """ |
---|
| 100 | |
---|
[11552] | 101 | @property |
---|
| 102 | def form_fields(self): |
---|
| 103 | if self.context.is_postgrad: |
---|
| 104 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit( |
---|
[12391] | 105 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment', |
---|
| 106 | 'physical_clearance_date') |
---|
[11552] | 107 | else: |
---|
| 108 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit( |
---|
[12391] | 109 | 'clearance_locked', 'clr_code', 'officer_comment', |
---|
| 110 | 'physical_clearance_date') |
---|
[11552] | 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 | |
---|
[9380] | 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.') |
---|
[9395] | 126 | #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'): |
---|
| 127 | # return _('No second sitting result uploaded.') |
---|
[9380] | 128 | if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'): |
---|
[9848] | 129 | return _('No affidavit of non-membership of secret cults uploaded.') |
---|
[9380] | 130 | return False |
---|
| 131 | |
---|
[8911] | 132 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
| 133 | """ Page to add an online payment ticket |
---|
| 134 | """ |
---|
| 135 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
| 136 | 'p_category') |
---|
| 137 | |
---|
[13063] | 138 | class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip): |
---|
[8911] | 139 | """Deliver a PDF slip of the context. |
---|
| 140 | """ |
---|
| 141 | grok.context(ICustomStudentOnlinePayment) |
---|
[9775] | 142 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9993] | 143 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 144 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9205] | 145 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 146 | |
---|
| 147 | |
---|
[13063] | 148 | class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip): |
---|
[9551] | 149 | """Deliver a PDF slip of the context. |
---|
| 150 | """ |
---|
| 151 | |
---|
[13303] | 152 | @property |
---|
| 153 | def omit_fields(self): |
---|
| 154 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
[13717] | 155 | 'phone', 'adm_code', 'email', 'date_of_birth', |
---|
| 156 | 'flash_notice') |
---|
[14902] | 157 | if self.context.is_jupeb: |
---|
[13303] | 158 | omit_fields += ('faculty', 'department') |
---|
| 159 | return omit_fields |
---|
[11537] | 160 | |
---|
[13299] | 161 | @property |
---|
| 162 | def label(self): |
---|
| 163 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13300] | 164 | line0 = '' |
---|
[14902] | 165 | if self.context.is_jupeb: |
---|
[13335] | 166 | line0 = 'Joint Universities Preliminary Examinations Board (JUPEB)\n' |
---|
[13300] | 167 | line1 = translate(_('Clearance Slip of'), |
---|
[13299] | 168 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 169 | + ' %s' % self.context.display_fullname |
---|
[13335] | 170 | return '%s%s' % (line0, line1) |
---|
[13299] | 171 | |
---|
[12846] | 172 | def _sigsInFooter(self): |
---|
[12845] | 173 | isStudent = getattr( |
---|
| 174 | self.request.principal, 'user_type', None) == 'student' |
---|
[12852] | 175 | if not isStudent and self.context.state in (CLEARED, RETURNING): |
---|
[12846] | 176 | return (_('Date, Student Signature'), |
---|
| 177 | _('Date, Clearance Officer Signature'), |
---|
| 178 | ) |
---|
| 179 | return () |
---|
[12845] | 180 | |
---|
[9551] | 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(), |
---|
[10271] | 188 | sigs_in_footer=self._sigsInFooter(), show_scans=False, |
---|
| 189 | omit_fields=self.omit_fields) |
---|
[9551] | 190 | |
---|
[12121] | 191 | |
---|
[13063] | 192 | class ExportClearanceInvitationSlip(UtilityView, grok.View): |
---|
[12121] | 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 | |
---|
[12263] | 202 | label = u'Invitation Letter for Physical Clearance' |
---|
[12121] | 203 | |
---|
| 204 | omit_fields = ( |
---|
| 205 | 'suspended', 'phone', 'email', |
---|
| 206 | 'adm_code', 'suspended_comment', |
---|
| 207 | 'date_of_birth', 'current_level', |
---|
[12150] | 208 | 'department', 'current_mode', |
---|
[13717] | 209 | 'entry_session', 'matric_number', 'sex', |
---|
| 210 | 'flash_notice') |
---|
[12121] | 211 | |
---|
| 212 | form_fields = [] |
---|
| 213 | |
---|
| 214 | @property |
---|
| 215 | def note(self): |
---|
| 216 | if self.context.physical_clearance_date: |
---|
| 217 | return """ |
---|
[12147] | 218 | <br /><br /><br /><br /><font size='12'> |
---|
| 219 | Dear %s, |
---|
| 220 | <br /><br /><br /> |
---|
[12264] | 221 | You are invited for your physical clearance on: |
---|
[12121] | 222 | <br /><br /> |
---|
[12264] | 223 | <strong>%s</strong>. |
---|
| 224 | <br /><br /> |
---|
[12265] | 225 | Please bring along this letter of invitation to the University Main Auditorium |
---|
[12147] | 226 | <br /><br /> |
---|
[12263] | 227 | on your clearance date. |
---|
[12147] | 228 | <br /><br /><br /> |
---|
[12263] | 229 | Signed, |
---|
[12147] | 230 | <br /><br /> |
---|
| 231 | The Registrar<br /> |
---|
[12121] | 232 | </font> |
---|
| 233 | |
---|
[12147] | 234 | """ % (self.context.display_fullname, self.context.physical_clearance_date) |
---|
[12121] | 235 | return |
---|
| 236 | |
---|
[12122] | 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 | |
---|
[12121] | 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 | |
---|
[13723] | 254 | class ExportExaminationScheduleSlip(UtilityView, grok.View): |
---|
| 255 | """Deliver a examination schedule slip. |
---|
| 256 | |
---|
[14689] | 257 | This form page is available only in Uniben and AAUE. |
---|
[13723] | 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 | |
---|
[15371] | 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 | |
---|
[15352] | 327 | class ExportJHLIdCard(UtilityView, grok.View): |
---|
[15371] | 328 | """Deliver an id card for the John Harris Library. |
---|
[15352] | 329 | """ |
---|
| 330 | grok.context(ICustomStudent) |
---|
| 331 | grok.name('jhl_idcard.pdf') |
---|
| 332 | grok.require('waeup.viewStudent') |
---|
| 333 | prefix = 'form' |
---|
| 334 | |
---|
[15403] | 335 | label = u"John Harris Library Clearance" |
---|
[15352] | 336 | |
---|
| 337 | omit_fields = ( |
---|
[15371] | 338 | 'suspended', 'email', 'phone', |
---|
[15352] | 339 | 'adm_code', 'suspended_comment', |
---|
[15371] | 340 | 'date_of_birth', |
---|
[15352] | 341 | 'current_mode', 'certificate', |
---|
| 342 | 'entry_session', |
---|
| 343 | 'flash_notice') |
---|
| 344 | |
---|
| 345 | form_fields = [] |
---|
| 346 | |
---|
| 347 | def _sigsInFooter(self): |
---|
[15371] | 348 | isStudent = getattr( |
---|
| 349 | self.request.principal, 'user_type', None) == 'student' |
---|
| 350 | if isStudent: |
---|
| 351 | return '' |
---|
[15352] | 352 | return (_("Date, Reader's Signature"), |
---|
| 353 | _("Date, Circulation Librarian's Signature"), |
---|
| 354 | ) |
---|
| 355 | |
---|
[15371] | 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 | |
---|
[15352] | 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 | |
---|
[14834] | 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): |
---|
[14902] | 411 | if not self.context.flash_notice or not self.context.is_jupeb \ |
---|
[14835] | 412 | or not 'results' in self.context.flash_notice.lower(): |
---|
[14834] | 413 | self.flash(_('Forbidden'), type="warning") |
---|
| 414 | self.redirect(self.url(self.context)) |
---|
| 415 | |
---|
[12856] | 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 | |
---|
[13085] | 437 | class CstomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage): |
---|
| 438 | """ Page to edit personal data |
---|
| 439 | """ |
---|
| 440 | form_fields = grok.AutoFields( |
---|
| 441 | ICustomStudentPersonalEdit).omit('personal_updated') |
---|
| 442 | |
---|
[9210] | 443 | class StudyCourseCOEditFormPage(KofaEditFormPage): |
---|
[9281] | 444 | """ Page to edit the student study course data by clearance officers. |
---|
[9210] | 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__)) |
---|
[9281] | 473 | return |
---|
| 474 | |
---|
| 475 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
| 476 | """ Page to edit the student study level data by students. |
---|
| 477 | |
---|
| 478 | """ |
---|
[9686] | 479 | grok.template('studyleveleditpage') |
---|
[9281] | 480 | |
---|
[9686] | 481 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
| 482 | """ Page to display student study levels |
---|
| 483 | """ |
---|
| 484 | grok.template('studylevelpage') |
---|
| 485 | |
---|
[13063] | 486 | class CustomExportPDFCourseRegistrationSlip( |
---|
| 487 | ExportPDFCourseRegistrationSlip): |
---|
[9686] | 488 | """Deliver a PDF slip of the context. |
---|
| 489 | """ |
---|
| 490 | |
---|
[9921] | 491 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
[15404] | 492 | 'level_verdict', 'gpa', 'level', 'transcript_remark') |
---|
[9921] | 493 | |
---|
[12855] | 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 | |
---|
[10441] | 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 | |
---|
[9686] | 518 | def render(self): |
---|
| 519 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9909] | 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) |
---|
[9686] | 525 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 526 | self.request, self.omit_fields) |
---|
| 527 | students_utils = getUtility(IStudentsUtils) |
---|
[10441] | 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 | ]) |
---|
[9686] | 540 | return students_utils.renderPDF( |
---|
| 541 | self, 'course_registration_slip.pdf', |
---|
| 542 | self.context.student, studentview, |
---|
[10441] | 543 | tableheader=tableheader, |
---|
| 544 | tabledata=tabledata, |
---|
[10271] | 545 | omit_fields=self.omit_fields |
---|
[9908] | 546 | ) |
---|
[9848] | 547 | |
---|
[15401] | 548 | class ExportPDFCourseResultSlip(ExportPDFCourseRegistrationSlip): |
---|
[9848] | 549 | """Deliver a PDF slip of the context. |
---|
| 550 | """ |
---|
| 551 | |
---|
| 552 | grok.name('course_result_slip.pdf') |
---|
| 553 | |
---|
[15401] | 554 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit('level') |
---|
| 555 | |
---|
[9848] | 556 | @property |
---|
[10441] | 557 | def tabletitle(self): |
---|
| 558 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 559 | tabletitle = [] |
---|
| 560 | tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa', |
---|
| 561 | target_language=portal_language)) |
---|
| 562 | tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa', |
---|
| 563 | target_language=portal_language)) |
---|
| 564 | tabletitle.append(translate(_('Level Courses'), 'waeup.kofa', |
---|
| 565 | target_language=portal_language)) |
---|
| 566 | tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa', |
---|
| 567 | target_language=portal_language)) |
---|
| 568 | tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa', |
---|
| 569 | target_language=portal_language)) |
---|
| 570 | tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa', |
---|
| 571 | target_language=portal_language)) |
---|
| 572 | return tabletitle |
---|
| 573 | |
---|
| 574 | @property |
---|
[9848] | 575 | def label(self): |
---|
| 576 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 577 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
| 578 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
| 579 | target_language=lang) |
---|
| 580 | return translate(_('Course Result Slip'), |
---|
| 581 | 'waeup.uniben', target_language=portal_language) \ |
---|
| 582 | + ' %s' % level_title |
---|
| 583 | |
---|
| 584 | def render(self): |
---|
| 585 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9909] | 586 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
| 587 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
| 588 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
| 589 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
| 590 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
| 591 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
[9848] | 592 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 593 | self.request, self.omit_fields) |
---|
| 594 | students_utils = getUtility(IStudentsUtils) |
---|
[10441] | 595 | |
---|
| 596 | tabledata = [] |
---|
| 597 | tableheader = [] |
---|
| 598 | for i in range(1,7): |
---|
| 599 | tabledata.append(sorted( |
---|
| 600 | [value for value in self.context.values() if value.semester == i], |
---|
| 601 | key=lambda value: str(value.semester) + value.code)) |
---|
| 602 | tableheader.append([(Code,'code', 2.5), |
---|
| 603 | (Title,'title', 5), |
---|
| 604 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
| 605 | (Cred, 'credits', 1.5), |
---|
| 606 | (Grade, 'grade', 1.5), |
---|
| 607 | ]) |
---|
[9908] | 608 | return students_utils.renderPDF( |
---|
[15401] | 609 | self, 'course_result_slip.pdf', |
---|
[9908] | 610 | self.context.student, studentview, |
---|
[10441] | 611 | tableheader=tableheader, |
---|
| 612 | tabledata=tabledata, |
---|
[10271] | 613 | omit_fields=self.omit_fields |
---|
[9908] | 614 | ) |
---|
[9686] | 615 | |
---|
| 616 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
| 617 | """ Page to display course tickets |
---|
| 618 | """ |
---|
| 619 | form_fields = grok.AutoFields(ICourseTicket).omit('score') |
---|
[11069] | 620 | |
---|
[13063] | 621 | class CustomStudentActivateView(StudentActivateView): |
---|
[11069] | 622 | """ Activate student account |
---|
| 623 | """ |
---|
| 624 | |
---|
| 625 | def update(self): |
---|
| 626 | self.context.suspended = False |
---|
| 627 | self.context.writeLogMessage(self, 'account activated') |
---|
| 628 | history = IObjectHistory(self.context) |
---|
| 629 | history.addMessage('Student account activated', user='undisclosed') |
---|
| 630 | self.flash(_('Student account has been activated.')) |
---|
| 631 | self.redirect(self.url(self.context)) |
---|
| 632 | return |
---|
| 633 | |
---|
[13063] | 634 | class CustomStudentDeactivateView(StudentDeactivateView): |
---|
[11069] | 635 | """ Deactivate student account |
---|
| 636 | """ |
---|
| 637 | def update(self): |
---|
| 638 | self.context.suspended = True |
---|
| 639 | self.context.writeLogMessage(self, 'account deactivated') |
---|
| 640 | history = IObjectHistory(self.context) |
---|
| 641 | history.addMessage('Student account deactivated', user='undisclosed') |
---|
| 642 | self.flash(_('Student account has been deactivated.')) |
---|
| 643 | self.redirect(self.url(self.context)) |
---|
| 644 | return |
---|
[12845] | 645 | |
---|
[13063] | 646 | class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip): |
---|
[12845] | 647 | """Deliver a PDF slip of the context. |
---|
| 648 | """ |
---|
| 649 | |
---|
[15164] | 650 | #def _sigsInFooter(self): |
---|
| 651 | # isStudent = getattr( |
---|
| 652 | # self.request.principal, 'user_type', None) == 'student' |
---|
| 653 | # if not isStudent: |
---|
| 654 | # return (_('D. R. (Exams & Records)'),_('Current Dean of Faculty'),) |
---|
| 655 | # return () |
---|
[12845] | 656 | |
---|
[14689] | 657 | #def _signatures(self): |
---|
| 658 | # return ([( |
---|
| 659 | # 'Current HD<br /> D. R. (Exams & Records)<br /> ' |
---|
| 660 | # 'For: Registrar')],) |
---|
[12845] | 661 | |
---|
| 662 | def render(self): |
---|
| 663 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 664 | Term = translate(_('Term'), 'waeup.kofa', target_language=portal_language) |
---|
| 665 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
| 666 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
| 667 | Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language) |
---|
| 668 | #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
| 669 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
---|
| 670 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 671 | self.request, self.omit_fields) |
---|
| 672 | students_utils = getUtility(IStudentsUtils) |
---|
| 673 | |
---|
| 674 | tableheader = [(Code,'code', 2.5), |
---|
| 675 | (Title,'title', 8.5), |
---|
| 676 | (Term, 'semester', 1.5), |
---|
| 677 | (Cred, 'credits', 1.5), |
---|
| 678 | #(Score, 'score', 1.5), |
---|
| 679 | (Grade, 'grade', 1.5), |
---|
| 680 | ] |
---|
| 681 | |
---|
[15164] | 682 | pdfstream = students_utils.renderPDFTranscript( |
---|
[12845] | 683 | self, 'transcript.pdf', |
---|
| 684 | self.context.student, studentview, |
---|
| 685 | omit_fields=self.omit_fields, |
---|
| 686 | tableheader=tableheader, |
---|
| 687 | signatures=self._signatures(), |
---|
| 688 | sigs_in_footer=self._sigsInFooter(), |
---|
[15164] | 689 | digital_sigs=self._digital_sigs(), |
---|
| 690 | save_file=self._save_file(), |
---|
[13297] | 691 | ) |
---|
[15164] | 692 | if not pdfstream: |
---|
| 693 | self.redirect(self.url(self.context.student)) |
---|
| 694 | return |
---|
| 695 | return pdfstream |
---|
[13297] | 696 | |
---|
| 697 | class CustomExportPDFBedTicketSlip(NigeriaExportPDFBedTicketSlip): |
---|
| 698 | """Deliver a PDF slip of the context. |
---|
| 699 | """ |
---|
[13317] | 700 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
[13717] | 701 | 'phone', 'adm_code', 'email', 'date_of_birth', 'flash_notice') |
---|
[13297] | 702 | |
---|
[13719] | 703 | class CustomPaymentsManageFormPage(PaymentsManageFormPage): |
---|
| 704 | """ Page to manage the student payments. This manage form page is for |
---|
| 705 | both students and students officers. Uniben does not allow students |
---|
| 706 | to remove any payment ticket. |
---|
| 707 | """ |
---|
| 708 | @property |
---|
| 709 | def manage_payments_allowed(self): |
---|
[13723] | 710 | return checkPermission('waeup.manageStudent', self.context) |
---|
[15267] | 711 | |
---|
| 712 | class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage): |
---|
| 713 | """ Page to manage bed tickets. |
---|
| 714 | This manage form page is for both students and students officers. |
---|
| 715 | """ |
---|
[15352] | 716 | with_hostel_selection = True |
---|
| 717 | |
---|
| 718 | class CustomStudentBaseEditFormPage(StudentBaseEditFormPage): |
---|
| 719 | """ View to edit student base data |
---|
| 720 | """ |
---|
| 721 | form_fields = grok.AutoFields(ICustomStudentBase).select( |
---|
| 722 | 'email', 'phone') |
---|
| 723 | form_fields['email'].field.required = True |
---|