[8911] | 1 | ## $Id: browser.py 17431 2023-06-16 11:43:53Z 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 |
---|
[13937] | 19 | import csv |
---|
[13964] | 20 | import textwrap |
---|
[14981] | 21 | import pytz |
---|
[13937] | 22 | from cStringIO import StringIO |
---|
[14981] | 23 | from datetime import datetime |
---|
[8911] | 24 | from zope.i18n import translate |
---|
[13900] | 25 | from zope.component import getUtility, queryUtility |
---|
[14113] | 26 | from zope.schema.interfaces import TooBig, TooSmall |
---|
[13523] | 27 | from zope.security import checkPermission |
---|
[13900] | 28 | from zope.catalog.interfaces import ICatalog |
---|
[13351] | 29 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[14981] | 30 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
[15330] | 31 | from waeup.kofa.browser.layout import UtilityView, KofaEditFormPage, jsaction |
---|
[8911] | 32 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[14288] | 33 | from waeup.kofa.interfaces import ( |
---|
[14306] | 34 | IKofaUtils, academic_sessions_vocab, ICSVExporter, IKofaObject) |
---|
| 35 | from waeup.kofa.students.interfaces import ( |
---|
[15330] | 36 | IStudentsUtils, IStudent, IStudentRequestPW, IStudentStudyLevel) |
---|
[15896] | 37 | from waeup.kofa.students.workflow import PAID, REGISTERED, RETURNING, GRADUATED |
---|
[9914] | 38 | from waeup.kofa.students.browser import ( |
---|
[11846] | 39 | StartClearancePage, |
---|
[9914] | 40 | StudentBasePDFFormPage, |
---|
| 41 | CourseTicketAddFormPage, |
---|
| 42 | StudyLevelDisplayFormPage, |
---|
[13834] | 43 | StudyLevelManageFormPage, |
---|
| 44 | StudyLevelEditFormPage, |
---|
[13059] | 45 | ExportPDFTranscriptSlip, |
---|
| 46 | ExportPDFAdmissionSlip, |
---|
[13380] | 47 | StudentFilesUploadPage, |
---|
[13523] | 48 | PaymentsManageFormPage, |
---|
[13770] | 49 | CourseTicketDisplayFormPage, |
---|
| 50 | CourseTicketManageFormPage, |
---|
[13900] | 51 | EditScoresPage, |
---|
[14165] | 52 | ExportPDFScoresSlip, |
---|
| 53 | StudyCourseTranscriptPage, |
---|
[14288] | 54 | DownloadScoresView, |
---|
[14534] | 55 | StudentRequestPasswordPage, |
---|
[14981] | 56 | StudyCourseManageFormPage, |
---|
[15330] | 57 | UnregisterCoursesView, |
---|
| 58 | addCourseTicket, |
---|
[15864] | 59 | AddStudyLevelFormPage, |
---|
[15330] | 60 | emit_lock_message |
---|
[10269] | 61 | ) |
---|
[8911] | 62 | from kofacustom.nigeria.students.browser import ( |
---|
| 63 | NigeriaOnlinePaymentDisplayFormPage, |
---|
| 64 | NigeriaOnlinePaymentAddFormPage, |
---|
[13059] | 65 | NigeriaExportPDFPaymentSlip, |
---|
| 66 | NigeriaExportPDFCourseRegistrationSlip, |
---|
[13351] | 67 | NigeriaStudentPersonalDisplayFormPage, |
---|
| 68 | NigeriaStudentPersonalEditFormPage, |
---|
| 69 | NigeriaStudentPersonalManageFormPage, |
---|
[14084] | 70 | NigeriaStudentClearanceDisplayFormPage, |
---|
| 71 | NigeriaExportPDFClearanceSlip, |
---|
| 72 | NigeriaStudentClearanceManageFormPage, |
---|
[13362] | 73 | NigeriaStudentClearanceEditFormPage, |
---|
[13462] | 74 | NigeriaAccommodationManageFormPage, |
---|
[15976] | 75 | NigeriaAccommodationDisplayFormPage, |
---|
[13795] | 76 | NigeriaStudentBaseDisplayFormPage, |
---|
[15713] | 77 | NigeriaStudentBaseManageFormPage, |
---|
| 78 | NigeriaBedTicketAddPage |
---|
[10269] | 79 | ) |
---|
[9496] | 80 | from waeup.aaue.students.interfaces import ( |
---|
[9914] | 81 | ICustomStudentOnlinePayment, |
---|
[11607] | 82 | ICustomStudentStudyLevel, |
---|
[13351] | 83 | ICustomStudent, |
---|
| 84 | ICustomStudentPersonal, |
---|
[13362] | 85 | ICustomStudentPersonalEdit, |
---|
[13770] | 86 | ICustomUGStudentClearance, |
---|
[14298] | 87 | ICustomUGStudentClearanceEdit, |
---|
[14084] | 88 | ICustomPGStudentClearance, |
---|
[13795] | 89 | ICustomCourseTicket, |
---|
[14534] | 90 | ICustomStudentBase, |
---|
| 91 | ICustomStudentStudyCourse) |
---|
[9914] | 92 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
[8911] | 93 | |
---|
[14306] | 94 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
| 95 | |
---|
[15228] | 96 | def translated_values(view): |
---|
| 97 | """Translate course ticket attribute values to be displayed on |
---|
| 98 | studylevel pages. |
---|
| 99 | """ |
---|
| 100 | lang = view.request.cookies.get('kofa.language') |
---|
| 101 | for value in view.context.values(): |
---|
| 102 | value._p_activate() |
---|
| 103 | value_dict = dict([i for i in value.__dict__.items()]) |
---|
| 104 | value_dict['url'] = view.url(value) |
---|
| 105 | value_dict['removable_by_student'] = value.removable_by_student |
---|
| 106 | value_dict['mandatory'] = translate(str(value.mandatory), 'zope', |
---|
| 107 | target_language=lang) |
---|
| 108 | value_dict['carry_over'] = translate(str(value.carry_over), 'zope', |
---|
| 109 | target_language=lang) |
---|
| 110 | value_dict['outstanding'] = translate(str(value.outstanding), 'zope', |
---|
| 111 | target_language=lang) |
---|
| 112 | value_dict['automatic'] = translate(str(value.automatic), 'zope', |
---|
| 113 | target_language=lang) |
---|
| 114 | value_dict['grade'] = value.grade |
---|
| 115 | value_dict['weight'] = value.weight |
---|
| 116 | value_dict['course_category'] = value.course_category |
---|
| 117 | value_dict['total_score'] = value.total_score |
---|
| 118 | semester_dict = getUtility(IKofaUtils).SEMESTER_DICT |
---|
| 119 | value_dict['semester'] = semester_dict[ |
---|
| 120 | value.semester].replace('mester', 'm.') |
---|
| 121 | # AAUE specific |
---|
| 122 | value_dict['formatted_total_score'] = value.total_score |
---|
| 123 | if getattr(value, 'imported_ts', None): |
---|
| 124 | value_dict['formatted_total_score'] = "<strong>%s</strong>" % value.imported_ts |
---|
| 125 | yield value_dict |
---|
| 126 | |
---|
[13795] | 127 | class CustomStudentBaseDisplayFormPage(NigeriaStudentBaseDisplayFormPage): |
---|
| 128 | """ Page to display student base data |
---|
| 129 | """ |
---|
| 130 | form_fields = grok.AutoFields(ICustomStudentBase).omit( |
---|
| 131 | 'password', 'suspended', 'suspended_comment', 'flash_notice') |
---|
| 132 | form_fields[ |
---|
| 133 | 'financial_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 | |
---|
[13351] | 142 | class CustomStudentPersonalDisplayFormPage(NigeriaStudentPersonalDisplayFormPage): |
---|
| 143 | """ Page to display student personal data |
---|
| 144 | """ |
---|
| 145 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
| 146 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 147 | form_fields['father_address'].custom_widget = BytesDisplayWidget |
---|
| 148 | form_fields['mother_address'].custom_widget = BytesDisplayWidget |
---|
| 149 | form_fields['next_kin_address'].custom_widget = BytesDisplayWidget |
---|
| 150 | form_fields[ |
---|
| 151 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 152 | |
---|
| 153 | class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage): |
---|
| 154 | """ Page to edit personal data |
---|
| 155 | """ |
---|
| 156 | form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit('personal_updated') |
---|
| 157 | |
---|
| 158 | class CustomStudentPersonalManageFormPage(NigeriaStudentPersonalManageFormPage): |
---|
| 159 | """ Page to edit personal data |
---|
| 160 | """ |
---|
| 161 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
| 162 | form_fields['personal_updated'].for_display = True |
---|
| 163 | form_fields[ |
---|
| 164 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 165 | |
---|
[14661] | 166 | |
---|
| 167 | class ExportExaminationScheduleSlip(UtilityView, grok.View): |
---|
| 168 | """Deliver a examination schedule slip. |
---|
| 169 | |
---|
| 170 | This form page is available only in Uniben and AAUE. |
---|
| 171 | """ |
---|
| 172 | grok.context(ICustomStudent) |
---|
| 173 | grok.name('examination_schedule_slip.pdf') |
---|
| 174 | grok.require('waeup.viewStudent') |
---|
| 175 | prefix = 'form' |
---|
| 176 | |
---|
| 177 | label = u'Examination Schedule Slip' |
---|
| 178 | |
---|
| 179 | omit_fields = ( |
---|
| 180 | 'suspended', 'phone', 'email', |
---|
| 181 | 'adm_code', 'suspended_comment', |
---|
| 182 | 'date_of_birth', 'current_level', |
---|
| 183 | 'current_mode', |
---|
| 184 | 'entry_session', |
---|
| 185 | 'flash_notice') |
---|
| 186 | |
---|
| 187 | form_fields = [] |
---|
| 188 | |
---|
| 189 | @property |
---|
| 190 | def note(self): |
---|
| 191 | return """ |
---|
[14674] | 192 | <br /><br /> |
---|
| 193 | <strong>Instructions on CBT Venue Allocation Slip (VAS)</strong> |
---|
| 194 | <br /><br /> |
---|
| 195 | You should login with your student id from Kofa and surname as password. |
---|
[14677] | 196 | Download and print two copies of this slip and bring them to the |
---|
| 197 | allocated CBT examination center. |
---|
| 198 | The copies <strong>MUST</strong> be shown to the invigilators |
---|
| 199 | before being admitted into the examination hall. |
---|
[14674] | 200 | <br /><br /> |
---|
[14677] | 201 | How to start examination:<br /><br /> |
---|
| 202 | * Username: "student id" from Kofa e.g E1000000<br /> |
---|
| 203 | * Password: "surname" as shown on this slip in capital letters<br /> |
---|
| 204 | * Click the course and click "start exam". |
---|
| 205 | <br /><br /> |
---|
| 206 | <strong>WARNING:</strong> Electronic devices (phones, tablets, laptops etc.) |
---|
[14674] | 207 | are not allowed in the examination hall. Any electronics seized will not |
---|
| 208 | be returned. Any student caught charging his/her mobile phone at the CBT |
---|
[14677] | 209 | centers will be penalized and the exam of such a student will be cancelled. |
---|
[14674] | 210 | Bags and any foreign materials are not allowed at the venue of |
---|
| 211 | the CBT exams. Any omission/other complaints should be reported to the CBT |
---|
| 212 | committee through the HoD before the date of examination. |
---|
| 213 | <br /><br /> |
---|
| 214 | Your examination date, time and venue is scheduled as follows: |
---|
| 215 | <br /><br /> |
---|
| 216 | <strong>%s</strong> |
---|
[14661] | 217 | """ % self.context.flash_notice |
---|
| 218 | return |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | def update(self): |
---|
| 222 | if not self.context.flash_notice \ |
---|
| 223 | or not 'exam' in self.context.flash_notice.lower(): |
---|
| 224 | self.flash(_('Forbidden'), type="warning") |
---|
| 225 | self.redirect(self.url(self.context)) |
---|
| 226 | |
---|
| 227 | def render(self): |
---|
| 228 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 229 | self.request, self.omit_fields) |
---|
| 230 | students_utils = getUtility(IStudentsUtils) |
---|
| 231 | return students_utils.renderPDF( |
---|
| 232 | self, 'examination_schedule_slip', |
---|
| 233 | self.context.student, studentview, |
---|
| 234 | omit_fields=self.omit_fields, |
---|
| 235 | note=self.note) |
---|
| 236 | |
---|
[14084] | 237 | class CustomStudentClearanceDisplayFormPage(NigeriaStudentClearanceDisplayFormPage): |
---|
| 238 | """ Page to display student clearance data |
---|
| 239 | """ |
---|
| 240 | |
---|
| 241 | @property |
---|
| 242 | def form_fields(self): |
---|
| 243 | if self.context.is_postgrad: |
---|
| 244 | form_fields = grok.AutoFields( |
---|
| 245 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
| 246 | else: |
---|
| 247 | form_fields = grok.AutoFields( |
---|
| 248 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
| 249 | if not getattr(self.context, 'officer_comment'): |
---|
| 250 | form_fields = form_fields.omit('officer_comment') |
---|
| 251 | else: |
---|
| 252 | form_fields['officer_comment'].custom_widget = BytesDisplayWidget |
---|
[14104] | 253 | form_fields = form_fields.omit('def_adm') |
---|
[14084] | 254 | return form_fields |
---|
| 255 | |
---|
| 256 | class CustomStudentClearanceManageFormPage(NigeriaStudentClearanceManageFormPage): |
---|
| 257 | """ Page to edit student clearance data |
---|
| 258 | """ |
---|
| 259 | |
---|
| 260 | @property |
---|
| 261 | def form_fields(self): |
---|
| 262 | if self.context.is_postgrad: |
---|
| 263 | form_fields = grok.AutoFields( |
---|
| 264 | ICustomPGStudentClearance).omit('clr_code') |
---|
| 265 | else: |
---|
| 266 | form_fields = grok.AutoFields( |
---|
| 267 | ICustomUGStudentClearance).omit('clr_code') |
---|
[14104] | 268 | form_fields = form_fields.omit('def_adm') |
---|
[14084] | 269 | return form_fields |
---|
| 270 | |
---|
[13362] | 271 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
| 272 | """ View to edit student clearance data by student |
---|
| 273 | """ |
---|
| 274 | |
---|
| 275 | @property |
---|
| 276 | def form_fields(self): |
---|
| 277 | if self.context.is_postgrad: |
---|
| 278 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit( |
---|
| 279 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment', |
---|
| 280 | 'physical_clearance_date') |
---|
| 281 | else: |
---|
[14298] | 282 | form_fields = grok.AutoFields(ICustomUGStudentClearanceEdit).omit( |
---|
[13362] | 283 | 'clearance_locked', 'clr_code', 'officer_comment', |
---|
[14104] | 284 | 'physical_clearance_date', 'date_of_birth', 'nationality', 'lga') |
---|
| 285 | form_fields = form_fields.omit('def_adm') |
---|
[13362] | 286 | return form_fields |
---|
| 287 | |
---|
[11846] | 288 | class CustomStartClearancePage(StartClearancePage): |
---|
[13360] | 289 | with_ac = False |
---|
[11846] | 290 | |
---|
[13351] | 291 | @property |
---|
| 292 | def all_required_fields_filled(self): |
---|
| 293 | if not self.context.email: |
---|
| 294 | return _("Email address is missing."), 'edit_base' |
---|
| 295 | if not self.context.phone: |
---|
| 296 | return _("Phone number is missing."), 'edit_base' |
---|
| 297 | if not self.context.father_name: |
---|
| 298 | return _("Personal data form is not properly filled."), 'edit_personal' |
---|
| 299 | return |
---|
| 300 | |
---|
[8911] | 301 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
| 302 | """ Page to view an online payment ticket |
---|
| 303 | """ |
---|
| 304 | grok.context(ICustomStudentOnlinePayment) |
---|
[9853] | 305 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9990] | 306 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 307 | form_fields[ |
---|
| 308 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 309 | form_fields[ |
---|
| 310 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 311 | |
---|
[13523] | 312 | class CustomPaymentsManageFormPage(PaymentsManageFormPage): |
---|
| 313 | """ Page to manage the student payments. |
---|
| 314 | |
---|
| 315 | This manage form page is for both students and students officers. |
---|
| 316 | """ |
---|
| 317 | @property |
---|
| 318 | def manage_payments_allowed(self): |
---|
| 319 | return checkPermission('waeup.manageStudent', self.context) |
---|
| 320 | |
---|
[13059] | 321 | class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip): |
---|
[8911] | 322 | """Deliver a PDF slip of the context. |
---|
| 323 | """ |
---|
| 324 | grok.context(ICustomStudentOnlinePayment) |
---|
[9853] | 325 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[15471] | 326 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', |
---|
[15689] | 327 | 'p_split_data', 'p_combi') |
---|
[8911] | 328 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9496] | 329 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9914] | 330 | |
---|
[11625] | 331 | @property |
---|
| 332 | def note(self): |
---|
[13408] | 333 | p_session = self.context.p_session |
---|
[13405] | 334 | try: |
---|
[13408] | 335 | academic_session = grok.getSite()['configuration'][str(p_session)] |
---|
[13405] | 336 | except KeyError: |
---|
| 337 | academic_session = None |
---|
[13425] | 338 | text = '\n\n The Amount Authorized is inclusive of: ' |
---|
[13512] | 339 | if self.context.p_category in ('schoolfee_incl', 'schoolfee_1') \ |
---|
| 340 | and academic_session: |
---|
[14244] | 341 | if self.context.student.entry_session == 2016 \ |
---|
| 342 | and self.context.student.entry_mode == 'ug_ft' \ |
---|
| 343 | and self.context.p_session == 2016: |
---|
| 344 | # Add student id card fee to first school fee payment. |
---|
[14385] | 345 | |
---|
| 346 | ## Attention: The payment slip does not contain any information |
---|
| 347 | ## whether the fee was added or not. |
---|
| 348 | ## We can only draw conclusions from from the student's entry |
---|
| 349 | ## session whether the fee had been included. |
---|
| 350 | #id_card_fee = gateway_net_amt(academic_session.id_card_fee) |
---|
| 351 | #text += ('School Fee, ' |
---|
| 352 | # '%s Naira Student ID Card Fee, ' |
---|
| 353 | # '%s Naira Student Union Dues, ' |
---|
| 354 | # '%s Naira Student Welfare Assurance Fee and ' |
---|
| 355 | # % (id_card_fee, union_fee, welfare_fee)) |
---|
| 356 | |
---|
[14244] | 357 | text += ('School Fee, ' |
---|
[14385] | 358 | 'Student ID Card Fee, ' |
---|
| 359 | 'Student Union Dues, ' |
---|
[15330] | 360 | 'Sports Fee, ' |
---|
| 361 | 'Library Levy, ' |
---|
[14385] | 362 | 'Student Welfare Assurance Fee and ') |
---|
[14244] | 363 | else: |
---|
[14385] | 364 | |
---|
| 365 | #text += ('School Fee, ' |
---|
| 366 | # '%s Naira Student Union Dues, ' |
---|
| 367 | # '%s Naira Student Welfare Assurance Fee and ' |
---|
| 368 | # % (union_fee, welfare_fee)) |
---|
| 369 | |
---|
[14244] | 370 | text += ('School Fee, ' |
---|
[14385] | 371 | 'Student Union Dues, ' |
---|
[15330] | 372 | 'Sports Development Fee, ' |
---|
| 373 | 'Library Development Levy, ' |
---|
[16934] | 374 | 'LMS + Sundry Fees, ' |
---|
[14385] | 375 | 'Student Welfare Assurance Fee and ') |
---|
[13410] | 376 | elif self.context.p_category in ( |
---|
| 377 | 'clearance_incl', 'clearance_medical_incl') and academic_session: |
---|
[14385] | 378 | |
---|
| 379 | #matric_gown_fee = gateway_net_amt(academic_session.matric_gown_fee) |
---|
| 380 | #lapel_fee = gateway_net_amt(academic_session.lapel_fee) |
---|
| 381 | #text += ('Acceptance Fee, ' |
---|
| 382 | # '%s Naira Matriculation Gown Fee, ' |
---|
| 383 | # '%s Naira Lapel/File Fee and ' |
---|
| 384 | # % (matric_gown_fee, lapel_fee)) |
---|
| 385 | |
---|
[13437] | 386 | text += ('Acceptance Fee, ' |
---|
[14385] | 387 | 'Matriculation Gown Fee, ' |
---|
| 388 | 'Lapel/File Fee and ') |
---|
[11625] | 389 | |
---|
[14385] | 390 | #return text + '250.0 Naira Transaction Charge.' |
---|
| 391 | |
---|
| 392 | return text + 'Transaction Charge.' |
---|
| 393 | |
---|
[14534] | 394 | class CustomStudyCourseManageFormPage(StudyCourseManageFormPage): |
---|
| 395 | """ Page to edit the student study course data |
---|
| 396 | """ |
---|
| 397 | grok.context(ICustomStudentStudyCourse) |
---|
| 398 | |
---|
| 399 | @property |
---|
| 400 | def form_fields(self): |
---|
| 401 | if self.context.is_postgrad: |
---|
| 402 | form_fields = grok.AutoFields(ICustomStudentStudyCourse).omit( |
---|
| 403 | 'previous_verdict') |
---|
| 404 | else: |
---|
| 405 | form_fields = grok.AutoFields(ICustomStudentStudyCourse) |
---|
| 406 | form_fields['imported_cgpa'].for_display = True |
---|
| 407 | return form_fields |
---|
| 408 | |
---|
[15461] | 409 | class CustomUnregisterCoursesView(UnregisterCoursesView): |
---|
| 410 | """Unregister course list by student |
---|
| 411 | """ |
---|
| 412 | grok.context(ICustomStudentStudyLevel) |
---|
[14981] | 413 | |
---|
[15461] | 414 | def update(self): |
---|
| 415 | if not self.context.__parent__.is_current: |
---|
| 416 | emit_lock_message(self) |
---|
| 417 | return |
---|
[15511] | 418 | #try: |
---|
| 419 | # academic_session = grok.getSite()['configuration'][ |
---|
| 420 | # str(self.context.level_session)] |
---|
| 421 | # if self.context.student.is_postgrad: |
---|
| 422 | # deadline = academic_session.coursereg_deadline_pg |
---|
| 423 | # elif self.context.student.current_mode.startswith('dp'): |
---|
| 424 | # deadline = academic_session.coursereg_deadline_dp |
---|
| 425 | # elif self.context.student.current_mode in ( |
---|
| 426 | # 'ug_pt', 'de_pt', 'de_dsh', 'ug_dsh'): |
---|
| 427 | # deadline = academic_session.coursereg_deadline_pt |
---|
| 428 | # elif self.context.student.current_mode == 'found': |
---|
| 429 | # deadline = academic_session.coursereg_deadline_found |
---|
| 430 | # elif self.context.student.current_mode == 'bridge': |
---|
| 431 | # deadline = academic_session.coursereg_deadline_bridge |
---|
| 432 | # else: |
---|
| 433 | # deadline = academic_session.coursereg_deadline |
---|
| 434 | #except (TypeError, KeyError): |
---|
| 435 | # deadline = None |
---|
| 436 | #if deadline and deadline < datetime.now(pytz.utc): |
---|
| 437 | # self.flash(_( |
---|
| 438 | # "Course registration has ended. " |
---|
| 439 | # "Unregistration is disabled."), type="danger") |
---|
[15512] | 440 | if str(self.context.__parent__.current_level) != self.context.__name__: |
---|
[15461] | 441 | self.flash(_('This is not your current level.'), type="danger") |
---|
| 442 | elif self.context.student.state == REGISTERED: |
---|
| 443 | IWorkflowInfo(self.context.student).fireTransition('reset7') |
---|
| 444 | message = _('Course list has been unregistered.') |
---|
| 445 | self.flash(message) |
---|
| 446 | else: |
---|
| 447 | self.flash(_('You are in the wrong state.'), type="warning") |
---|
| 448 | self.redirect(self.url(self.context)) |
---|
| 449 | return |
---|
[14981] | 450 | |
---|
[9914] | 451 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
| 452 | """ Page to display student study levels |
---|
| 453 | """ |
---|
| 454 | grok.context(ICustomStudentStudyLevel) |
---|
[10480] | 455 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
[14206] | 456 | 'total_credits', 'gpa', 'level', 'imported_gpa', 'imported_cgpa') |
---|
[9914] | 457 | form_fields[ |
---|
| 458 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 459 | |
---|
[14000] | 460 | @property |
---|
[15228] | 461 | def translated_values(self): |
---|
| 462 | return translated_values(self) |
---|
| 463 | |
---|
| 464 | @property |
---|
[14000] | 465 | def show_results(self): |
---|
| 466 | isStudent = getattr( |
---|
| 467 | self.request.principal, 'user_type', None) == 'student' |
---|
[14944] | 468 | try: |
---|
| 469 | show_results = grok.getSite()[ |
---|
| 470 | 'configuration'][str(self.context.level_session)].show_results |
---|
| 471 | except KeyError: |
---|
[14000] | 472 | return False |
---|
[14944] | 473 | if isStudent and self.context.student.current_mode not in show_results: |
---|
| 474 | return False |
---|
[15409] | 475 | #if isStudent and self.context.student.state != RETURNING \ |
---|
| 476 | # and self.context.student.current_level == self.context.level: |
---|
| 477 | # return False |
---|
[14000] | 478 | return True |
---|
| 479 | |
---|
[13834] | 480 | class CustomStudyLevelManageFormPage(StudyLevelManageFormPage): |
---|
| 481 | """ Page to edit the student study level data |
---|
| 482 | """ |
---|
| 483 | grok.context(ICustomStudentStudyLevel) |
---|
| 484 | |
---|
[14534] | 485 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
| 486 | 'validation_date', 'validated_by', 'total_credits', 'gpa', 'level', |
---|
| 487 | 'total_credits_s1', 'total_credits_s2') |
---|
| 488 | |
---|
| 489 | form_fields['imported_gpa'].for_display = True |
---|
| 490 | form_fields['imported_cgpa'].for_display = True |
---|
| 491 | |
---|
[13834] | 492 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
| 493 | """ Page to edit the student study level data by students |
---|
| 494 | """ |
---|
| 495 | grok.context(ICustomStudentStudyLevel) |
---|
| 496 | |
---|
[15330] | 497 | class StudyLevelRepairFormPage(KofaEditFormPage): |
---|
| 498 | """ Page to repair the student study level data by students |
---|
| 499 | """ |
---|
| 500 | grok.context(IStudentStudyLevel) |
---|
| 501 | grok.name('repair') |
---|
| 502 | grok.require('waeup.editStudyLevel') |
---|
| 503 | grok.template('studylevelrepairpage') |
---|
| 504 | pnav = 4 |
---|
| 505 | placeholder = _('Enter valid course code') |
---|
| 506 | |
---|
| 507 | def update(self, ADD=None, course=None): |
---|
[15340] | 508 | if not self.context.__parent__.is_current \ |
---|
| 509 | or self.context.student.studycourse_locked: |
---|
| 510 | emit_lock_message(self) |
---|
| 511 | return |
---|
[15330] | 512 | try: |
---|
| 513 | studylevel_repair_enabled = grok.getSite()['configuration'][ |
---|
| 514 | str(self.context.level_session)].studylevel_repair_enabled |
---|
| 515 | except KeyError: |
---|
| 516 | emit_lock_message(self) |
---|
| 517 | return |
---|
| 518 | if not studylevel_repair_enabled: |
---|
| 519 | emit_lock_message(self) |
---|
| 520 | return |
---|
| 521 | super(StudyLevelRepairFormPage, self).update() |
---|
| 522 | if ADD is not None: |
---|
| 523 | if not course: |
---|
| 524 | self.flash(_('No valid course code entered.'), type="warning") |
---|
| 525 | return |
---|
| 526 | cat = queryUtility(ICatalog, name='courses_catalog') |
---|
| 527 | result = cat.searchResults(code=(course, course)) |
---|
| 528 | if len(result) != 1: |
---|
| 529 | self.flash(_('Course not found.'), type="warning") |
---|
| 530 | return |
---|
| 531 | course = list(result)[0] |
---|
| 532 | addCourseTicket(self, course) |
---|
| 533 | return |
---|
| 534 | |
---|
| 535 | @property |
---|
| 536 | def label(self): |
---|
| 537 | # Here we know that the cookie has been set |
---|
| 538 | lang = self.request.cookies.get('kofa.language') |
---|
| 539 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
| 540 | target_language=lang) |
---|
| 541 | return _('Repair course list of ${a}', |
---|
| 542 | mapping = {'a':level_title}) |
---|
| 543 | |
---|
| 544 | @property |
---|
| 545 | def translated_values(self): |
---|
| 546 | return translated_values(self) |
---|
| 547 | |
---|
| 548 | def _delCourseTicket(self, **data): |
---|
| 549 | form = self.request.form |
---|
| 550 | if 'val_id' in form: |
---|
| 551 | child_id = form['val_id'] |
---|
| 552 | else: |
---|
| 553 | self.flash(_('No ticket selected.'), type="warning") |
---|
| 554 | self.redirect(self.url(self.context, '@@edit')) |
---|
| 555 | return |
---|
| 556 | if not isinstance(child_id, list): |
---|
| 557 | child_id = [child_id] |
---|
| 558 | deleted = [] |
---|
| 559 | for id in child_id: |
---|
| 560 | # Students are not allowed to remove core tickets |
---|
| 561 | if id in self.context and \ |
---|
| 562 | self.context[id].removable_by_student: |
---|
| 563 | del self.context[id] |
---|
| 564 | deleted.append(id) |
---|
| 565 | if len(deleted): |
---|
| 566 | self.flash(_('Successfully removed: ${a}', |
---|
| 567 | mapping = {'a':', '.join(deleted)})) |
---|
| 568 | self.context.writeLogMessage( |
---|
| 569 | self,'removed: %s at %s' % |
---|
| 570 | (', '.join(deleted), self.context.level)) |
---|
| 571 | self.redirect(self.url(self.context, u'@@repair')) |
---|
| 572 | return |
---|
| 573 | |
---|
| 574 | @jsaction(_('Remove selected tickets')) |
---|
| 575 | def delCourseTicket(self, **data): |
---|
| 576 | self._delCourseTicket(**data) |
---|
| 577 | return |
---|
| 578 | |
---|
[13059] | 579 | class CustomExportPDFCourseRegistrationSlip( |
---|
| 580 | NigeriaExportPDFCourseRegistrationSlip): |
---|
[9914] | 581 | """Deliver a PDF slip of the context. |
---|
| 582 | """ |
---|
| 583 | grok.context(ICustomStudentStudyLevel) |
---|
| 584 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
[10102] | 585 | 'level_session', 'level_verdict', |
---|
[14206] | 586 | 'validated_by', 'validation_date', 'gpa', 'level', |
---|
[16816] | 587 | 'imported_gpa', 'imported_cgpa', 'transcript_remark') |
---|
[9914] | 588 | |
---|
[10269] | 589 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
[10689] | 590 | 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', |
---|
[15408] | 591 | 'department', 'current_mode', 'current_level', 'flash_notice', |
---|
[16816] | 592 | ) |
---|
[10269] | 593 | |
---|
[14000] | 594 | @property |
---|
| 595 | def show_results(self): |
---|
| 596 | isStudent = getattr( |
---|
| 597 | self.request.principal, 'user_type', None) == 'student' |
---|
[14944] | 598 | try: |
---|
| 599 | show_results = grok.getSite()[ |
---|
| 600 | 'configuration'][str(self.context.level_session)].show_results |
---|
| 601 | except KeyError: |
---|
[14302] | 602 | return False |
---|
[14944] | 603 | if isStudent and self.context.student.current_mode not in show_results: |
---|
| 604 | return False |
---|
| 605 | if isStudent and self.context.student.state != RETURNING \ |
---|
| 606 | and self.context.student.current_level == self.context.level: |
---|
| 607 | return False |
---|
[14302] | 608 | return True |
---|
[14000] | 609 | |
---|
[13038] | 610 | def update(self): |
---|
| 611 | if self.context.student.state != REGISTERED \ |
---|
[13051] | 612 | and self.context.student.current_level == self.context.level: |
---|
[13038] | 613 | self.flash(_('Forbidden'), type="warning") |
---|
| 614 | self.redirect(self.url(self.context)) |
---|
[14000] | 615 | return |
---|
[13038] | 616 | |
---|
[9914] | 617 | @property |
---|
| 618 | def label(self): |
---|
| 619 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 620 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
| 621 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
| 622 | target_language=lang) |
---|
| 623 | line0 = '' |
---|
[13788] | 624 | if self.context.student.is_postgrad: |
---|
| 625 | line0 = 'SCHOOL OF POSTGRADUATE STUDIES\n' |
---|
| 626 | elif self.context.student.current_mode.endswith('_pt'): |
---|
[9914] | 627 | line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n' |
---|
[13866] | 628 | line1 = translate(_('Course Registration Slip'), |
---|
| 629 | target_language=portal_language) \ |
---|
[9914] | 630 | + ' %s' % level_title |
---|
[13866] | 631 | line2 = translate(_('Session'), |
---|
| 632 | target_language=portal_language) \ |
---|
[9914] | 633 | + ' %s' % self.context.getSessionString |
---|
| 634 | return '%s%s\n%s' % (line0, line1, line2) |
---|
| 635 | |
---|
| 636 | @property |
---|
| 637 | def title(self): |
---|
| 638 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 639 | return translate(_('Units Registered'), target_language=portal_language) |
---|
[9914] | 640 | |
---|
| 641 | def _signatures(self): |
---|
[15483] | 642 | if self.context.student.current_mode in ( |
---|
| 643 | 'ug_pt', 'de_pt', 'ug_dsh', 'de_dsh', 'found'): |
---|
[13647] | 644 | return ( |
---|
| 645 | [('I have selected the course on the advise of my Head of ' |
---|
| 646 | 'Department. <br>', _('Student\'s Signature'), '<br>')], |
---|
| 647 | [('This student has satisfied the department\'s requirements. ' |
---|
| 648 | 'I recommend to approve the course registration. <br>', |
---|
| 649 | _('Head of Department\'s Signature'), '<br>')], |
---|
[13946] | 650 | [('' , _('Deputy Registrar\'s Signature'), '<br>')], |
---|
[13647] | 651 | [('', _('Director\'s Signature'))] |
---|
| 652 | ) |
---|
| 653 | if self.context.student.current_mode in ( |
---|
[15457] | 654 | 'de_ft', 'ug_ft', 'dp_ft', 'transfer', 'bridge'): |
---|
[13649] | 655 | return ([_('Academic Adviser\'s Signature'), |
---|
| 656 | _('Faculty Officer\'s Signature'), |
---|
| 657 | _('Student\'s Signature')],) |
---|
| 658 | |
---|
[13647] | 659 | if self.context.student.current_mode in ('special_pg_ft', 'special_pg_pt'): |
---|
| 660 | return ( |
---|
[13676] | 661 | [('I declare that all items of information supplied above are correct:' , |
---|
[13680] | 662 | _('Student\'s Signature'), '<br>')], |
---|
[13676] | 663 | [('We approved the above registration:', |
---|
[13680] | 664 | _('Major Supervisor (Name / Signature)'), '')], |
---|
| 665 | [('', _('Co-Supervisor (Name / Signature)'), '')], |
---|
[13676] | 666 | [('', _('Head of Department'), '<br>')], |
---|
| 667 | [('The student has satisfied the conditions for renewal of ' |
---|
| 668 | 'registration for graduate school programme in this university:', |
---|
[13680] | 669 | _('Secretary <br /> (School of Postgraduate Studies)'), '')], |
---|
| 670 | [('', _('Dean <br /> (School of Postgraduate Studies)'), '')], |
---|
[13647] | 671 | ) |
---|
| 672 | return None |
---|
[9914] | 673 | |
---|
[13647] | 674 | |
---|
[9914] | 675 | def render(self): |
---|
[16041] | 676 | if not self.context.student.current_mode: |
---|
| 677 | self.flash('No certificate assigned.', type="danger") |
---|
| 678 | self.redirect(self.url(self.context)) |
---|
| 679 | return |
---|
[9914] | 680 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[16968] | 681 | Sem = translate(_('Term'), target_language=portal_language) |
---|
[13866] | 682 | Code = translate(_('Code'), target_language=portal_language) |
---|
| 683 | Title = translate(_('Title'), target_language=portal_language) |
---|
| 684 | Cred = translate(_('Cred.'), target_language=portal_language) |
---|
[14650] | 685 | CC = translate(_('Cat.'), target_language=portal_language) |
---|
[14000] | 686 | if self.show_results: |
---|
[15317] | 687 | TotalScore = translate(_('Total Score'), target_language=portal_language) |
---|
[14000] | 688 | #CA = translate(_('CA'), target_language=portal_language) |
---|
| 689 | Grade = translate(_('Grade'), target_language=portal_language) |
---|
[13866] | 690 | Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue', |
---|
[9914] | 691 | target_language=portal_language) |
---|
| 692 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 693 | self.request, self.omit_fields) |
---|
| 694 | students_utils = getUtility(IStudentsUtils) |
---|
[10442] | 695 | |
---|
| 696 | tabledata = [] |
---|
| 697 | tableheader = [] |
---|
| 698 | contenttitle = [] |
---|
| 699 | for i in range(1,7): |
---|
| 700 | tabledata.append(sorted( |
---|
[16041] | 701 | [value for value in self.context.values() |
---|
| 702 | if value.semester == i and not value.outstanding], |
---|
| 703 | key=lambda value: str(value.semester) + value.code)) |
---|
[14000] | 704 | if self.show_results: |
---|
| 705 | tableheader.append([(Code,'code', 2.0), |
---|
| 706 | (Title,'title', 7), |
---|
[14650] | 707 | (Cred, 'credits', 1.4), |
---|
| 708 | (CC, 'course_category', 1.2), |
---|
[15317] | 709 | (TotalScore, 'total_score', 1.4), |
---|
[14000] | 710 | #(CA, 'ca', 1.4), |
---|
| 711 | (Grade, 'grade', 1.4), |
---|
| 712 | (Signature, 'dummy', 3), |
---|
| 713 | ]) |
---|
| 714 | else: |
---|
| 715 | tableheader.append([(Code,'code', 2.0), |
---|
| 716 | (Title,'title', 7), |
---|
| 717 | (Cred, 'credits', 1.5), |
---|
[14650] | 718 | (CC, 'course_category', 1.2), |
---|
[14000] | 719 | (Signature, 'dummy', 3), |
---|
| 720 | ]) |
---|
[9914] | 721 | if len(self.label.split('\n')) == 3: |
---|
| 722 | topMargin = 1.9 |
---|
| 723 | elif len(self.label.split('\n')) == 2: |
---|
| 724 | topMargin = 1.7 |
---|
| 725 | else: |
---|
| 726 | topMargin = 1.5 |
---|
| 727 | return students_utils.renderPDF( |
---|
| 728 | self, 'course_registration_slip.pdf', |
---|
| 729 | self.context.student, studentview, |
---|
[10442] | 730 | tableheader=tableheader, |
---|
| 731 | tabledata=tabledata, |
---|
[9914] | 732 | signatures=self._signatures(), |
---|
[10269] | 733 | topMargin=topMargin, |
---|
| 734 | omit_fields=self.omit_fields |
---|
[9914] | 735 | ) |
---|
[10566] | 736 | |
---|
[14165] | 737 | class CustomStudyCourseTranscriptPage(StudyCourseTranscriptPage): |
---|
| 738 | """ Page to display the student's transcript. |
---|
| 739 | """ |
---|
| 740 | grok.require('waeup.viewStudent') |
---|
| 741 | |
---|
[13059] | 742 | class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip): |
---|
[10566] | 743 | """Deliver a PDF slip of the context. |
---|
| 744 | """ |
---|
| 745 | |
---|
[14267] | 746 | note = _(""" |
---|
| 747 | <br /><br /><br /><br /> |
---|
| 748 | <font size='10'> |
---|
| 749 | <strong>Note:</strong> This copy is subject to correction for typographical errors and ratification by the departmental board. |
---|
| 750 | </font> |
---|
| 751 | """) |
---|
| 752 | |
---|
[10566] | 753 | def _sigsInFooter(self): |
---|
| 754 | return [] |
---|
| 755 | |
---|
| 756 | def _signatures(self): |
---|
[10922] | 757 | |
---|
[16143] | 758 | #if self.context.student.state == GRADUATED: |
---|
| 759 | # return ([( |
---|
| 760 | # 'O.O OHIKHENA (Manupa)<br />' |
---|
| 761 | # 'Principal Asst. Registrar<br /> ' |
---|
| 762 | # 'Exams, Records and Data Processing Division <br /> ' |
---|
| 763 | # 'For: Registrar')],) |
---|
| 764 | #elif self.context.certificate is not None: |
---|
| 765 | # dep = self.context.certificate.__parent__.__parent__ |
---|
| 766 | # if dep.officer_1: |
---|
| 767 | # return ([(dep.officer_1)],) |
---|
| 768 | #return |
---|
| 769 | |
---|
| 770 | return ([( |
---|
[17430] | 771 | 'F.O. Omoigui, MANUPA<br />' |
---|
| 772 | 'Principal Assistant Registrar<br /> ' |
---|
[16143] | 773 | 'Exams, Records and Data Processing Division <br /> ' |
---|
| 774 | 'For: Registrar')],) |
---|
| 775 | |
---|
[13834] | 776 | def render(self): |
---|
| 777 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[16968] | 778 | Term = translate(_('Term'), target_language=portal_language) |
---|
[13866] | 779 | Code = translate(_('Code'), target_language=portal_language) |
---|
| 780 | Title = translate(_('Title'), target_language=portal_language) |
---|
| 781 | Cred = translate(_('Credits'), target_language=portal_language) |
---|
| 782 | Score = translate(_('Score'), target_language=portal_language) |
---|
| 783 | Grade = translate(_('Grade'), target_language=portal_language) |
---|
[13834] | 784 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 785 | self.request, self.omit_fields) |
---|
| 786 | students_utils = getUtility(IStudentsUtils) |
---|
| 787 | |
---|
| 788 | tableheader = [(Code,'code', 2.5), |
---|
| 789 | (Title,'title', 7), |
---|
| 790 | (Term, 'semester', 1.5), |
---|
| 791 | (Cred, 'credits', 1.5), |
---|
[14136] | 792 | (Score, 'total_score', 1.5), |
---|
[13834] | 793 | (Grade, 'grade', 1.5), |
---|
| 794 | ] |
---|
| 795 | |
---|
[15165] | 796 | pdfstream = students_utils.renderPDFTranscript( |
---|
[13834] | 797 | self, 'transcript.pdf', |
---|
| 798 | self.context.student, studentview, |
---|
| 799 | omit_fields=self.omit_fields, |
---|
| 800 | tableheader=tableheader, |
---|
| 801 | signatures=self._signatures(), |
---|
| 802 | sigs_in_footer=self._sigsInFooter(), |
---|
[15165] | 803 | digital_sigs=self._digital_sigs(), |
---|
| 804 | save_file=self._save_file(), |
---|
[13834] | 805 | ) |
---|
[15165] | 806 | if not pdfstream: |
---|
| 807 | self.redirect(self.url(self.context.student)) |
---|
| 808 | return |
---|
| 809 | return pdfstream |
---|
[13834] | 810 | |
---|
[16967] | 811 | class ExportPDFTranscriptStudViewSlip(CustomExportPDFTranscriptSlip): |
---|
| 812 | """Deliver a PDF slip of the context. |
---|
| 813 | """ |
---|
| 814 | |
---|
| 815 | grok.name('transcript_studview.pdf') |
---|
| 816 | |
---|
| 817 | def render(self): |
---|
| 818 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[16968] | 819 | Term = translate(_('Term'), target_language=portal_language) |
---|
[16967] | 820 | Code = translate(_('Code'), target_language=portal_language) |
---|
| 821 | Title = translate(_('Title'), target_language=portal_language) |
---|
| 822 | Cred = translate(_('Credits'), target_language=portal_language) |
---|
| 823 | #Score = translate(_('Score'), target_language=portal_language) |
---|
| 824 | Grade = translate(_('Grade'), target_language=portal_language) |
---|
| 825 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 826 | self.request, self.omit_fields) |
---|
| 827 | students_utils = getUtility(IStudentsUtils) |
---|
| 828 | |
---|
| 829 | tableheader = [(Code,'code', 2.5), |
---|
| 830 | (Title,'title', 7), |
---|
| 831 | (Term, 'semester', 1.5), |
---|
| 832 | (Cred, 'credits', 1.5), |
---|
| 833 | #(Score, 'total_score', 1.5), |
---|
| 834 | (Grade, 'grade', 1.5), |
---|
| 835 | ] |
---|
| 836 | |
---|
| 837 | pdfstream = students_utils.renderPDFTranscript( |
---|
| 838 | self, 'transcript.pdf', |
---|
| 839 | self.context.student, studentview, |
---|
| 840 | omit_fields=self.omit_fields, |
---|
| 841 | tableheader=tableheader, |
---|
| 842 | signatures=self._signatures(), |
---|
| 843 | sigs_in_footer=self._sigsInFooter(), |
---|
| 844 | digital_sigs=self._digital_sigs(), |
---|
| 845 | save_file=self._save_file(), |
---|
| 846 | ) |
---|
| 847 | if not pdfstream: |
---|
| 848 | self.redirect(self.url(self.context.student)) |
---|
| 849 | return |
---|
| 850 | return pdfstream |
---|
| 851 | |
---|
[13059] | 852 | class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip): |
---|
[10922] | 853 | """Deliver a PDF Admission slip. |
---|
| 854 | """ |
---|
| 855 | |
---|
| 856 | @property |
---|
| 857 | def label(self): |
---|
| 858 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 859 | return translate(_('e-Admission Slip \n'), |
---|
| 860 | target_language=portal_language) \ |
---|
[10922] | 861 | + ' %s' % self.context.display_fullname |
---|
[11597] | 862 | |
---|
[13059] | 863 | class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip): |
---|
[11606] | 864 | """Deliver a PDF slip of the context. |
---|
| 865 | """ |
---|
| 866 | |
---|
| 867 | @property |
---|
| 868 | def label(self): |
---|
| 869 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[14114] | 870 | return translate(_('Verification/Clearance Slip\n'), |
---|
[13866] | 871 | target_language=portal_language) \ |
---|
[11606] | 872 | + ' %s' % self.context.display_fullname |
---|
| 873 | |
---|
[14084] | 874 | @property |
---|
| 875 | def form_fields(self): |
---|
| 876 | if self.context.is_postgrad: |
---|
| 877 | form_fields = grok.AutoFields( |
---|
| 878 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
| 879 | else: |
---|
| 880 | form_fields = grok.AutoFields( |
---|
| 881 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
| 882 | if not getattr(self.context, 'officer_comment'): |
---|
| 883 | form_fields = form_fields.omit('officer_comment') |
---|
[14104] | 884 | form_fields = form_fields.omit('def_adm') |
---|
[14084] | 885 | return form_fields |
---|
| 886 | |
---|
[11597] | 887 | class StudentGetMatricNumberPage(UtilityView, grok.View): |
---|
| 888 | """ Construct and set the matriculation number. |
---|
| 889 | """ |
---|
| 890 | grok.context(IStudent) |
---|
| 891 | grok.name('get_matric_number') |
---|
| 892 | grok.require('waeup.viewStudent') |
---|
| 893 | |
---|
| 894 | def update(self): |
---|
| 895 | students_utils = getUtility(IStudentsUtils) |
---|
| 896 | msg, mnumber = students_utils.setMatricNumber(self.context) |
---|
| 897 | if msg: |
---|
| 898 | self.flash(msg, type="danger") |
---|
| 899 | else: |
---|
| 900 | self.flash(_('Matriculation number %s assigned.' % mnumber)) |
---|
[11602] | 901 | self.context.writeLogMessage(self, '%s assigned' % mnumber) |
---|
[11597] | 902 | self.redirect(self.url(self.context)) |
---|
| 903 | return |
---|
| 904 | |
---|
| 905 | def render(self): |
---|
[11607] | 906 | return |
---|
| 907 | |
---|
[13059] | 908 | class ExportPDFMatricNumberSlip(UtilityView, grok.View): |
---|
[11607] | 909 | """Deliver a PDF notification slip. |
---|
| 910 | """ |
---|
| 911 | grok.context(ICustomStudent) |
---|
| 912 | grok.name('matric_number_slip.pdf') |
---|
| 913 | grok.require('waeup.viewStudent') |
---|
| 914 | prefix = 'form' |
---|
| 915 | |
---|
| 916 | form_fields = grok.AutoFields(ICustomStudent).select( |
---|
| 917 | 'student_id', 'matric_number') |
---|
[13713] | 918 | omit_fields = ('date_of_birth', 'current_level', 'flash_notice') |
---|
[11607] | 919 | |
---|
| 920 | @property |
---|
[13489] | 921 | def title(self): |
---|
| 922 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 923 | return translate(_('Matriculation Number'), 'waeup.kofa', |
---|
[13489] | 924 | target_language=portal_language) |
---|
| 925 | |
---|
| 926 | @property |
---|
[11607] | 927 | def label(self): |
---|
| 928 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 929 | return translate(_('Matriculation Number Slip\n'), |
---|
| 930 | target_language=portal_language) \ |
---|
[11607] | 931 | + ' %s' % self.context.display_fullname |
---|
| 932 | |
---|
| 933 | def render(self): |
---|
| 934 | if self.context.state not in (PAID,) or not self.context.is_fresh \ |
---|
| 935 | or not self.context.matric_number: |
---|
| 936 | self.flash('Not allowed.', type="danger") |
---|
| 937 | self.redirect(self.url(self.context)) |
---|
| 938 | return |
---|
| 939 | students_utils = getUtility(IStudentsUtils) |
---|
[11609] | 940 | pre_text = _('Congratulations! Your acceptance fee and school fees ' + |
---|
| 941 | 'payments have been received and your matriculation ' + |
---|
| 942 | 'number generated with details as follows.') |
---|
[11607] | 943 | return students_utils.renderPDFAdmissionLetter(self, |
---|
| 944 | self.context.student, omit_fields=self.omit_fields, |
---|
[13353] | 945 | pre_text=pre_text, post_text='') |
---|
| 946 | |
---|
[13489] | 947 | class ExportPersonalDataSlip(UtilityView, grok.View): |
---|
| 948 | """Deliver a PDF notification slip. |
---|
| 949 | """ |
---|
| 950 | grok.context(ICustomStudent) |
---|
| 951 | grok.name('personal_data_slip.pdf') |
---|
| 952 | grok.require('waeup.viewStudent') |
---|
| 953 | prefix = 'form' |
---|
| 954 | note = None |
---|
| 955 | |
---|
| 956 | form_fields = grok.AutoFields(ICustomStudentPersonal).omit('personal_updated') |
---|
[13713] | 957 | omit_fields = ('suspended', 'suspended_comment', 'adm_code', |
---|
| 958 | 'certificate', 'flash_notice') |
---|
[13489] | 959 | |
---|
| 960 | @property |
---|
| 961 | def title(self): |
---|
| 962 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 963 | return translate(_('Personal Data'), 'waeup.kofa', |
---|
[13489] | 964 | target_language=portal_language) |
---|
| 965 | |
---|
| 966 | @property |
---|
| 967 | def label(self): |
---|
| 968 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 969 | return translate(_('Personal Data Slip\n'), |
---|
| 970 | target_language=portal_language) \ |
---|
[13489] | 971 | + ' %s' % self.context.display_fullname |
---|
| 972 | |
---|
| 973 | def render(self): |
---|
| 974 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 975 | self.request, self.omit_fields) |
---|
| 976 | students_utils = getUtility(IStudentsUtils) |
---|
| 977 | return students_utils.renderPDF(self, 'personal_data_slip.pdf', |
---|
| 978 | self.context.student, studentview, note=self.note, |
---|
| 979 | omit_fields=self.omit_fields) |
---|
| 980 | |
---|
[15976] | 981 | class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage): |
---|
| 982 | """ Page to view bed tickets. |
---|
| 983 | """ |
---|
| 984 | with_hostel_selection = True |
---|
| 985 | |
---|
[13462] | 986 | class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage): |
---|
| 987 | """ Page to manage bed tickets. |
---|
| 988 | This manage form page is for both students and students officers. |
---|
| 989 | """ |
---|
| 990 | with_hostel_selection = True |
---|
| 991 | |
---|
[15713] | 992 | class CustomBedTicketAddPage(NigeriaBedTicketAddPage): |
---|
[13360] | 993 | with_ac = False |
---|
[13380] | 994 | |
---|
| 995 | class CustomStudentFilesUploadPage(StudentFilesUploadPage): |
---|
| 996 | """ View to upload files by student. Inherit from same class in |
---|
| 997 | base package, not from kofacustom.nigeria which |
---|
| 998 | requires that no application slip exists. |
---|
[13770] | 999 | """ |
---|
| 1000 | |
---|
| 1001 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
| 1002 | """ Page to display course tickets |
---|
| 1003 | """ |
---|
| 1004 | |
---|
[14453] | 1005 | @property |
---|
| 1006 | def show_results(self): |
---|
| 1007 | isStudent = getattr( |
---|
| 1008 | self.request.principal, 'user_type', None) == 'student' |
---|
| 1009 | if isStudent: |
---|
| 1010 | return False |
---|
| 1011 | return True |
---|
| 1012 | |
---|
| 1013 | @property |
---|
| 1014 | def form_fields(self): |
---|
| 1015 | if self.show_results: |
---|
| 1016 | return grok.AutoFields(ICustomCourseTicket) |
---|
| 1017 | else: |
---|
| 1018 | return grok.AutoFields(ICustomCourseTicket).omit('score').omit('ca') |
---|
| 1019 | |
---|
[13770] | 1020 | class CustomCourseTicketManageFormPage(CourseTicketManageFormPage): |
---|
| 1021 | """ Page to manage course tickets |
---|
| 1022 | """ |
---|
| 1023 | form_fields = grok.AutoFields(ICustomCourseTicket) |
---|
| 1024 | form_fields['title'].for_display = True |
---|
| 1025 | form_fields['fcode'].for_display = True |
---|
| 1026 | form_fields['dcode'].for_display = True |
---|
| 1027 | form_fields['semester'].for_display = True |
---|
| 1028 | form_fields['passmark'].for_display = True |
---|
| 1029 | form_fields['credits'].for_display = True |
---|
| 1030 | form_fields['mandatory'].for_display = False |
---|
| 1031 | form_fields['automatic'].for_display = True |
---|
| 1032 | form_fields['carry_over'].for_display = True |
---|
[15205] | 1033 | form_fields['ticket_session'].for_display = True |
---|
[15226] | 1034 | form_fields['imported_ts'].for_display = True |
---|
[13770] | 1035 | |
---|
| 1036 | class CustomEditScoresPage(EditScoresPage): |
---|
| 1037 | """Page that filters and lists students. |
---|
| 1038 | """ |
---|
| 1039 | grok.template('editscorespage') |
---|
| 1040 | |
---|
[14700] | 1041 | def _searchCatalog(self, session): |
---|
| 1042 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
---|
| 1043 | coursetickets = cat.searchResults( |
---|
[15876] | 1044 | session=(session, session), |
---|
[14700] | 1045 | code=(self.context.code, self.context.code) |
---|
| 1046 | ) |
---|
| 1047 | try: |
---|
| 1048 | score_editing_enabled = grok.getSite()[ |
---|
| 1049 | 'configuration'][str(session)].score_editing_enabled |
---|
| 1050 | except KeyError: |
---|
| 1051 | return [] |
---|
[14707] | 1052 | coursetickets_list = [courseticket for courseticket in coursetickets |
---|
| 1053 | if courseticket.student.current_mode in score_editing_enabled] |
---|
[14700] | 1054 | return coursetickets_list |
---|
[13937] | 1055 | |
---|
| 1056 | def _extract_uploadfile(self, uploadfile): |
---|
| 1057 | """Get a mapping of student-ids to scores. |
---|
| 1058 | |
---|
| 1059 | The mapping is constructed by reading contents from `uploadfile`. |
---|
| 1060 | |
---|
| 1061 | We expect uploadfile to be a regular CSV file with columns |
---|
[15414] | 1062 | ``student_id``, ``score``, ``imported_ts`` |
---|
| 1063 | and ``ca`` (other cols are ignored). |
---|
[13937] | 1064 | """ |
---|
| 1065 | result = dict() |
---|
| 1066 | data = StringIO(uploadfile.read()) # ensure we have something seekable |
---|
| 1067 | reader = csv.DictReader(data) |
---|
| 1068 | for row in reader: |
---|
[15414] | 1069 | if not ('student_id' in row and 'score' in row and 'ca' in row and |
---|
| 1070 | 'imported_ts' in row): |
---|
[13937] | 1071 | continue |
---|
[15414] | 1072 | result[row['student_id']] = ( |
---|
| 1073 | row['score'], row['ca'], row['imported_ts']) |
---|
[13937] | 1074 | return result |
---|
| 1075 | |
---|
[14288] | 1076 | def _update_scores(self, form): |
---|
[13937] | 1077 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.', '') |
---|
[14288] | 1078 | error = '' |
---|
[13937] | 1079 | if 'UPDATE_FILE' in form: |
---|
| 1080 | if form['uploadfile']: |
---|
| 1081 | try: |
---|
| 1082 | formvals = self._extract_uploadfile(form['uploadfile']) |
---|
| 1083 | except: |
---|
| 1084 | self.flash( |
---|
| 1085 | _('Uploaded file contains illegal data. Ignored'), |
---|
| 1086 | type="danger") |
---|
[14288] | 1087 | return False |
---|
[13937] | 1088 | else: |
---|
| 1089 | self.flash( |
---|
| 1090 | _('No file provided.'), type="danger") |
---|
[14288] | 1091 | return False |
---|
[13937] | 1092 | else: |
---|
[15414] | 1093 | formvals = dict(zip(form['sids'], zip( |
---|
[15822] | 1094 | form['scores'], form['cas'], form['imported_ts']))) |
---|
[14149] | 1095 | for ticket in self.editable_tickets: |
---|
[13937] | 1096 | ticket_error = False |
---|
| 1097 | score = ticket.score |
---|
| 1098 | ca = ticket.ca |
---|
[15414] | 1099 | imported_ts = ticket.imported_ts |
---|
[13937] | 1100 | sid = ticket.student.student_id |
---|
[15896] | 1101 | if sid not in formvals: |
---|
| 1102 | continue |
---|
[13937] | 1103 | if formvals[sid][0] == '': |
---|
| 1104 | score = None |
---|
| 1105 | if formvals[sid][1] == '': |
---|
| 1106 | ca = None |
---|
[15414] | 1107 | if formvals[sid][2] == '': |
---|
| 1108 | imported_ts = None |
---|
[13937] | 1109 | try: |
---|
| 1110 | if formvals[sid][0]: |
---|
| 1111 | score = int(formvals[sid][0]) |
---|
| 1112 | if formvals[sid][1]: |
---|
| 1113 | ca = int(formvals[sid][1]) |
---|
[15414] | 1114 | if formvals[sid][2]: |
---|
| 1115 | imported_ts = int(formvals[sid][2]) |
---|
[13937] | 1116 | except ValueError: |
---|
| 1117 | error += '%s, ' % ticket.student.display_fullname |
---|
| 1118 | ticket_error = True |
---|
[16240] | 1119 | if score and ca and not ticket_error and score + ca > 100: |
---|
| 1120 | error += '%s, ' % ticket.student.display_fullname |
---|
| 1121 | ticket_error = True |
---|
[13937] | 1122 | if not ticket_error and ticket.score != score: |
---|
[14113] | 1123 | try: |
---|
| 1124 | ticket.score = score |
---|
| 1125 | except TooBig: |
---|
| 1126 | error += '%s, ' % ticket.student.display_fullname |
---|
| 1127 | ticket_error = True |
---|
| 1128 | pass |
---|
[13937] | 1129 | ticket.student.__parent__.logger.info( |
---|
| 1130 | '%s - %s %s/%s score updated (%s)' % |
---|
| 1131 | (ob_class, ticket.student.student_id, |
---|
| 1132 | ticket.level, ticket.code, score)) |
---|
| 1133 | if not ticket_error and ticket.ca != ca: |
---|
[14113] | 1134 | try: |
---|
| 1135 | ticket.ca = ca |
---|
| 1136 | except TooBig: |
---|
| 1137 | error += '%s, ' % ticket.student.display_fullname |
---|
| 1138 | pass |
---|
[13937] | 1139 | ticket.student.__parent__.logger.info( |
---|
| 1140 | '%s - %s %s/%s ca updated (%s)' % |
---|
| 1141 | (ob_class, ticket.student.student_id, |
---|
| 1142 | ticket.level, ticket.code, ca)) |
---|
[15414] | 1143 | if not ticket_error and ticket.imported_ts != imported_ts: |
---|
| 1144 | try: |
---|
| 1145 | ticket.imported_ts = imported_ts |
---|
| 1146 | except TooBig: |
---|
| 1147 | error += '%s, ' % ticket.student.display_fullname |
---|
| 1148 | pass |
---|
| 1149 | ticket.student.__parent__.logger.info( |
---|
| 1150 | '%s - %s %s/%s imported_ts updated (%s)' % |
---|
| 1151 | (ob_class, ticket.student.student_id, |
---|
| 1152 | ticket.level, ticket.code, imported_ts)) |
---|
[13937] | 1153 | if error: |
---|
[15414] | 1154 | self.flash(_('Error: Score(s), CA(s) and Imported TS(s) of %s have not be updated. ' |
---|
[14113] | 1155 | % error.strip(', ')), type="danger") |
---|
[14288] | 1156 | return True |
---|
| 1157 | |
---|
| 1158 | class EditPreviousSessionScoresPage(CustomEditScoresPage): |
---|
| 1159 | |
---|
| 1160 | grok.name('edit_prev_scores') |
---|
| 1161 | |
---|
| 1162 | def update(self, *args, **kw): |
---|
| 1163 | form = self.request.form |
---|
| 1164 | self.current_academic_session = grok.getSite()[ |
---|
| 1165 | 'configuration'].current_academic_session |
---|
| 1166 | if self.context.__parent__.__parent__.score_editing_disabled: |
---|
| 1167 | self.flash(_('Score editing disabled.'), type="warning") |
---|
| 1168 | self.redirect(self.url(self.context)) |
---|
[13939] | 1169 | return |
---|
[14288] | 1170 | if not self.current_academic_session: |
---|
| 1171 | self.flash(_('Current academic session not set.'), type="warning") |
---|
| 1172 | self.redirect(self.url(self.context)) |
---|
| 1173 | return |
---|
| 1174 | previous_session = self.current_academic_session - 1 |
---|
| 1175 | self.session_title = academic_sessions_vocab.getTerm( |
---|
| 1176 | previous_session).title |
---|
| 1177 | self.tickets = self._searchCatalog(previous_session) |
---|
| 1178 | if not self.tickets: |
---|
| 1179 | self.flash(_('No student found.'), type="warning") |
---|
| 1180 | self.redirect(self.url(self.context)) |
---|
| 1181 | return |
---|
| 1182 | self.editable_tickets = [ |
---|
| 1183 | ticket for ticket in self.tickets if ticket.editable_by_lecturer] |
---|
| 1184 | if not 'UPDATE_TABLE' in form and not 'UPDATE_FILE' in form: |
---|
| 1185 | return |
---|
| 1186 | if not self.editable_tickets: |
---|
| 1187 | return |
---|
| 1188 | success = self._update_scores(form) |
---|
| 1189 | if success: |
---|
| 1190 | self.flash(_('You successfully updated course results.')) |
---|
[13900] | 1191 | return |
---|
| 1192 | |
---|
| 1193 | class CustomExportPDFScoresSlip(ExportPDFScoresSlip): |
---|
| 1194 | """Deliver a PDF slip of course tickets for a lecturer. |
---|
| 1195 | """ |
---|
| 1196 | |
---|
[15343] | 1197 | note = u'\nUpgraded scores are with asterisks.' |
---|
[15247] | 1198 | |
---|
[14315] | 1199 | def data(self, session): |
---|
[14704] | 1200 | #site = grok.getSite() |
---|
[13900] | 1201 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
---|
| 1202 | coursetickets = cat.searchResults( |
---|
| 1203 | session=(session, session), |
---|
| 1204 | code=(self.context.code, self.context.code) |
---|
| 1205 | ) |
---|
[14707] | 1206 | # Apply filter |
---|
| 1207 | try: |
---|
| 1208 | score_editing_enabled = grok.getSite()[ |
---|
| 1209 | 'configuration'][str(session)].score_editing_enabled |
---|
[15453] | 1210 | if checkPermission('waeup.manageAcademics', self.context): |
---|
| 1211 | score_editing_enabled = True |
---|
[14707] | 1212 | coursetickets_filtered = [courseticket |
---|
| 1213 | for courseticket in coursetickets |
---|
[15454] | 1214 | if (checkPermission('waeup.manageAcademics', self.context) |
---|
| 1215 | or (courseticket.student.current_mode in |
---|
| 1216 | score_editing_enabled)) |
---|
[15236] | 1217 | and courseticket.total_score is not None |
---|
| 1218 | and courseticket.__parent__.__parent__.is_current] |
---|
[14707] | 1219 | except KeyError: |
---|
| 1220 | coursetickets_filtered = coursetickets |
---|
[15631] | 1221 | # In AAUE only editable tickets can be printed (deactivated on 02/10/19) |
---|
| 1222 | #editable_tickets = [ |
---|
| 1223 | # ticket for ticket in coursetickets_filtered |
---|
| 1224 | # if ticket.editable_by_lecturer] |
---|
[13963] | 1225 | header = [[_(''), |
---|
[15006] | 1226 | _('Student Id'), |
---|
[13963] | 1227 | _('Matric No.'), |
---|
[14703] | 1228 | #_('Reg. No.'), |
---|
| 1229 | #_('Fullname'), |
---|
| 1230 | #_('Status'), |
---|
| 1231 | #_('Course of\nStudies'), |
---|
[14704] | 1232 | _('Department'), |
---|
[13900] | 1233 | _('Level'), |
---|
[15201] | 1234 | _(' CA '), |
---|
| 1235 | _('Exam\nScore'), |
---|
[13964] | 1236 | _('Total '), |
---|
[13963] | 1237 | _('Grade'), |
---|
| 1238 | ],] |
---|
[15631] | 1239 | sorted_tickets = sorted(coursetickets_filtered, # editable_tickets, |
---|
[15912] | 1240 | key=lambda ticket: str(ticket.student.depcode) |
---|
| 1241 | + str(ticket.student.faccode) |
---|
[15911] | 1242 | + str(ticket.student.matric_number) |
---|
[15910] | 1243 | ) |
---|
[14288] | 1244 | no = 1 |
---|
[13907] | 1245 | tickets = [] |
---|
[14315] | 1246 | passed = 0 |
---|
| 1247 | failed = 0 |
---|
[15229] | 1248 | with_ca = False |
---|
[15822] | 1249 | grade_stats = {'A':0, 'B':0, 'C':0, 'D':0, 'E':0, 'F':0, } |
---|
[14288] | 1250 | for ticket in sorted_tickets: |
---|
[15229] | 1251 | if ticket.ca > 0: |
---|
| 1252 | with_ca = True |
---|
[15006] | 1253 | total = ticket.total_score |
---|
[15232] | 1254 | if getattr(ticket, 'imported_ts', None): |
---|
[15245] | 1255 | total = "**%s**" % ticket.imported_ts |
---|
[15006] | 1256 | grade = ticket._getGradeWeightFromScore[0] |
---|
[15822] | 1257 | if grade in grade_stats.keys(): |
---|
| 1258 | grade_stats[grade] += 1 |
---|
[15006] | 1259 | if grade in ('F', '-'): |
---|
| 1260 | failed += 1 |
---|
[13963] | 1261 | else: |
---|
[15006] | 1262 | passed += 1 |
---|
[13964] | 1263 | fullname = textwrap.fill(ticket.student.display_fullname, 30) |
---|
[14704] | 1264 | #deptitle = site['faculties'][ticket.student.faccode][ |
---|
| 1265 | # ticket.student.depcode].longtitle |
---|
[15240] | 1266 | row = [str(no), |
---|
[15006] | 1267 | ticket.student.student_id, |
---|
[13963] | 1268 | ticket.student.matric_number, |
---|
[14703] | 1269 | #ticket.student.reg_number, |
---|
| 1270 | #fullname, |
---|
| 1271 | #ticket.student.translated_state, |
---|
| 1272 | #ticket.student.certcode, |
---|
[15913] | 1273 | str(ticket.student.faccode) + ' / ' + str(ticket.student.depcode), |
---|
[13900] | 1274 | ticket.level, |
---|
[15201] | 1275 | ticket.ca, |
---|
| 1276 | ticket.score, |
---|
[13963] | 1277 | total, |
---|
[13964] | 1278 | grade, |
---|
[13963] | 1279 | ] |
---|
[13907] | 1280 | tickets.append(row) |
---|
[13963] | 1281 | no += 1 |
---|
[14317] | 1282 | total = passed + failed |
---|
[14320] | 1283 | passed_perc = 0 |
---|
| 1284 | failed_perc = 0 |
---|
[14317] | 1285 | if total: |
---|
[15408] | 1286 | passed_perc = round(100.0 * passed / total) |
---|
| 1287 | failed_perc = round(100.0 * failed / total) |
---|
[14710] | 1288 | dep = self.context.__parent__.__parent__.longtitle |
---|
| 1289 | fac = self.context.__parent__.__parent__.__parent__.longtitle |
---|
[15229] | 1290 | # remove CA column if not necessary |
---|
| 1291 | if not with_ca: |
---|
| 1292 | header = [[_(''), |
---|
| 1293 | _('Student Id'), |
---|
| 1294 | _('Matric No.'), |
---|
| 1295 | #_('Reg. No.'), |
---|
| 1296 | #_('Fullname'), |
---|
| 1297 | #_('Status'), |
---|
| 1298 | #_('Course of\nStudies'), |
---|
| 1299 | _('Department'), |
---|
| 1300 | _('Level'), |
---|
| 1301 | #_(' CA '), |
---|
| 1302 | _('Exam\nScore'), |
---|
| 1303 | _('Total '), |
---|
| 1304 | _('Grade'), |
---|
| 1305 | ],] |
---|
| 1306 | for ticket in tickets: |
---|
| 1307 | del(ticket[5]) |
---|
[14320] | 1308 | return header + tickets, [ |
---|
[15822] | 1309 | dep, fac, total, passed, passed_perc, failed, failed_perc, grade_stats] |
---|
[14288] | 1310 | |
---|
[14703] | 1311 | def render(self): |
---|
| 1312 | session = grok.getSite()['configuration'].current_academic_session |
---|
| 1313 | lecturers = [i['user_title'] for i in self.getUsersWithLocalRoles() |
---|
| 1314 | if i['local_role'] == 'waeup.local.Lecturer'] |
---|
[15866] | 1315 | lecturers = sorted(lecturers) |
---|
[14703] | 1316 | lecturers = ', '.join(lecturers) |
---|
| 1317 | students_utils = getUtility(IStudentsUtils) |
---|
| 1318 | # only orientation is different |
---|
| 1319 | return students_utils.renderPDFCourseticketsOverview( |
---|
[15424] | 1320 | self, 'coursetickets', |
---|
| 1321 | session, self.data(session), lecturers, '', 45, self.note) |
---|
[14703] | 1322 | |
---|
[14288] | 1323 | class DownloadPreviousSessionScoresView(DownloadScoresView): |
---|
| 1324 | """View that exports scores. |
---|
| 1325 | """ |
---|
| 1326 | grok.name('download_prev_scores') |
---|
| 1327 | |
---|
| 1328 | def update(self): |
---|
| 1329 | self.current_academic_session = grok.getSite()[ |
---|
| 1330 | 'configuration'].current_academic_session |
---|
| 1331 | if self.context.__parent__.__parent__.score_editing_disabled: |
---|
| 1332 | self.flash(_('Score editing disabled.'), type="warning") |
---|
| 1333 | self.redirect(self.url(self.context)) |
---|
| 1334 | return |
---|
| 1335 | if not self.current_academic_session: |
---|
| 1336 | self.flash(_('Current academic session not set.'), type="warning") |
---|
| 1337 | self.redirect(self.url(self.context)) |
---|
| 1338 | return |
---|
| 1339 | site = grok.getSite() |
---|
| 1340 | exporter = getUtility(ICSVExporter, name='lecturer') |
---|
| 1341 | self.csv = exporter.export_filtered(site, filepath=None, |
---|
| 1342 | catalog='coursetickets', |
---|
| 1343 | session=self.current_academic_session-1, |
---|
| 1344 | level=None, |
---|
| 1345 | code=self.context.code) |
---|
[14306] | 1346 | return |
---|
| 1347 | |
---|
| 1348 | class AlumniRequestPasswordPage(StudentRequestPasswordPage): |
---|
| 1349 | """Captcha'd request password page for students. |
---|
| 1350 | """ |
---|
| 1351 | grok.name('alumni_requestpw') |
---|
| 1352 | grok.require('waeup.Anonymous') |
---|
| 1353 | grok.template('alumni_requestpw') |
---|
| 1354 | form_fields = grok.AutoFields(IStudentRequestPW).select( |
---|
| 1355 | 'lastname','number','email') |
---|
| 1356 | label = _('Search student record and send password for first-time login') |
---|
| 1357 | |
---|
| 1358 | def _redirect_no_student(self): |
---|
| 1359 | self.flash(_('No student record found.'), type="warning") |
---|
| 1360 | self.redirect(self.application_url() + '/applicants/trans2017/register') |
---|
[15864] | 1361 | return |
---|
| 1362 | |
---|
[17077] | 1363 | class CustomAddStudyLevelFormPage(AddStudyLevelFormPage): |
---|
| 1364 | """ This page is temporarily locked. |
---|
| 1365 | """ |
---|
| 1366 | def update(self): |
---|
| 1367 | if self.context.student.current_mode == 'ug_ft' \ |
---|
[17098] | 1368 | and self.context.student.current_session == 2021 \ |
---|
| 1369 | and not self.context.student.entry_session == 2021: |
---|
[17077] | 1370 | emit_lock_message(self) |
---|
| 1371 | return |
---|
| 1372 | super(CustomAddStudyLevelFormPage, self).update() |
---|
| 1373 | return |
---|