| 1 | ## $Id: browser.py 18347 2026-10-25 17:24:17Z 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 | import csv |
|---|
| 20 | import textwrap |
|---|
| 21 | import pytz |
|---|
| 22 | from datetime import datetime, date |
|---|
| 23 | from cStringIO import StringIO |
|---|
| 24 | from zope.i18n import translate |
|---|
| 25 | from zope.schema.interfaces import ConstraintNotSatisfied |
|---|
| 26 | from zope.component import getUtility, queryUtility |
|---|
| 27 | from zope.catalog.interfaces import ICatalog |
|---|
| 28 | from zope.security import checkPermission |
|---|
| 29 | from zope.formlib.textwidgets import BytesDisplayWidget |
|---|
| 30 | from hurry.workflow.interfaces import IWorkflowInfo |
|---|
| 31 | from waeup.kofa.utils.helpers import now |
|---|
| 32 | from waeup.kofa.interfaces import ( |
|---|
| 33 | REQUESTED, IExtFileStore, IKofaUtils, academic_sessions_vocab) |
|---|
| 34 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
|---|
| 35 | from waeup.kofa.browser.layout import KofaEditFormPage, UtilityView |
|---|
| 36 | from waeup.kofa.browser.layout import action, jsaction |
|---|
| 37 | from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID, |
|---|
| 38 | CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED, |
|---|
| 39 | GRADUATED, TRANSREQ, TRANSVAL, TRANSREL, FORBIDDEN_POSTGRAD_TRANS) |
|---|
| 40 | from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket, IStudentBase |
|---|
| 41 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS |
|---|
| 42 | from waeup.kofa.students.browser import ( |
|---|
| 43 | StartClearancePage, |
|---|
| 44 | StudentBasePDFFormPage, |
|---|
| 45 | CourseTicketAddFormPage, |
|---|
| 46 | StudyLevelDisplayFormPage, |
|---|
| 47 | StudyLevelManageFormPage, |
|---|
| 48 | StudyLevelEditFormPage, |
|---|
| 49 | ExportPDFTranscriptSlip, |
|---|
| 50 | ExportPDFAdmissionSlip, |
|---|
| 51 | StudentFilesUploadPage, |
|---|
| 52 | PaymentsManageFormPage, |
|---|
| 53 | CourseTicketDisplayFormPage, |
|---|
| 54 | CourseTicketManageFormPage, |
|---|
| 55 | EditScoresPage, |
|---|
| 56 | ExportPDFScoresSlip, |
|---|
| 57 | StudyCourseTranscriptPage, |
|---|
| 58 | DownloadScoresView, |
|---|
| 59 | StudentRequestPasswordPage, |
|---|
| 60 | StudyCourseManageFormPage, |
|---|
| 61 | UnregisterCoursesView, |
|---|
| 62 | addCourseTicket, |
|---|
| 63 | AddStudyLevelFormPage, |
|---|
| 64 | ExportPDFCourseRegistrationSlip, |
|---|
| 65 | ExportAttendanceSlip, |
|---|
| 66 | emit_lock_message,) |
|---|
| 67 | from kofacustom.nigeria.students.browser import ( |
|---|
| 68 | NigeriaOnlinePaymentDisplayFormPage, |
|---|
| 69 | NigeriaStudentBaseDisplayFormPage, |
|---|
| 70 | NigeriaStudentBaseManageFormPage, |
|---|
| 71 | NigeriaStudentClearanceEditFormPage, |
|---|
| 72 | NigeriaStudentClearanceDisplayFormPage, |
|---|
| 73 | NigeriaStudentClearanceManageFormPage, |
|---|
| 74 | NigeriaOnlinePaymentAddFormPage, |
|---|
| 75 | NigeriaExportPDFPaymentSlip, |
|---|
| 76 | NigeriaExportPDFClearanceSlip, |
|---|
| 77 | NigeriaBedTicketAddPage, |
|---|
| 78 | NigeriaAccommodationDisplayFormPage, |
|---|
| 79 | NigeriaAccommodationManageFormPage, |
|---|
| 80 | ) |
|---|
| 81 | from kofacustom.unidel.students.interfaces import ( |
|---|
| 82 | ICustomStudent, |
|---|
| 83 | ICustomStudentBase, |
|---|
| 84 | ICustomStudentOnlinePayment, |
|---|
| 85 | ICustomStudentStudyCourse, |
|---|
| 86 | ICustomStudentStudyLevel, |
|---|
| 87 | ICustomUGStudentClearance, |
|---|
| 88 | ICustomPGStudentClearance, |
|---|
| 89 | ICustomCourseTicket) |
|---|
| 90 | from kofacustom.unidel.interfaces import MessageFactory as _ |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | def translated_values(view): |
|---|
| 94 | """Translate course ticket attribute values to be displayed on |
|---|
| 95 | studylevel pages. |
|---|
| 96 | """ |
|---|
| 97 | lang = view.request.cookies.get('kofa.language') |
|---|
| 98 | for value in view.context.values(): |
|---|
| 99 | value._p_activate() |
|---|
| 100 | value_dict = dict([i for i in value.__dict__.items()]) |
|---|
| 101 | value_dict['url'] = view.url(value) |
|---|
| 102 | value_dict['removable_by_student'] = value.removable_by_student |
|---|
| 103 | value_dict['mandatory'] = translate(str(value.mandatory), 'zope', |
|---|
| 104 | target_language=lang) |
|---|
| 105 | value_dict['carry_over'] = translate(str(value.carry_over), 'zope', |
|---|
| 106 | target_language=lang) |
|---|
| 107 | value_dict['outstanding'] = translate(str(value.outstanding), 'zope', |
|---|
| 108 | target_language=lang) |
|---|
| 109 | value_dict['automatic'] = translate(str(value.automatic), 'zope', |
|---|
| 110 | target_language=lang) |
|---|
| 111 | value_dict['grade'] = value.grade |
|---|
| 112 | value_dict['weight'] = value.weight |
|---|
| 113 | value_dict['course_category'] = value.course_category |
|---|
| 114 | value_dict['total_score'] = value.total_score |
|---|
| 115 | semester_dict = getUtility(IKofaUtils).SEMESTER_DICT |
|---|
| 116 | value_dict['semester'] = semester_dict[ |
|---|
| 117 | value.semester].replace('mester', 'm.') |
|---|
| 118 | # Unidel specific |
|---|
| 119 | value_dict['formatted_total_score'] = value.total_score |
|---|
| 120 | if getattr(value, 'imported_ts', None): |
|---|
| 121 | value_dict['formatted_total_score'] = "<strong>%s</strong>" % value.imported_ts |
|---|
| 122 | yield value_dict |
|---|
| 123 | |
|---|
| 124 | class CustomStudentBaseDisplayFormPage(NigeriaStudentBaseDisplayFormPage): |
|---|
| 125 | """ Page to display student base data |
|---|
| 126 | """ |
|---|
| 127 | form_fields = grok.AutoFields(ICustomStudentBase).omit( |
|---|
| 128 | 'password', 'suspended', 'suspended_comment', |
|---|
| 129 | 'flash_notice', 'provisionally_cleared') |
|---|
| 130 | form_fields[ |
|---|
| 131 | 'financial_clearance_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 132 | form_fields[ |
|---|
| 133 | 'final_clearance_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 134 | |
|---|
| 135 | class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage): |
|---|
| 136 | """ View to manage student base data |
|---|
| 137 | """ |
|---|
| 138 | form_fields = grok.AutoFields(ICustomStudentBase).omit( |
|---|
| 139 | 'student_id', 'adm_code', 'suspended', |
|---|
| 140 | 'financially_cleared_by', 'financial_clearance_date', |
|---|
| 141 | 'finally_cleared_by', 'final_clearance_date', 'password_updated') |
|---|
| 142 | |
|---|
| 143 | class CustomBedTicketAddPage(NigeriaBedTicketAddPage): |
|---|
| 144 | with_ac = False |
|---|
| 145 | |
|---|
| 146 | def update(self, SUBMIT=None): |
|---|
| 147 | if getattr(self.request.principal, 'user_type', None) == 'student': |
|---|
| 148 | entry_session = self.context.student['studycourse'].entry_session |
|---|
| 149 | if entry_session != grok.getSite()['hostels'].accommodation_session: |
|---|
| 150 | error_message = 'Only newly admitted students can book accommodation.' |
|---|
| 151 | self.flash(error_message, type="warning") |
|---|
| 152 | self.redirect(self.url(self.context)) |
|---|
| 153 | return |
|---|
| 154 | return super(CustomBedTicketAddPage, self).update(SUBMIT) |
|---|
| 155 | |
|---|
| 156 | class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage): |
|---|
| 157 | """ Page to view bed tickets. |
|---|
| 158 | """ |
|---|
| 159 | with_hostel_selection = True |
|---|
| 160 | |
|---|
| 161 | class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage): |
|---|
| 162 | """ Page to manage bed tickets. |
|---|
| 163 | This manage form page is for both students and students officers. |
|---|
| 164 | """ |
|---|
| 165 | with_hostel_selection = True |
|---|
| 166 | |
|---|
| 167 | @property |
|---|
| 168 | def booking_allowed(self): |
|---|
| 169 | if getattr(self.request.principal, 'user_type', None) == 'student': |
|---|
| 170 | entry_session = self.context.student['studycourse'].entry_session |
|---|
| 171 | if entry_session != grok.getSite()['hostels'].accommodation_session: |
|---|
| 172 | return False |
|---|
| 173 | students_utils = getUtility(IStudentsUtils) |
|---|
| 174 | acc_details = students_utils.getAccommodationDetails(self.context.student) |
|---|
| 175 | error_message = students_utils.checkAccommodationRequirements( |
|---|
| 176 | self.context.student, acc_details) |
|---|
| 177 | if error_message: |
|---|
| 178 | return False |
|---|
| 179 | return True |
|---|
| 180 | |
|---|
| 181 | @property |
|---|
| 182 | def actionsgroup2(self): |
|---|
| 183 | if getattr(self.request.principal, 'user_type', None) == 'student': |
|---|
| 184 | ## Book button can be disabled in custom packages by |
|---|
| 185 | ## uncommenting the following lines. |
|---|
| 186 | if not self.booking_allowed: |
|---|
| 187 | return [] |
|---|
| 188 | return [_('Book accommodation')] |
|---|
| 189 | return [_('Book accommodation'), _('Remove selected')] |
|---|
| 190 | |
|---|
| 191 | class CustomPaymentsManageFormPage(PaymentsManageFormPage): |
|---|
| 192 | """ Page to manage the student payments. This manage form page is for |
|---|
| 193 | both students and students officers. UNIDEL does not allow students |
|---|
| 194 | to remove any payment ticket. |
|---|
| 195 | """ |
|---|
| 196 | @property |
|---|
| 197 | def manage_payments_allowed(self): |
|---|
| 198 | return checkPermission('waeup.manageStudent', self.context) |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | class CustomStudentClearanceDisplayFormPage(NigeriaStudentClearanceDisplayFormPage): |
|---|
| 202 | """ Page to display student clearance data |
|---|
| 203 | """ |
|---|
| 204 | |
|---|
| 205 | @property |
|---|
| 206 | def form_fields(self): |
|---|
| 207 | if self.context.is_postgrad: |
|---|
| 208 | form_fields = grok.AutoFields( |
|---|
| 209 | ICustomPGStudentClearance).omit('clearance_locked') |
|---|
| 210 | else: |
|---|
| 211 | form_fields = grok.AutoFields( |
|---|
| 212 | ICustomUGStudentClearance).omit('clearance_locked') |
|---|
| 213 | if not getattr(self.context, 'officer_comment'): |
|---|
| 214 | form_fields = form_fields.omit('officer_comment') |
|---|
| 215 | else: |
|---|
| 216 | form_fields['officer_comment'].custom_widget = BytesDisplayWidget |
|---|
| 217 | return form_fields |
|---|
| 218 | |
|---|
| 219 | class CustomStudentClearanceManageFormPage(NigeriaStudentClearanceManageFormPage): |
|---|
| 220 | """ Page to edit student clearance data |
|---|
| 221 | """ |
|---|
| 222 | |
|---|
| 223 | @property |
|---|
| 224 | def form_fields(self): |
|---|
| 225 | if self.context.is_postgrad: |
|---|
| 226 | form_fields = grok.AutoFields( |
|---|
| 227 | ICustomPGStudentClearance).omit('clr_code') |
|---|
| 228 | else: |
|---|
| 229 | form_fields = grok.AutoFields( |
|---|
| 230 | ICustomUGStudentClearance).omit('clr_code') |
|---|
| 231 | return form_fields |
|---|
| 232 | |
|---|
| 233 | class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip): |
|---|
| 234 | """Deliver a PDF slip of the context. |
|---|
| 235 | """ |
|---|
| 236 | |
|---|
| 237 | @property |
|---|
| 238 | def form_fields(self): |
|---|
| 239 | if self.context.is_postgrad: |
|---|
| 240 | form_fields = grok.AutoFields( |
|---|
| 241 | ICustomPGStudentClearance).omit('clearance_locked') |
|---|
| 242 | else: |
|---|
| 243 | form_fields = grok.AutoFields( |
|---|
| 244 | ICustomUGStudentClearance).omit('clearance_locked') |
|---|
| 245 | if not getattr(self.context, 'officer_comment'): |
|---|
| 246 | form_fields = form_fields.omit('officer_comment') |
|---|
| 247 | return form_fields |
|---|
| 248 | |
|---|
| 249 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
|---|
| 250 | """ View to edit student clearance data by student |
|---|
| 251 | """ |
|---|
| 252 | |
|---|
| 253 | def dataNotComplete(self): |
|---|
| 254 | """To be implemented in the customization package. |
|---|
| 255 | """ |
|---|
| 256 | return False |
|---|
| 257 | |
|---|
| 258 | @property |
|---|
| 259 | def form_fields(self): |
|---|
| 260 | if self.context.is_postgrad: |
|---|
| 261 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit( |
|---|
| 262 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment', |
|---|
| 263 | 'physical_clearance_date') |
|---|
| 264 | else: |
|---|
| 265 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit( |
|---|
| 266 | 'clearance_locked', 'clr_code', 'officer_comment', |
|---|
| 267 | 'physical_clearance_date') |
|---|
| 268 | form_fields['date_of_birth'].for_display = True |
|---|
| 269 | form_fields['nationality'].for_display = True |
|---|
| 270 | form_fields['lga'].for_display = True |
|---|
| 271 | return form_fields |
|---|
| 272 | |
|---|
| 273 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
|---|
| 274 | """ Page to view an online payment ticket |
|---|
| 275 | """ |
|---|
| 276 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
|---|
| 277 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item','p_combi', |
|---|
| 278 | 'net_amt') |
|---|
| 279 | form_fields[ |
|---|
| 280 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 281 | form_fields[ |
|---|
| 282 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 283 | |
|---|
| 284 | class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip): |
|---|
| 285 | """Deliver a PDF slip of the context. |
|---|
| 286 | """ |
|---|
| 287 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
|---|
| 288 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', |
|---|
| 289 | 'p_split_data','p_combi', 'net_amt') |
|---|
| 290 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 291 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 292 | |
|---|
| 293 | class CustomStudyCourseManageFormPage(StudyCourseManageFormPage): |
|---|
| 294 | """ Page to edit the student study course data |
|---|
| 295 | """ |
|---|
| 296 | grok.context(ICustomStudentStudyCourse) |
|---|
| 297 | |
|---|
| 298 | @property |
|---|
| 299 | def form_fields(self): |
|---|
| 300 | if self.context.is_postgrad: |
|---|
| 301 | form_fields = grok.AutoFields(ICustomStudentStudyCourse).omit( |
|---|
| 302 | 'previous_verdict') |
|---|
| 303 | else: |
|---|
| 304 | form_fields = grok.AutoFields(ICustomStudentStudyCourse) |
|---|
| 305 | form_fields['imported_cgpa'].for_display = True |
|---|
| 306 | return form_fields |
|---|
| 307 | |
|---|
| 308 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
|---|
| 309 | """ Page to display student study levels |
|---|
| 310 | """ |
|---|
| 311 | #grok.template('studylevelpage') |
|---|
| 312 | grok.context(ICustomStudentStudyLevel) |
|---|
| 313 | |
|---|
| 314 | @property |
|---|
| 315 | def translated_values(self): |
|---|
| 316 | return translated_values(self) |
|---|
| 317 | |
|---|
| 318 | @property |
|---|
| 319 | def show_results(self): |
|---|
| 320 | isStudent = getattr( |
|---|
| 321 | self.request.principal, 'user_type', None) == 'student' |
|---|
| 322 | try: |
|---|
| 323 | show_results = grok.getSite()[ |
|---|
| 324 | 'configuration'][str(self.context.level_session)].show_results |
|---|
| 325 | except KeyError: |
|---|
| 326 | return False |
|---|
| 327 | if isStudent and self.context.student.current_mode not in show_results: |
|---|
| 328 | return False |
|---|
| 329 | #if isStudent and self.context.student.state != RETURNING \ |
|---|
| 330 | # and self.context.student.current_level == self.context.level: |
|---|
| 331 | # return False |
|---|
| 332 | return True |
|---|
| 333 | |
|---|
| 334 | @property |
|---|
| 335 | def form_fields(self): |
|---|
| 336 | if self.show_results: |
|---|
| 337 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
|---|
| 338 | 'total_credits', 'level','imported_gpa', 'imported_cgpa') |
|---|
| 339 | else: |
|---|
| 340 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
|---|
| 341 | 'total_credits', 'gpa', 'level','imported_gpa', 'imported_cgpa') |
|---|
| 342 | form_fields[ |
|---|
| 343 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 344 | return form_fields |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | class CustomStudyLevelManageFormPage(StudyLevelManageFormPage): |
|---|
| 348 | """ Page to edit the student study level data |
|---|
| 349 | """ |
|---|
| 350 | grok.context(ICustomStudentStudyLevel) |
|---|
| 351 | |
|---|
| 352 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
|---|
| 353 | 'validation_date', 'validated_by', 'total_credits', 'gpa', 'level', |
|---|
| 354 | 'total_credits_s1', 'total_credits_s2') |
|---|
| 355 | form_fields['imported_gpa'].for_display = True |
|---|
| 356 | form_fields['imported_cgpa'].for_display = True |
|---|
| 357 | |
|---|
| 358 | class CustomExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip): |
|---|
| 359 | """Deliver a PDF slip of the context. |
|---|
| 360 | """ |
|---|
| 361 | grok.context(ICustomStudentStudyLevel) |
|---|
| 362 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
|---|
| 363 | 'level', 'gpa', 'transcript_remark') |
|---|
| 364 | form_fields[ |
|---|
| 365 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 366 | #prefix = 'form' |
|---|
| 367 | omit_fields = ( |
|---|
| 368 | 'password', 'suspended', 'phone', 'date_of_birth', |
|---|
| 369 | 'adm_code', 'sex', 'suspended_comment', 'current_level', |
|---|
| 370 | 'flash_notice', 'imported_gpa', 'imported_cgpa',) |
|---|
| 371 | |
|---|
| 372 | @property |
|---|
| 373 | def show_results(self): |
|---|
| 374 | isStudent = getattr( |
|---|
| 375 | self.request.principal, 'user_type', None) == 'student' |
|---|
| 376 | try: |
|---|
| 377 | show_results = grok.getSite()[ |
|---|
| 378 | 'configuration'][str(self.context.level_session)].show_results |
|---|
| 379 | except KeyError: |
|---|
| 380 | return False |
|---|
| 381 | if isStudent and self.context.student.current_mode not in show_results: |
|---|
| 382 | return False |
|---|
| 383 | if isStudent and self.context.student.state != RETURNING \ |
|---|
| 384 | and self.context.student.current_level == self.context.level: |
|---|
| 385 | return False |
|---|
| 386 | return True |
|---|
| 387 | |
|---|
| 388 | def _signatures(self): |
|---|
| 389 | return ( |
|---|
| 390 | [_('Student\'s Signature')], |
|---|
| 391 | [_('Academic Adviser\'s Signature')], |
|---|
| 392 | [_('Head of Department\'s Signature')], |
|---|
| 393 | [_('Dean of Faculty\'s Signature')], |
|---|
| 394 | ) |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | def render(self): |
|---|
| 398 | if not self.context.student.current_mode: |
|---|
| 399 | self.flash('No certificate assigned.', type="danger") |
|---|
| 400 | self.redirect(self.url(self.context)) |
|---|
| 401 | return |
|---|
| 402 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 403 | Sem = translate(_('Term'), target_language=portal_language) |
|---|
| 404 | Code = translate(_('Code'), target_language=portal_language) |
|---|
| 405 | Title = translate(_('Title'), target_language=portal_language) |
|---|
| 406 | Cred = translate(_('Cred.'), target_language=portal_language) |
|---|
| 407 | CC = translate(_('Cat.'), target_language=portal_language) |
|---|
| 408 | TotalScore = translate(_('Total Score'), target_language=portal_language) |
|---|
| 409 | #CA = translate(_('CA'), target_language=portal_language) |
|---|
| 410 | Grade = translate(_('Grade'), target_language=portal_language) |
|---|
| 411 | Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue', |
|---|
| 412 | target_language=portal_language) |
|---|
| 413 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 414 | self.request, self.omit_fields) |
|---|
| 415 | students_utils = getUtility(IStudentsUtils) |
|---|
| 416 | tabledata = [] |
|---|
| 417 | tableheader = [] |
|---|
| 418 | contenttitle = [] |
|---|
| 419 | for i in range(1,7): |
|---|
| 420 | tabledata.append(sorted( |
|---|
| 421 | [value for value in self.context.values() |
|---|
| 422 | if value.semester == i and not value.outstanding], |
|---|
| 423 | key=lambda value: str(value.semester) + value.code)) |
|---|
| 424 | if self.show_results: |
|---|
| 425 | tableheader.append([(Code,'code', 2.0), |
|---|
| 426 | (Title,'title', 7), |
|---|
| 427 | (Cred, 'credits', 1.4), |
|---|
| 428 | (CC, 'course_category', 1.2), |
|---|
| 429 | (TotalScore, 'total_score', 1.4), |
|---|
| 430 | #(CA, 'ca', 1.4), |
|---|
| 431 | (Grade, 'grade', 1.4), |
|---|
| 432 | (Signature, 'dummy', 3), |
|---|
| 433 | ]) |
|---|
| 434 | else: |
|---|
| 435 | tableheader.append([(Code,'code', 2.0), |
|---|
| 436 | (Title,'title', 7), |
|---|
| 437 | (Cred, 'credits', 1.5), |
|---|
| 438 | (CC, 'course_category', 1.2), |
|---|
| 439 | (Signature, 'dummy', 3), |
|---|
| 440 | ]) |
|---|
| 441 | return students_utils.renderPDF( |
|---|
| 442 | self, 'course_registration_slip.pdf', |
|---|
| 443 | self.context.student, studentview, |
|---|
| 444 | tableheader=tableheader, |
|---|
| 445 | tabledata=tabledata, |
|---|
| 446 | omit_fields=self.omit_fields, |
|---|
| 447 | signatures=self._signatures(), |
|---|
| 448 | sigs_in_footer=self._sigsInFooter(), |
|---|
| 449 | ) |
|---|
| 450 | |
|---|
| 451 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
|---|
| 452 | """ Page to display course tickets |
|---|
| 453 | """ |
|---|
| 454 | |
|---|
| 455 | @property |
|---|
| 456 | def show_results(self): |
|---|
| 457 | isStudent = getattr( |
|---|
| 458 | self.request.principal, 'user_type', None) == 'student' |
|---|
| 459 | if isStudent: |
|---|
| 460 | return False |
|---|
| 461 | return True |
|---|
| 462 | |
|---|
| 463 | @property |
|---|
| 464 | def form_fields(self): |
|---|
| 465 | if self.show_results: |
|---|
| 466 | return grok.AutoFields(ICustomCourseTicket).omit('course_category', |
|---|
| 467 | 'ticket_session') |
|---|
| 468 | else: |
|---|
| 469 | return grok.AutoFields(ICustomCourseTicket).omit('score', 'ca', |
|---|
| 470 | 'course_category', 'ticket_session') |
|---|
| 471 | |
|---|
| 472 | class CustomCourseTicketManageFormPage(CourseTicketManageFormPage): |
|---|
| 473 | """ Page to manage course tickets |
|---|
| 474 | """ |
|---|
| 475 | |
|---|
| 476 | form_fields = grok.AutoFields(ICustomCourseTicket).omit('course_category') |
|---|
| 477 | form_fields['title'].for_display = True |
|---|
| 478 | form_fields['fcode'].for_display = True |
|---|
| 479 | form_fields['dcode'].for_display = True |
|---|
| 480 | form_fields['semester'].for_display = True |
|---|
| 481 | form_fields['passmark'].for_display = True |
|---|
| 482 | form_fields['credits'].for_display = True |
|---|
| 483 | form_fields['mandatory'].for_display = False |
|---|
| 484 | form_fields['automatic'].for_display = True |
|---|
| 485 | form_fields['carry_over'].for_display = True |
|---|
| 486 | form_fields['ticket_session'].for_display = True |
|---|
| 487 | form_fields['imported_ts'].for_display = True |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | class ExaminationClearanceSlip(NigeriaExportPDFClearanceSlip): |
|---|
| 491 | """Deliver a PDF slip of the context. |
|---|
| 492 | """ |
|---|
| 493 | |
|---|
| 494 | grok.name('examclearance_slip.pdf') |
|---|
| 495 | grok.require('waeup.handleStudent') |
|---|
| 496 | omit_fields = ( |
|---|
| 497 | 'suspended', |
|---|
| 498 | #'phone', |
|---|
| 499 | 'email', |
|---|
| 500 | 'adm_code', 'suspended_comment', |
|---|
| 501 | 'date_of_birth', |
|---|
| 502 | #'current_level', |
|---|
| 503 | #'current_mode', |
|---|
| 504 | #'entry_session', |
|---|
| 505 | 'flash_notice', |
|---|
| 506 | 'parents_email', |
|---|
| 507 | 'certificate', |
|---|
| 508 | #'faculty', |
|---|
| 509 | #'department', |
|---|
| 510 | 'reg_number') |
|---|
| 511 | form_fields = None |
|---|
| 512 | |
|---|
| 513 | @property |
|---|
| 514 | def note(self): |
|---|
| 515 | return ''' |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | You have been cleared to write second semester examination for %s/%s session. |
|---|
| 520 | ''' % (self.context.current_session, self.context.current_session + 1) |
|---|
| 521 | |
|---|
| 522 | def update(self): |
|---|
| 523 | # disabled 05/07/24 |
|---|
| 524 | return |
|---|
| 525 | #if not self.context.state in (VALIDATED, REGISTERED, PAID): |
|---|
| 526 | # self.flash(_('Your course list has not yet been registered.'), |
|---|
| 527 | # type="warning") |
|---|
| 528 | # self.redirect(self.url(self.context)) |
|---|
| 529 | # return |
|---|
| 530 | |
|---|
| 531 | @property |
|---|
| 532 | def label(self): |
|---|
| 533 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 534 | return translate(_('Examination Clearance Slip of'), |
|---|
| 535 | 'waeup.kofa', target_language=portal_language) \ |
|---|
| 536 | + ' %s' % self.context.display_fullname |
|---|
| 537 | |
|---|
| 538 | def _sigsInFooter(self): |
|---|
| 539 | #isStudent = getattr( |
|---|
| 540 | # self.request.principal, 'user_type', None) == 'student' |
|---|
| 541 | #if not isStudent and self.context.state in (CLEARED, RETURNING): |
|---|
| 542 | |
|---|
| 543 | return (_('Date, DICT Signature'), |
|---|
| 544 | _('Date, Dean\'s Signature'), |
|---|
| 545 | ) |
|---|
| 546 | def render(self): |
|---|
| 547 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 548 | self.request, self.omit_fields) |
|---|
| 549 | students_utils = getUtility(IStudentsUtils) |
|---|
| 550 | return students_utils.renderPDF( |
|---|
| 551 | self, 'examclearance_slip.pdf', |
|---|
| 552 | self.context.student, studentview, signatures=None, |
|---|
| 553 | sigs_in_footer=self._sigsInFooter(), show_scans=False, |
|---|
| 554 | omit_fields=self.omit_fields, |
|---|
| 555 | note=self.note) |
|---|
| 556 | |
|---|
| 557 | |
|---|
| 558 | class CustomExportAttendanceSlip(ExportAttendanceSlip): |
|---|
| 559 | """ |
|---|
| 560 | """ |
|---|
| 561 | |
|---|
| 562 | #def _signatures(self): |
|---|
| 563 | # return ([_('Student Signature')], |
|---|
| 564 | # [_('Clearance Officer Signature')]) |
|---|
| 565 | |
|---|
| 566 | @property |
|---|
| 567 | def note(self): |
|---|
| 568 | return """ |
|---|
| 569 | |
|---|
| 570 | |
|---|
| 571 | Faculty: __________________________________________________________ |
|---|
| 572 | |
|---|
| 573 | Department: ______________________________________________________ |
|---|
| 574 | |
|---|
| 575 | Date of Examination: _______________________________________________ |
|---|
| 576 | |
|---|
| 577 | Time of Examination: _______________________________________________ |
|---|
| 578 | |
|---|
| 579 | Venue of Examination: ______________________________________________ |
|---|
| 580 | |
|---|
| 581 | Names of Supervisors: |
|---|
| 582 | |
|---|
| 583 | ______________________________________________ |
|---|
| 584 | |
|---|
| 585 | ______________________________________________ |
|---|
| 586 | |
|---|
| 587 | ______________________________________________ |
|---|
| 588 | |
|---|
| 589 | ______________________________________________ |
|---|
| 590 | |
|---|
| 591 | ______________________________________________ |
|---|
| 592 | """ |
|---|
| 593 | |
|---|
| 594 | def render(self): |
|---|
| 595 | lecturers = [i['user_title'] for i in self.getUsersWithLocalRoles() |
|---|
| 596 | if i['local_role'] == 'waeup.local.Lecturer'] |
|---|
| 597 | lecturers = ', '.join(lecturers) |
|---|
| 598 | students_utils = getUtility(IStudentsUtils) |
|---|
| 599 | return students_utils.renderPDFCourseticketsOverview( |
|---|
| 600 | self, 'attendance', self.current_academic_session, |
|---|
| 601 | self.data(self.current_academic_session), |
|---|
| 602 | lecturers, '', 65, self.note) |
|---|
| 603 | |
|---|
| 604 | class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip): |
|---|
| 605 | """Deliver a PDF slip of the context. |
|---|
| 606 | """ |
|---|
| 607 | |
|---|
| 608 | @property |
|---|
| 609 | def note(self): |
|---|
| 610 | return """ |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | Signature: ________________________________ |
|---|
| 614 | |
|---|
| 615 | Name: ___________________________________ |
|---|
| 616 | |
|---|
| 617 | Head Examinations and Records |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | """ |
|---|
| 621 | |
|---|
| 622 | def render(self): |
|---|
| 623 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 624 | Term = 'Sem.' |
|---|
| 625 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
|---|
| 626 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
|---|
| 627 | Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language) |
|---|
| 628 | Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
|---|
| 629 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
|---|
| 630 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 631 | self.request, self.omit_fields) |
|---|
| 632 | students_utils = getUtility(IStudentsUtils) |
|---|
| 633 | |
|---|
| 634 | tableheader = [(Code,'code', 2.5), |
|---|
| 635 | (Title,'title', 7), |
|---|
| 636 | (Term, 'semester', 1.5), |
|---|
| 637 | (Cred, 'credits', 1.5), |
|---|
| 638 | (Score, 'total_score', 1.5), |
|---|
| 639 | (Grade, 'grade', 1.5), |
|---|
| 640 | ] |
|---|
| 641 | |
|---|
| 642 | pdfstream = students_utils.renderPDFTranscript( |
|---|
| 643 | self, 'transcript_%s.pdf' % self.context.student.student_id, |
|---|
| 644 | self.context.student, studentview, |
|---|
| 645 | omit_fields=self.omit_fields, |
|---|
| 646 | tableheader=tableheader, |
|---|
| 647 | note=self.note, |
|---|
| 648 | signatures=(), |
|---|
| 649 | sigs_in_footer=(), |
|---|
| 650 | digital_sigs=self._digital_sigs(), |
|---|
| 651 | save_file=self._save_file(), |
|---|
| 652 | ) |
|---|
| 653 | if not pdfstream: |
|---|
| 654 | self.redirect(self.url(self.context.student)) |
|---|
| 655 | return |
|---|
| 656 | return pdfstream |
|---|
| 657 | |
|---|
| 658 | class CustomEditScoresPage(EditScoresPage): |
|---|
| 659 | """Page that filters and lists students. |
|---|
| 660 | """ |
|---|
| 661 | grok.template('editscorespage') |
|---|
| 662 | |
|---|
| 663 | def _searchCatalog(self, session): |
|---|
| 664 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
|---|
| 665 | coursetickets = cat.searchResults( |
|---|
| 666 | session=(session, session), |
|---|
| 667 | code=(self.context.code, self.context.code) |
|---|
| 668 | ) |
|---|
| 669 | try: |
|---|
| 670 | score_editing_enabled = grok.getSite()[ |
|---|
| 671 | 'configuration'][str(session)].score_editing_enabled |
|---|
| 672 | except KeyError: |
|---|
| 673 | return [] |
|---|
| 674 | coursetickets_list = [courseticket for courseticket in coursetickets |
|---|
| 675 | if courseticket.student.current_mode in score_editing_enabled] |
|---|
| 676 | return coursetickets_list |
|---|
| 677 | |
|---|
| 678 | def _extract_uploadfile(self, uploadfile): |
|---|
| 679 | """Get a mapping of student-ids to scores. |
|---|
| 680 | |
|---|
| 681 | The mapping is constructed by reading contents from `uploadfile`. |
|---|
| 682 | |
|---|
| 683 | We expect uploadfile to be a regular CSV file with columns |
|---|
| 684 | ``student_id``, ``score``, ``imported_ts`` |
|---|
| 685 | and ``ca`` (other cols are ignored). |
|---|
| 686 | """ |
|---|
| 687 | result = dict() |
|---|
| 688 | data = StringIO(uploadfile.read()) # ensure we have something seekable |
|---|
| 689 | reader = csv.DictReader(data) |
|---|
| 690 | for row in reader: |
|---|
| 691 | if not ('student_id' in row and 'score' in row and 'ca' in row and |
|---|
| 692 | 'imported_ts' in row): |
|---|
| 693 | continue |
|---|
| 694 | result[row['student_id']] = ( |
|---|
| 695 | row['score'], row['ca'], row['imported_ts']) |
|---|
| 696 | return result |
|---|
| 697 | |
|---|
| 698 | def _update_scores(self, form): |
|---|
| 699 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.', '') |
|---|
| 700 | error = '' |
|---|
| 701 | if 'UPDATE_FILE' in form: |
|---|
| 702 | if form['uploadfile']: |
|---|
| 703 | try: |
|---|
| 704 | formvals = self._extract_uploadfile(form['uploadfile']) |
|---|
| 705 | except: |
|---|
| 706 | self.flash( |
|---|
| 707 | _('Uploaded file contains illegal data. Ignored'), |
|---|
| 708 | type="danger") |
|---|
| 709 | return False |
|---|
| 710 | else: |
|---|
| 711 | self.flash( |
|---|
| 712 | _('No file provided.'), type="danger") |
|---|
| 713 | return False |
|---|
| 714 | else: |
|---|
| 715 | formvals = dict(zip(form['sids'], zip( |
|---|
| 716 | form['scores'], form['cas'], form['imported_ts']))) |
|---|
| 717 | for ticket in self.editable_tickets: |
|---|
| 718 | ticket_error = False |
|---|
| 719 | score = ticket.score |
|---|
| 720 | ca = ticket.ca |
|---|
| 721 | imported_ts = ticket.imported_ts |
|---|
| 722 | sid = ticket.student.student_id |
|---|
| 723 | if sid not in formvals: |
|---|
| 724 | continue |
|---|
| 725 | if formvals[sid][0] == '': |
|---|
| 726 | score = None |
|---|
| 727 | if formvals[sid][1] == '': |
|---|
| 728 | ca = None |
|---|
| 729 | if formvals[sid][2] == '': |
|---|
| 730 | imported_ts = None |
|---|
| 731 | try: |
|---|
| 732 | if formvals[sid][0]: |
|---|
| 733 | score = int(formvals[sid][0]) |
|---|
| 734 | if formvals[sid][1]: |
|---|
| 735 | ca = int(formvals[sid][1]) |
|---|
| 736 | if formvals[sid][2]: |
|---|
| 737 | imported_ts = int(formvals[sid][2]) |
|---|
| 738 | except ValueError: |
|---|
| 739 | error += '%s, ' % ticket.student.display_fullname |
|---|
| 740 | ticket_error = True |
|---|
| 741 | if score and ca and not ticket_error and score + ca > 100: |
|---|
| 742 | error += '%s, ' % ticket.student.display_fullname |
|---|
| 743 | ticket_error = True |
|---|
| 744 | if not ticket_error and ticket.score != score: |
|---|
| 745 | try: |
|---|
| 746 | ticket.score = score |
|---|
| 747 | except TooBig: |
|---|
| 748 | error += '%s, ' % ticket.student.display_fullname |
|---|
| 749 | ticket_error = True |
|---|
| 750 | pass |
|---|
| 751 | ticket.student.__parent__.logger.info( |
|---|
| 752 | '%s - %s %s/%s score updated (%s)' % |
|---|
| 753 | (ob_class, ticket.student.student_id, |
|---|
| 754 | ticket.level, ticket.code, score)) |
|---|
| 755 | if not ticket_error and ticket.ca != ca: |
|---|
| 756 | try: |
|---|
| 757 | ticket.ca = ca |
|---|
| 758 | except TooBig: |
|---|
| 759 | error += '%s, ' % ticket.student.display_fullname |
|---|
| 760 | pass |
|---|
| 761 | ticket.student.__parent__.logger.info( |
|---|
| 762 | '%s - %s %s/%s ca updated (%s)' % |
|---|
| 763 | (ob_class, ticket.student.student_id, |
|---|
| 764 | ticket.level, ticket.code, ca)) |
|---|
| 765 | if not ticket_error and ticket.imported_ts != imported_ts: |
|---|
| 766 | try: |
|---|
| 767 | ticket.imported_ts = imported_ts |
|---|
| 768 | except TooBig: |
|---|
| 769 | error += '%s, ' % ticket.student.display_fullname |
|---|
| 770 | pass |
|---|
| 771 | ticket.student.__parent__.logger.info( |
|---|
| 772 | '%s - %s %s/%s imported_ts updated (%s)' % |
|---|
| 773 | (ob_class, ticket.student.student_id, |
|---|
| 774 | ticket.level, ticket.code, imported_ts)) |
|---|
| 775 | if error: |
|---|
| 776 | self.flash(_('Error: Score(s), CA(s) and Imported TS(s) of %s have not be updated. ' |
|---|
| 777 | % error.strip(', ')), type="danger") |
|---|
| 778 | return True |
|---|
| 779 | |
|---|
| 780 | class CustomExportPDFScoresSlip(ExportPDFScoresSlip): |
|---|
| 781 | """Deliver a PDF slip of course tickets for a lecturer. |
|---|
| 782 | """ |
|---|
| 783 | |
|---|
| 784 | note = u'\nUpgraded scores are with asterisks.' |
|---|
| 785 | |
|---|
| 786 | def data(self, session): |
|---|
| 787 | #site = grok.getSite() |
|---|
| 788 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
|---|
| 789 | coursetickets = cat.searchResults( |
|---|
| 790 | session=(session, session), |
|---|
| 791 | code=(self.context.code, self.context.code) |
|---|
| 792 | ) |
|---|
| 793 | # Apply filter |
|---|
| 794 | try: |
|---|
| 795 | score_editing_enabled = grok.getSite()[ |
|---|
| 796 | 'configuration'][str(session)].score_editing_enabled |
|---|
| 797 | if checkPermission('waeup.manageAcademics', self.context): |
|---|
| 798 | score_editing_enabled = True |
|---|
| 799 | coursetickets_filtered = [courseticket |
|---|
| 800 | for courseticket in coursetickets |
|---|
| 801 | if (checkPermission('waeup.manageAcademics', self.context) |
|---|
| 802 | or (courseticket.student.current_mode in |
|---|
| 803 | score_editing_enabled)) |
|---|
| 804 | and courseticket.total_score is not None |
|---|
| 805 | and courseticket.__parent__.__parent__.is_current] |
|---|
| 806 | except KeyError: |
|---|
| 807 | coursetickets_filtered = coursetickets |
|---|
| 808 | # In AAUE only editable tickets can be printed (deactivated on 02/10/19) |
|---|
| 809 | #editable_tickets = [ |
|---|
| 810 | # ticket for ticket in coursetickets_filtered |
|---|
| 811 | # if ticket.editable_by_lecturer] |
|---|
| 812 | header = [[_(''), |
|---|
| 813 | _('Student Id'), |
|---|
| 814 | _('Matric No.'), |
|---|
| 815 | #_('Reg. No.'), |
|---|
| 816 | #_('Fullname'), |
|---|
| 817 | #_('Status'), |
|---|
| 818 | #_('Course of\nStudies'), |
|---|
| 819 | _('Department'), |
|---|
| 820 | _('Level'), |
|---|
| 821 | _(' CA '), |
|---|
| 822 | _('Exam\nScore'), |
|---|
| 823 | _('Total '), |
|---|
| 824 | _('Grade'), |
|---|
| 825 | ],] |
|---|
| 826 | sorted_tickets = sorted(coursetickets_filtered, # editable_tickets, |
|---|
| 827 | key=lambda ticket: str(ticket.student.depcode) |
|---|
| 828 | + str(ticket.student.faccode) |
|---|
| 829 | + str(ticket.student.matric_number) |
|---|
| 830 | ) |
|---|
| 831 | no = 1 |
|---|
| 832 | tickets = [] |
|---|
| 833 | passed = 0 |
|---|
| 834 | failed = 0 |
|---|
| 835 | with_ca = False |
|---|
| 836 | grade_stats = {'A':0, 'B':0, 'C':0, 'D':0, 'E':0, 'F':0, } |
|---|
| 837 | for ticket in sorted_tickets: |
|---|
| 838 | if ticket.ca > 0: |
|---|
| 839 | with_ca = True |
|---|
| 840 | total = ticket.total_score |
|---|
| 841 | if getattr(ticket, 'imported_ts', None): |
|---|
| 842 | total = "**%s**" % ticket.imported_ts |
|---|
| 843 | grade = ticket._getGradeWeightFromScore[0] |
|---|
| 844 | if grade in grade_stats.keys(): |
|---|
| 845 | grade_stats[grade] += 1 |
|---|
| 846 | if grade in ('F', '-'): |
|---|
| 847 | failed += 1 |
|---|
| 848 | else: |
|---|
| 849 | passed += 1 |
|---|
| 850 | fullname = textwrap.fill(ticket.student.display_fullname, 30) |
|---|
| 851 | #deptitle = site['faculties'][ticket.student.faccode][ |
|---|
| 852 | # ticket.student.depcode].longtitle |
|---|
| 853 | row = [str(no), |
|---|
| 854 | ticket.student.student_id, |
|---|
| 855 | ticket.student.matric_number, |
|---|
| 856 | #ticket.student.reg_number, |
|---|
| 857 | #fullname, |
|---|
| 858 | #ticket.student.translated_state, |
|---|
| 859 | #ticket.student.certcode, |
|---|
| 860 | str(ticket.student.faccode) + ' / ' + str(ticket.student.depcode), |
|---|
| 861 | ticket.level, |
|---|
| 862 | ticket.ca, |
|---|
| 863 | ticket.score, |
|---|
| 864 | total, |
|---|
| 865 | grade, |
|---|
| 866 | ] |
|---|
| 867 | tickets.append(row) |
|---|
| 868 | no += 1 |
|---|
| 869 | total = passed + failed |
|---|
| 870 | passed_perc = 0 |
|---|
| 871 | failed_perc = 0 |
|---|
| 872 | if total: |
|---|
| 873 | passed_perc = round(100.0 * passed / total) |
|---|
| 874 | failed_perc = round(100.0 * failed / total) |
|---|
| 875 | dep = self.context.__parent__.__parent__.longtitle |
|---|
| 876 | fac = self.context.__parent__.__parent__.__parent__.longtitle |
|---|
| 877 | # remove CA column if not necessary |
|---|
| 878 | if not with_ca: |
|---|
| 879 | header = [[_(''), |
|---|
| 880 | _('Student Id'), |
|---|
| 881 | _('Matric No.'), |
|---|
| 882 | #_('Reg. No.'), |
|---|
| 883 | #_('Fullname'), |
|---|
| 884 | #_('Status'), |
|---|
| 885 | #_('Course of\nStudies'), |
|---|
| 886 | _('Department'), |
|---|
| 887 | _('Level'), |
|---|
| 888 | #_(' CA '), |
|---|
| 889 | _('Exam\nScore'), |
|---|
| 890 | _('Total '), |
|---|
| 891 | _('Grade'), |
|---|
| 892 | ],] |
|---|
| 893 | for ticket in tickets: |
|---|
| 894 | del(ticket[5]) |
|---|
| 895 | return header + tickets, [ |
|---|
| 896 | dep, fac, total, passed, passed_perc, failed, failed_perc, grade_stats] |
|---|
| 897 | |
|---|
| 898 | def render(self): |
|---|
| 899 | session = grok.getSite()['configuration'].current_academic_session |
|---|
| 900 | lecturers = [i['user_title'] for i in self.getUsersWithLocalRoles() |
|---|
| 901 | if i['local_role'] == 'waeup.local.Lecturer'] |
|---|
| 902 | lecturers = sorted(lecturers) |
|---|
| 903 | lecturers = ', '.join(lecturers) |
|---|
| 904 | students_utils = getUtility(IStudentsUtils) |
|---|
| 905 | # only orientation is different |
|---|
| 906 | return students_utils.renderPDFCourseticketsOverview( |
|---|
| 907 | self, 'coursetickets', |
|---|
| 908 | session, self.data(session), lecturers, '', 45, self.note) |
|---|
| 909 | |
|---|
| 910 | class ResultNotificationPage(grok.View): |
|---|
| 911 | """ Simple HTML Layout Page |
|---|
| 912 | """ |
|---|
| 913 | grok.context(ICustomStudent) |
|---|
| 914 | grok.name('notificationofresult') |
|---|
| 915 | grok.require('waeup.manageStudent') |
|---|
| 916 | grok.template('notificationofresult') |
|---|
| 917 | |
|---|
| 918 | def update(self): |
|---|
| 919 | if not self.context.state in (GRADUATED,): |
|---|
| 920 | self.flash(_('Not yet graduated!'), |
|---|
| 921 | type="danger") |
|---|
| 922 | self.redirect(self.url(self.context)) |
|---|
| 923 | return |
|---|
| 924 | self.response.setHeader('Content-Type', 'text/html; charset=utf-8') |
|---|
| 925 | certificate = self.context['studycourse'].certificate |
|---|
| 926 | self.certificate = certificate.title |
|---|
| 927 | self.fullname = self.context.display_fullname |
|---|
| 928 | self.firstname = self.context.firstname |
|---|
| 929 | self.lastname = self.context.lastname |
|---|
| 930 | self.matric_number = self.context.matric_number |
|---|
| 931 | self.dep = certificate.__parent__.__parent__.longtitle |
|---|
| 932 | self.fac = certificate.__parent__.__parent__.__parent__.longtitle |
|---|
| 933 | tz = getattr(queryUtility(IKofaUtils), 'tzinfo', pytz.utc) |
|---|
| 934 | self.date = now(tz).strftime('%d/%m/%Y') |
|---|
| 935 | return |
|---|
| 936 | |
|---|
| 937 | |
|---|
| 938 | class CustomAddStudyLevelFormPage(AddStudyLevelFormPage): |
|---|
| 939 | """ This page is temporarily locked. for all ug students in 2026. |
|---|
| 940 | """ |
|---|
| 941 | def update(self): |
|---|
| 942 | if self.context.student.current_mode == 'ug_ft' \ |
|---|
| 943 | and self.context.student.current_session == 2026 \ |
|---|
| 944 | and self.context.student.entry_session != 2026 \ |
|---|
| 945 | and self.context.student.fullname != 'anna-tester': |
|---|
| 946 | self.flash('Course registration for the current academic session is not yet open. Please check back later.', type="warning") |
|---|
| 947 | self.redirect(view.url(view.context)) |
|---|
| 948 | return |
|---|
| 949 | super(CustomAddStudyLevelFormPage, self).update() |
|---|
| 950 | return |
|---|