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