[8911] | 1 | ## $Id: browser.py 14569 2017-02-21 14:02:21Z 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 |
---|
[13937] | 21 | from cStringIO import StringIO |
---|
[8911] | 22 | from zope.i18n import translate |
---|
[13900] | 23 | from zope.component import getUtility, queryUtility |
---|
[14113] | 24 | from zope.schema.interfaces import TooBig, TooSmall |
---|
[13523] | 25 | from zope.security import checkPermission |
---|
[13900] | 26 | from zope.catalog.interfaces import ICatalog |
---|
[13351] | 27 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[11597] | 28 | from waeup.kofa.browser.layout import UtilityView |
---|
[8911] | 29 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[14288] | 30 | from waeup.kofa.interfaces import ( |
---|
[14306] | 31 | IKofaUtils, academic_sessions_vocab, ICSVExporter, IKofaObject) |
---|
| 32 | from waeup.kofa.students.interfaces import ( |
---|
| 33 | IStudentsUtils, IStudent, IStudentRequestPW) |
---|
[14000] | 34 | from waeup.kofa.students.workflow import PAID, REGISTERED, RETURNING |
---|
[9914] | 35 | from waeup.kofa.students.browser import ( |
---|
[11846] | 36 | StartClearancePage, |
---|
[9914] | 37 | StudentBasePDFFormPage, |
---|
| 38 | CourseTicketAddFormPage, |
---|
| 39 | StudyLevelDisplayFormPage, |
---|
[13834] | 40 | StudyLevelManageFormPage, |
---|
| 41 | StudyLevelEditFormPage, |
---|
[13059] | 42 | ExportPDFTranscriptSlip, |
---|
| 43 | ExportPDFAdmissionSlip, |
---|
[13353] | 44 | BedTicketAddPage, |
---|
[13380] | 45 | StudentFilesUploadPage, |
---|
[13523] | 46 | PaymentsManageFormPage, |
---|
[13770] | 47 | CourseTicketDisplayFormPage, |
---|
| 48 | CourseTicketManageFormPage, |
---|
[13900] | 49 | EditScoresPage, |
---|
[14165] | 50 | ExportPDFScoresSlip, |
---|
| 51 | StudyCourseTranscriptPage, |
---|
[14288] | 52 | DownloadScoresView, |
---|
[14534] | 53 | StudentRequestPasswordPage, |
---|
| 54 | StudyCourseManageFormPage |
---|
[10269] | 55 | ) |
---|
[8911] | 56 | from kofacustom.nigeria.students.browser import ( |
---|
| 57 | NigeriaOnlinePaymentDisplayFormPage, |
---|
| 58 | NigeriaOnlinePaymentAddFormPage, |
---|
[13059] | 59 | NigeriaExportPDFPaymentSlip, |
---|
| 60 | NigeriaExportPDFCourseRegistrationSlip, |
---|
[13351] | 61 | NigeriaStudentPersonalDisplayFormPage, |
---|
| 62 | NigeriaStudentPersonalEditFormPage, |
---|
| 63 | NigeriaStudentPersonalManageFormPage, |
---|
[14084] | 64 | NigeriaStudentClearanceDisplayFormPage, |
---|
| 65 | NigeriaExportPDFClearanceSlip, |
---|
| 66 | NigeriaStudentClearanceManageFormPage, |
---|
[13362] | 67 | NigeriaStudentClearanceEditFormPage, |
---|
[13462] | 68 | NigeriaAccommodationManageFormPage, |
---|
[13795] | 69 | NigeriaStudentBaseDisplayFormPage, |
---|
[14165] | 70 | NigeriaStudentBaseManageFormPage |
---|
[10269] | 71 | ) |
---|
[9496] | 72 | from waeup.aaue.students.interfaces import ( |
---|
[9914] | 73 | ICustomStudentOnlinePayment, |
---|
[11607] | 74 | ICustomStudentStudyLevel, |
---|
[13351] | 75 | ICustomStudent, |
---|
| 76 | ICustomStudentPersonal, |
---|
[13362] | 77 | ICustomStudentPersonalEdit, |
---|
[13770] | 78 | ICustomUGStudentClearance, |
---|
[14298] | 79 | ICustomUGStudentClearanceEdit, |
---|
[14084] | 80 | ICustomPGStudentClearance, |
---|
[13795] | 81 | ICustomCourseTicket, |
---|
[14534] | 82 | ICustomStudentBase, |
---|
| 83 | ICustomStudentStudyCourse) |
---|
[13414] | 84 | from waeup.aaue.interswitch.browser import gateway_net_amt |
---|
[9914] | 85 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
[8911] | 86 | |
---|
[14306] | 87 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
| 88 | |
---|
[13795] | 89 | class CustomStudentBaseDisplayFormPage(NigeriaStudentBaseDisplayFormPage): |
---|
| 90 | """ Page to display student base data |
---|
| 91 | """ |
---|
| 92 | form_fields = grok.AutoFields(ICustomStudentBase).omit( |
---|
| 93 | 'password', 'suspended', 'suspended_comment', 'flash_notice') |
---|
| 94 | form_fields[ |
---|
| 95 | 'financial_clearance_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 96 | |
---|
| 97 | class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage): |
---|
| 98 | """ View to manage student base data |
---|
| 99 | """ |
---|
| 100 | form_fields = grok.AutoFields(ICustomStudentBase).omit( |
---|
| 101 | 'student_id', 'adm_code', 'suspended', |
---|
| 102 | 'financially_cleared_by', 'financial_clearance_date') |
---|
| 103 | |
---|
[13351] | 104 | class CustomStudentPersonalDisplayFormPage(NigeriaStudentPersonalDisplayFormPage): |
---|
| 105 | """ Page to display student personal data |
---|
| 106 | """ |
---|
| 107 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
| 108 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 109 | form_fields['father_address'].custom_widget = BytesDisplayWidget |
---|
| 110 | form_fields['mother_address'].custom_widget = BytesDisplayWidget |
---|
| 111 | form_fields['next_kin_address'].custom_widget = BytesDisplayWidget |
---|
| 112 | form_fields[ |
---|
| 113 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 114 | |
---|
| 115 | class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage): |
---|
| 116 | """ Page to edit personal data |
---|
| 117 | """ |
---|
| 118 | form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit('personal_updated') |
---|
| 119 | |
---|
| 120 | class CustomStudentPersonalManageFormPage(NigeriaStudentPersonalManageFormPage): |
---|
| 121 | """ Page to edit personal data |
---|
| 122 | """ |
---|
| 123 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
| 124 | form_fields['personal_updated'].for_display = True |
---|
| 125 | form_fields[ |
---|
| 126 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 127 | |
---|
[14084] | 128 | class CustomStudentClearanceDisplayFormPage(NigeriaStudentClearanceDisplayFormPage): |
---|
| 129 | """ Page to display student clearance data |
---|
| 130 | """ |
---|
| 131 | |
---|
| 132 | @property |
---|
| 133 | def form_fields(self): |
---|
| 134 | if self.context.is_postgrad: |
---|
| 135 | form_fields = grok.AutoFields( |
---|
| 136 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
| 137 | else: |
---|
| 138 | form_fields = grok.AutoFields( |
---|
| 139 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
| 140 | if not getattr(self.context, 'officer_comment'): |
---|
| 141 | form_fields = form_fields.omit('officer_comment') |
---|
| 142 | else: |
---|
| 143 | form_fields['officer_comment'].custom_widget = BytesDisplayWidget |
---|
[14104] | 144 | form_fields = form_fields.omit('def_adm') |
---|
[14084] | 145 | return form_fields |
---|
| 146 | |
---|
| 147 | class CustomStudentClearanceManageFormPage(NigeriaStudentClearanceManageFormPage): |
---|
| 148 | """ Page to edit student clearance data |
---|
| 149 | """ |
---|
| 150 | |
---|
| 151 | @property |
---|
| 152 | def form_fields(self): |
---|
| 153 | if self.context.is_postgrad: |
---|
| 154 | form_fields = grok.AutoFields( |
---|
| 155 | ICustomPGStudentClearance).omit('clr_code') |
---|
| 156 | else: |
---|
| 157 | form_fields = grok.AutoFields( |
---|
| 158 | ICustomUGStudentClearance).omit('clr_code') |
---|
[14104] | 159 | form_fields = form_fields.omit('def_adm') |
---|
[14084] | 160 | return form_fields |
---|
| 161 | |
---|
[13362] | 162 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
| 163 | """ View to edit student clearance data by student |
---|
| 164 | """ |
---|
| 165 | |
---|
| 166 | @property |
---|
| 167 | def form_fields(self): |
---|
| 168 | if self.context.is_postgrad: |
---|
| 169 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit( |
---|
| 170 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment', |
---|
| 171 | 'physical_clearance_date') |
---|
| 172 | else: |
---|
[14298] | 173 | form_fields = grok.AutoFields(ICustomUGStudentClearanceEdit).omit( |
---|
[13362] | 174 | 'clearance_locked', 'clr_code', 'officer_comment', |
---|
[14104] | 175 | 'physical_clearance_date', 'date_of_birth', 'nationality', 'lga') |
---|
| 176 | form_fields = form_fields.omit('def_adm') |
---|
[13362] | 177 | return form_fields |
---|
| 178 | |
---|
[11846] | 179 | class CustomStartClearancePage(StartClearancePage): |
---|
[13360] | 180 | with_ac = False |
---|
[11846] | 181 | |
---|
[13351] | 182 | @property |
---|
| 183 | def all_required_fields_filled(self): |
---|
| 184 | if not self.context.email: |
---|
| 185 | return _("Email address is missing."), 'edit_base' |
---|
| 186 | if not self.context.phone: |
---|
| 187 | return _("Phone number is missing."), 'edit_base' |
---|
| 188 | if not self.context.father_name: |
---|
| 189 | return _("Personal data form is not properly filled."), 'edit_personal' |
---|
| 190 | return |
---|
| 191 | |
---|
[8911] | 192 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
| 193 | """ Page to view an online payment ticket |
---|
| 194 | """ |
---|
| 195 | grok.context(ICustomStudentOnlinePayment) |
---|
[9853] | 196 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9990] | 197 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 198 | form_fields[ |
---|
| 199 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 200 | form_fields[ |
---|
| 201 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 202 | |
---|
| 203 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
| 204 | """ Page to add an online payment ticket |
---|
| 205 | """ |
---|
| 206 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
| 207 | 'p_category') |
---|
| 208 | |
---|
[14527] | 209 | ALUMNI_PAYMENT_CATS = { |
---|
[14296] | 210 | 'transcript_local': 'Transcript Fee Local', |
---|
| 211 | 'transcript_inter': 'Transcript Fee International', |
---|
| 212 | } |
---|
| 213 | |
---|
[14533] | 214 | REDUCED_PAYMENT_CATS = { |
---|
[14527] | 215 | 'clearance': 'Acceptance Fee', |
---|
| 216 | 'schoolfee': 'School Fee', |
---|
| 217 | } |
---|
| 218 | |
---|
[14296] | 219 | @property |
---|
| 220 | def selectable_categories(self): |
---|
| 221 | if 'alumni' in self.application_url(): |
---|
[14527] | 222 | return self.ALUMNI_PAYMENT_CATS.items() |
---|
[14569] | 223 | if self.context.student.current_mode in ('ijmbe', 'found') : |
---|
[14533] | 224 | return self.REDUCED_PAYMENT_CATS.items() |
---|
[14296] | 225 | categories = getUtility(IKofaUtils).SELECTABLE_PAYMENT_CATEGORIES |
---|
| 226 | return sorted(categories.items()) |
---|
| 227 | |
---|
[13523] | 228 | class CustomPaymentsManageFormPage(PaymentsManageFormPage): |
---|
| 229 | """ Page to manage the student payments. |
---|
| 230 | |
---|
| 231 | This manage form page is for both students and students officers. |
---|
| 232 | """ |
---|
| 233 | @property |
---|
| 234 | def manage_payments_allowed(self): |
---|
| 235 | return checkPermission('waeup.manageStudent', self.context) |
---|
| 236 | |
---|
[13059] | 237 | class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip): |
---|
[8911] | 238 | """Deliver a PDF slip of the context. |
---|
| 239 | """ |
---|
| 240 | grok.context(ICustomStudentOnlinePayment) |
---|
[9853] | 241 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9990] | 242 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 243 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9496] | 244 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9914] | 245 | |
---|
[11625] | 246 | @property |
---|
| 247 | def note(self): |
---|
[13408] | 248 | p_session = self.context.p_session |
---|
[13405] | 249 | try: |
---|
[13408] | 250 | academic_session = grok.getSite()['configuration'][str(p_session)] |
---|
[13405] | 251 | except KeyError: |
---|
| 252 | academic_session = None |
---|
[13425] | 253 | text = '\n\n The Amount Authorized is inclusive of: ' |
---|
[13512] | 254 | if self.context.p_category in ('schoolfee_incl', 'schoolfee_1') \ |
---|
| 255 | and academic_session: |
---|
[14385] | 256 | #welfare_fee = gateway_net_amt(academic_session.welfare_fee) |
---|
| 257 | #union_fee = gateway_net_amt(academic_session.union_fee) |
---|
[14244] | 258 | if self.context.student.entry_session == 2016 \ |
---|
| 259 | and self.context.student.entry_mode == 'ug_ft' \ |
---|
| 260 | and self.context.p_session == 2016: |
---|
| 261 | # Add student id card fee to first school fee payment. |
---|
[14385] | 262 | |
---|
| 263 | ## Attention: The payment slip does not contain any information |
---|
| 264 | ## whether the fee was added or not. |
---|
| 265 | ## We can only draw conclusions from from the student's entry |
---|
| 266 | ## session whether the fee had been included. |
---|
| 267 | #id_card_fee = gateway_net_amt(academic_session.id_card_fee) |
---|
| 268 | #text += ('School Fee, ' |
---|
| 269 | # '%s Naira Student ID Card Fee, ' |
---|
| 270 | # '%s Naira Student Union Dues, ' |
---|
| 271 | # '%s Naira Student Welfare Assurance Fee and ' |
---|
| 272 | # % (id_card_fee, union_fee, welfare_fee)) |
---|
| 273 | |
---|
[14244] | 274 | text += ('School Fee, ' |
---|
[14385] | 275 | 'Student ID Card Fee, ' |
---|
| 276 | 'Student Union Dues, ' |
---|
| 277 | 'Student Welfare Assurance Fee and ') |
---|
[14244] | 278 | else: |
---|
[14385] | 279 | |
---|
| 280 | #text += ('School Fee, ' |
---|
| 281 | # '%s Naira Student Union Dues, ' |
---|
| 282 | # '%s Naira Student Welfare Assurance Fee and ' |
---|
| 283 | # % (union_fee, welfare_fee)) |
---|
| 284 | |
---|
[14244] | 285 | text += ('School Fee, ' |
---|
[14385] | 286 | 'Student Union Dues, ' |
---|
| 287 | 'Student Welfare Assurance Fee and ') |
---|
[13410] | 288 | elif self.context.p_category in ( |
---|
| 289 | 'clearance_incl', 'clearance_medical_incl') and academic_session: |
---|
[14385] | 290 | |
---|
| 291 | #matric_gown_fee = gateway_net_amt(academic_session.matric_gown_fee) |
---|
| 292 | #lapel_fee = gateway_net_amt(academic_session.lapel_fee) |
---|
| 293 | #text += ('Acceptance Fee, ' |
---|
| 294 | # '%s Naira Matriculation Gown Fee, ' |
---|
| 295 | # '%s Naira Lapel/File Fee and ' |
---|
| 296 | # % (matric_gown_fee, lapel_fee)) |
---|
| 297 | |
---|
[13437] | 298 | text += ('Acceptance Fee, ' |
---|
[14385] | 299 | 'Matriculation Gown Fee, ' |
---|
| 300 | 'Lapel/File Fee and ') |
---|
[11625] | 301 | |
---|
[14385] | 302 | #return text + '250.0 Naira Transaction Charge.' |
---|
| 303 | |
---|
| 304 | return text + 'Transaction Charge.' |
---|
| 305 | |
---|
[14534] | 306 | class CustomStudyCourseManageFormPage(StudyCourseManageFormPage): |
---|
| 307 | """ Page to edit the student study course data |
---|
| 308 | """ |
---|
| 309 | grok.context(ICustomStudentStudyCourse) |
---|
| 310 | |
---|
| 311 | @property |
---|
| 312 | def form_fields(self): |
---|
| 313 | if self.context.is_postgrad: |
---|
| 314 | form_fields = grok.AutoFields(ICustomStudentStudyCourse).omit( |
---|
| 315 | 'previous_verdict') |
---|
| 316 | else: |
---|
| 317 | form_fields = grok.AutoFields(ICustomStudentStudyCourse) |
---|
| 318 | form_fields['imported_cgpa'].for_display = True |
---|
| 319 | return form_fields |
---|
| 320 | |
---|
[9914] | 321 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
| 322 | """ Page to display student study levels |
---|
| 323 | """ |
---|
| 324 | grok.context(ICustomStudentStudyLevel) |
---|
[10480] | 325 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
[14206] | 326 | 'total_credits', 'gpa', 'level', 'imported_gpa', 'imported_cgpa') |
---|
[9914] | 327 | form_fields[ |
---|
| 328 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 329 | |
---|
[14000] | 330 | @property |
---|
| 331 | def show_results(self): |
---|
| 332 | isStudent = getattr( |
---|
| 333 | self.request.principal, 'user_type', None) == 'student' |
---|
[14302] | 334 | # Temporarily disabled on 1/12/2016 |
---|
| 335 | if isStudent: |
---|
[14000] | 336 | return False |
---|
[14302] | 337 | #if isStudent and self.context.student.state != RETURNING \ |
---|
| 338 | # and self.context.student.current_level == self.context.level: |
---|
| 339 | # return False |
---|
[14000] | 340 | return True |
---|
| 341 | |
---|
[13834] | 342 | class CustomStudyLevelManageFormPage(StudyLevelManageFormPage): |
---|
| 343 | """ Page to edit the student study level data |
---|
| 344 | """ |
---|
| 345 | grok.context(ICustomStudentStudyLevel) |
---|
| 346 | |
---|
[14534] | 347 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
| 348 | 'validation_date', 'validated_by', 'total_credits', 'gpa', 'level', |
---|
| 349 | 'total_credits_s1', 'total_credits_s2') |
---|
| 350 | |
---|
| 351 | form_fields['imported_gpa'].for_display = True |
---|
| 352 | form_fields['imported_cgpa'].for_display = True |
---|
| 353 | |
---|
[13834] | 354 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
| 355 | """ Page to edit the student study level data by students |
---|
| 356 | """ |
---|
| 357 | grok.context(ICustomStudentStudyLevel) |
---|
| 358 | |
---|
[13059] | 359 | class CustomExportPDFCourseRegistrationSlip( |
---|
| 360 | NigeriaExportPDFCourseRegistrationSlip): |
---|
[9914] | 361 | """Deliver a PDF slip of the context. |
---|
| 362 | """ |
---|
| 363 | grok.context(ICustomStudentStudyLevel) |
---|
| 364 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
[10102] | 365 | 'level_session', 'level_verdict', |
---|
[14206] | 366 | 'validated_by', 'validation_date', 'gpa', 'level', |
---|
| 367 | 'imported_gpa', 'imported_cgpa') |
---|
[9914] | 368 | |
---|
[10269] | 369 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
[10689] | 370 | 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', |
---|
[13713] | 371 | 'department', 'current_mode', 'current_level', 'flash_notice') |
---|
[10269] | 372 | |
---|
[14000] | 373 | @property |
---|
| 374 | def show_results(self): |
---|
| 375 | isStudent = getattr( |
---|
| 376 | self.request.principal, 'user_type', None) == 'student' |
---|
[14302] | 377 | # Temporarily disabled on 1/12/2016 |
---|
| 378 | if isStudent: |
---|
| 379 | return False |
---|
| 380 | #if isStudent and self.context.student.state != RETURNING \ |
---|
| 381 | # and self.context.student.current_level == self.context.level: |
---|
| 382 | # return False |
---|
| 383 | return True |
---|
[14000] | 384 | |
---|
[13038] | 385 | def update(self): |
---|
| 386 | if self.context.student.state != REGISTERED \ |
---|
[13051] | 387 | and self.context.student.current_level == self.context.level: |
---|
[13038] | 388 | self.flash(_('Forbidden'), type="warning") |
---|
| 389 | self.redirect(self.url(self.context)) |
---|
[14000] | 390 | return |
---|
[13038] | 391 | |
---|
[9914] | 392 | @property |
---|
| 393 | def label(self): |
---|
| 394 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 395 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
| 396 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
| 397 | target_language=lang) |
---|
| 398 | line0 = '' |
---|
[13788] | 399 | if self.context.student.is_postgrad: |
---|
| 400 | line0 = 'SCHOOL OF POSTGRADUATE STUDIES\n' |
---|
| 401 | elif self.context.student.current_mode.endswith('_pt'): |
---|
[9914] | 402 | line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n' |
---|
[13866] | 403 | line1 = translate(_('Course Registration Slip'), |
---|
| 404 | target_language=portal_language) \ |
---|
[9914] | 405 | + ' %s' % level_title |
---|
[13866] | 406 | line2 = translate(_('Session'), |
---|
| 407 | target_language=portal_language) \ |
---|
[9914] | 408 | + ' %s' % self.context.getSessionString |
---|
| 409 | return '%s%s\n%s' % (line0, line1, line2) |
---|
| 410 | |
---|
| 411 | @property |
---|
| 412 | def title(self): |
---|
| 413 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 414 | return translate(_('Units Registered'), target_language=portal_language) |
---|
[9914] | 415 | |
---|
| 416 | def _signatures(self): |
---|
[13647] | 417 | if self.context.student.current_mode.endswith('_pt') \ |
---|
| 418 | or self.context.student.current_mode == 'found': |
---|
| 419 | return ( |
---|
| 420 | [('I have selected the course on the advise of my Head of ' |
---|
| 421 | 'Department. <br>', _('Student\'s Signature'), '<br>')], |
---|
| 422 | [('This student has satisfied the department\'s requirements. ' |
---|
| 423 | 'I recommend to approve the course registration. <br>', |
---|
| 424 | _('Head of Department\'s Signature'), '<br>')], |
---|
[13946] | 425 | [('' , _('Deputy Registrar\'s Signature'), '<br>')], |
---|
[13647] | 426 | [('', _('Director\'s Signature'))] |
---|
| 427 | ) |
---|
| 428 | if self.context.student.current_mode in ( |
---|
| 429 | 'de_ft', 'ug_ft', 'dp_ft', 'transfer'): |
---|
[13649] | 430 | return ([_('Academic Adviser\'s Signature'), |
---|
| 431 | _('Faculty Officer\'s Signature'), |
---|
| 432 | _('Student\'s Signature')],) |
---|
| 433 | |
---|
[13647] | 434 | if self.context.student.current_mode in ('special_pg_ft', 'special_pg_pt'): |
---|
| 435 | return ( |
---|
[13676] | 436 | [('I declare that all items of information supplied above are correct:' , |
---|
[13680] | 437 | _('Student\'s Signature'), '<br>')], |
---|
[13676] | 438 | [('We approved the above registration:', |
---|
[13680] | 439 | _('Major Supervisor (Name / Signature)'), '')], |
---|
| 440 | [('', _('Co-Supervisor (Name / Signature)'), '')], |
---|
[13676] | 441 | [('', _('Head of Department'), '<br>')], |
---|
| 442 | [('The student has satisfied the conditions for renewal of ' |
---|
| 443 | 'registration for graduate school programme in this university:', |
---|
[13680] | 444 | _('Secretary <br /> (School of Postgraduate Studies)'), '')], |
---|
| 445 | [('', _('Dean <br /> (School of Postgraduate Studies)'), '')], |
---|
[13647] | 446 | ) |
---|
| 447 | return None |
---|
[9914] | 448 | |
---|
[13647] | 449 | |
---|
[9914] | 450 | def render(self): |
---|
| 451 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 452 | Sem = translate(_('Sem.'), target_language=portal_language) |
---|
| 453 | Code = translate(_('Code'), target_language=portal_language) |
---|
| 454 | Title = translate(_('Title'), target_language=portal_language) |
---|
| 455 | Cred = translate(_('Cred.'), target_language=portal_language) |
---|
[14000] | 456 | if self.show_results: |
---|
| 457 | Score = translate(_('Score'), target_language=portal_language) |
---|
| 458 | #CA = translate(_('CA'), target_language=portal_language) |
---|
| 459 | Grade = translate(_('Grade'), target_language=portal_language) |
---|
[13866] | 460 | Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue', |
---|
[9914] | 461 | target_language=portal_language) |
---|
| 462 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 463 | self.request, self.omit_fields) |
---|
| 464 | students_utils = getUtility(IStudentsUtils) |
---|
[10442] | 465 | |
---|
| 466 | tabledata = [] |
---|
| 467 | tableheader = [] |
---|
| 468 | contenttitle = [] |
---|
| 469 | for i in range(1,7): |
---|
| 470 | tabledata.append(sorted( |
---|
| 471 | [value for value in self.context.values() if value.semester == i], |
---|
| 472 | key=lambda value: str(value.semester) + value.code)) |
---|
[14000] | 473 | if self.show_results: |
---|
| 474 | tableheader.append([(Code,'code', 2.0), |
---|
| 475 | (Title,'title', 7), |
---|
| 476 | (Cred, 'credits', 1.5), |
---|
| 477 | (Score, 'score', 1.4), |
---|
| 478 | #(CA, 'ca', 1.4), |
---|
| 479 | (Grade, 'grade', 1.4), |
---|
| 480 | (Signature, 'dummy', 3), |
---|
| 481 | ]) |
---|
| 482 | else: |
---|
| 483 | tableheader.append([(Code,'code', 2.0), |
---|
| 484 | (Title,'title', 7), |
---|
| 485 | (Cred, 'credits', 1.5), |
---|
| 486 | (Signature, 'dummy', 3), |
---|
| 487 | ]) |
---|
[9914] | 488 | if len(self.label.split('\n')) == 3: |
---|
| 489 | topMargin = 1.9 |
---|
| 490 | elif len(self.label.split('\n')) == 2: |
---|
| 491 | topMargin = 1.7 |
---|
| 492 | else: |
---|
| 493 | topMargin = 1.5 |
---|
| 494 | return students_utils.renderPDF( |
---|
| 495 | self, 'course_registration_slip.pdf', |
---|
| 496 | self.context.student, studentview, |
---|
[10442] | 497 | tableheader=tableheader, |
---|
| 498 | tabledata=tabledata, |
---|
[9914] | 499 | signatures=self._signatures(), |
---|
[10269] | 500 | topMargin=topMargin, |
---|
| 501 | omit_fields=self.omit_fields |
---|
[9914] | 502 | ) |
---|
[10566] | 503 | |
---|
[14165] | 504 | class CustomStudyCourseTranscriptPage(StudyCourseTranscriptPage): |
---|
| 505 | """ Page to display the student's transcript. |
---|
| 506 | """ |
---|
| 507 | grok.require('waeup.viewStudent') |
---|
| 508 | |
---|
[13059] | 509 | class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip): |
---|
[10566] | 510 | """Deliver a PDF slip of the context. |
---|
| 511 | """ |
---|
[14315] | 512 | # grok.require('waeup.viewStudent') |
---|
[10566] | 513 | |
---|
[14267] | 514 | note = _(""" |
---|
| 515 | <br /><br /><br /><br /> |
---|
| 516 | <font size='10'> |
---|
| 517 | <strong>Note:</strong> This copy is subject to correction for typographical errors and ratification by the departmental board. |
---|
| 518 | </font> |
---|
| 519 | """) |
---|
| 520 | |
---|
[10566] | 521 | def _sigsInFooter(self): |
---|
| 522 | return [] |
---|
| 523 | |
---|
| 524 | def _signatures(self): |
---|
| 525 | return ([( |
---|
[14136] | 526 | 'Mrs. Uniamikogbo, S.O., mnim, manupa <br /> Prin. Asst Registrar <br /> ' |
---|
[11555] | 527 | 'Exams, Records and Data Processing Division <br /> For: Registrar')],) |
---|
[10922] | 528 | |
---|
[13834] | 529 | def render(self): |
---|
| 530 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 531 | Term = translate(_('Sem.'), target_language=portal_language) |
---|
| 532 | Code = translate(_('Code'), target_language=portal_language) |
---|
| 533 | Title = translate(_('Title'), target_language=portal_language) |
---|
| 534 | Cred = translate(_('Credits'), target_language=portal_language) |
---|
| 535 | Score = translate(_('Score'), target_language=portal_language) |
---|
| 536 | Grade = translate(_('Grade'), target_language=portal_language) |
---|
[13834] | 537 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 538 | self.request, self.omit_fields) |
---|
| 539 | students_utils = getUtility(IStudentsUtils) |
---|
| 540 | |
---|
| 541 | tableheader = [(Code,'code', 2.5), |
---|
| 542 | (Title,'title', 7), |
---|
| 543 | (Term, 'semester', 1.5), |
---|
| 544 | (Cred, 'credits', 1.5), |
---|
[14136] | 545 | (Score, 'total_score', 1.5), |
---|
[13834] | 546 | (Grade, 'grade', 1.5), |
---|
| 547 | ] |
---|
| 548 | |
---|
| 549 | return students_utils.renderPDFTranscript( |
---|
| 550 | self, 'transcript.pdf', |
---|
| 551 | self.context.student, studentview, |
---|
| 552 | omit_fields=self.omit_fields, |
---|
| 553 | tableheader=tableheader, |
---|
| 554 | signatures=self._signatures(), |
---|
| 555 | sigs_in_footer=self._sigsInFooter(), |
---|
[14295] | 556 | note = self.note, |
---|
| 557 | no_passport=True |
---|
[13834] | 558 | ) |
---|
| 559 | |
---|
[13059] | 560 | class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip): |
---|
[10922] | 561 | """Deliver a PDF Admission slip. |
---|
| 562 | """ |
---|
| 563 | |
---|
| 564 | @property |
---|
| 565 | def label(self): |
---|
| 566 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 567 | return translate(_('e-Admission Slip \n'), |
---|
| 568 | target_language=portal_language) \ |
---|
[10922] | 569 | + ' %s' % self.context.display_fullname |
---|
[11597] | 570 | |
---|
[13059] | 571 | class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip): |
---|
[11606] | 572 | """Deliver a PDF slip of the context. |
---|
| 573 | """ |
---|
| 574 | |
---|
| 575 | @property |
---|
| 576 | def label(self): |
---|
| 577 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[14114] | 578 | return translate(_('Verification/Clearance Slip\n'), |
---|
[13866] | 579 | target_language=portal_language) \ |
---|
[11606] | 580 | + ' %s' % self.context.display_fullname |
---|
| 581 | |
---|
[14084] | 582 | @property |
---|
| 583 | def form_fields(self): |
---|
| 584 | if self.context.is_postgrad: |
---|
| 585 | form_fields = grok.AutoFields( |
---|
| 586 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
| 587 | else: |
---|
| 588 | form_fields = grok.AutoFields( |
---|
| 589 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
| 590 | if not getattr(self.context, 'officer_comment'): |
---|
| 591 | form_fields = form_fields.omit('officer_comment') |
---|
[14104] | 592 | form_fields = form_fields.omit('def_adm') |
---|
[14084] | 593 | return form_fields |
---|
| 594 | |
---|
[11597] | 595 | class StudentGetMatricNumberPage(UtilityView, grok.View): |
---|
| 596 | """ Construct and set the matriculation number. |
---|
| 597 | """ |
---|
| 598 | grok.context(IStudent) |
---|
| 599 | grok.name('get_matric_number') |
---|
| 600 | grok.require('waeup.viewStudent') |
---|
| 601 | |
---|
| 602 | def update(self): |
---|
| 603 | students_utils = getUtility(IStudentsUtils) |
---|
| 604 | msg, mnumber = students_utils.setMatricNumber(self.context) |
---|
| 605 | if msg: |
---|
| 606 | self.flash(msg, type="danger") |
---|
| 607 | else: |
---|
| 608 | self.flash(_('Matriculation number %s assigned.' % mnumber)) |
---|
[11602] | 609 | self.context.writeLogMessage(self, '%s assigned' % mnumber) |
---|
[11597] | 610 | self.redirect(self.url(self.context)) |
---|
| 611 | return |
---|
| 612 | |
---|
| 613 | def render(self): |
---|
[11607] | 614 | return |
---|
| 615 | |
---|
[13059] | 616 | class ExportPDFMatricNumberSlip(UtilityView, grok.View): |
---|
[11607] | 617 | """Deliver a PDF notification slip. |
---|
| 618 | """ |
---|
| 619 | grok.context(ICustomStudent) |
---|
| 620 | grok.name('matric_number_slip.pdf') |
---|
| 621 | grok.require('waeup.viewStudent') |
---|
| 622 | prefix = 'form' |
---|
| 623 | |
---|
| 624 | form_fields = grok.AutoFields(ICustomStudent).select( |
---|
| 625 | 'student_id', 'matric_number') |
---|
[13713] | 626 | omit_fields = ('date_of_birth', 'current_level', 'flash_notice') |
---|
[11607] | 627 | |
---|
| 628 | @property |
---|
[13489] | 629 | def title(self): |
---|
| 630 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 631 | return translate(_('Matriculation Number'), 'waeup.kofa', |
---|
[13489] | 632 | target_language=portal_language) |
---|
| 633 | |
---|
| 634 | @property |
---|
[11607] | 635 | def label(self): |
---|
| 636 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 637 | return translate(_('Matriculation Number Slip\n'), |
---|
| 638 | target_language=portal_language) \ |
---|
[11607] | 639 | + ' %s' % self.context.display_fullname |
---|
| 640 | |
---|
| 641 | def render(self): |
---|
| 642 | if self.context.state not in (PAID,) or not self.context.is_fresh \ |
---|
| 643 | or not self.context.matric_number: |
---|
| 644 | self.flash('Not allowed.', type="danger") |
---|
| 645 | self.redirect(self.url(self.context)) |
---|
| 646 | return |
---|
| 647 | students_utils = getUtility(IStudentsUtils) |
---|
[11609] | 648 | pre_text = _('Congratulations! Your acceptance fee and school fees ' + |
---|
| 649 | 'payments have been received and your matriculation ' + |
---|
| 650 | 'number generated with details as follows.') |
---|
[11607] | 651 | return students_utils.renderPDFAdmissionLetter(self, |
---|
| 652 | self.context.student, omit_fields=self.omit_fields, |
---|
[13353] | 653 | pre_text=pre_text, post_text='') |
---|
| 654 | |
---|
[13489] | 655 | class ExportPersonalDataSlip(UtilityView, grok.View): |
---|
| 656 | """Deliver a PDF notification slip. |
---|
| 657 | """ |
---|
| 658 | grok.context(ICustomStudent) |
---|
| 659 | grok.name('personal_data_slip.pdf') |
---|
| 660 | grok.require('waeup.viewStudent') |
---|
| 661 | prefix = 'form' |
---|
| 662 | note = None |
---|
| 663 | |
---|
| 664 | form_fields = grok.AutoFields(ICustomStudentPersonal).omit('personal_updated') |
---|
[13713] | 665 | omit_fields = ('suspended', 'suspended_comment', 'adm_code', |
---|
| 666 | 'certificate', 'flash_notice') |
---|
[13489] | 667 | |
---|
| 668 | @property |
---|
| 669 | def title(self): |
---|
| 670 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 671 | return translate(_('Personal Data'), 'waeup.kofa', |
---|
[13489] | 672 | target_language=portal_language) |
---|
| 673 | |
---|
| 674 | @property |
---|
| 675 | def label(self): |
---|
| 676 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[13866] | 677 | return translate(_('Personal Data Slip\n'), |
---|
| 678 | target_language=portal_language) \ |
---|
[13489] | 679 | + ' %s' % self.context.display_fullname |
---|
| 680 | |
---|
| 681 | def render(self): |
---|
| 682 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 683 | self.request, self.omit_fields) |
---|
| 684 | students_utils = getUtility(IStudentsUtils) |
---|
| 685 | return students_utils.renderPDF(self, 'personal_data_slip.pdf', |
---|
| 686 | self.context.student, studentview, note=self.note, |
---|
| 687 | omit_fields=self.omit_fields) |
---|
| 688 | |
---|
[13462] | 689 | class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage): |
---|
| 690 | """ Page to manage bed tickets. |
---|
| 691 | This manage form page is for both students and students officers. |
---|
| 692 | """ |
---|
| 693 | with_hostel_selection = True |
---|
| 694 | |
---|
[13353] | 695 | class CustomBedTicketAddPage(BedTicketAddPage): |
---|
[13360] | 696 | with_ac = False |
---|
[13380] | 697 | |
---|
| 698 | class CustomStudentFilesUploadPage(StudentFilesUploadPage): |
---|
| 699 | """ View to upload files by student. Inherit from same class in |
---|
| 700 | base package, not from kofacustom.nigeria which |
---|
| 701 | requires that no application slip exists. |
---|
[13770] | 702 | """ |
---|
| 703 | |
---|
| 704 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
| 705 | """ Page to display course tickets |
---|
| 706 | """ |
---|
| 707 | |
---|
[14453] | 708 | @property |
---|
| 709 | def show_results(self): |
---|
| 710 | isStudent = getattr( |
---|
| 711 | self.request.principal, 'user_type', None) == 'student' |
---|
| 712 | if isStudent: |
---|
| 713 | return False |
---|
| 714 | return True |
---|
| 715 | |
---|
| 716 | @property |
---|
| 717 | def form_fields(self): |
---|
| 718 | if self.show_results: |
---|
| 719 | return grok.AutoFields(ICustomCourseTicket) |
---|
| 720 | else: |
---|
| 721 | return grok.AutoFields(ICustomCourseTicket).omit('score').omit('ca') |
---|
| 722 | |
---|
[13770] | 723 | class CustomCourseTicketManageFormPage(CourseTicketManageFormPage): |
---|
| 724 | """ Page to manage course tickets |
---|
| 725 | """ |
---|
| 726 | form_fields = grok.AutoFields(ICustomCourseTicket) |
---|
| 727 | form_fields['title'].for_display = True |
---|
| 728 | form_fields['fcode'].for_display = True |
---|
| 729 | form_fields['dcode'].for_display = True |
---|
| 730 | form_fields['semester'].for_display = True |
---|
| 731 | form_fields['passmark'].for_display = True |
---|
| 732 | form_fields['credits'].for_display = True |
---|
| 733 | form_fields['mandatory'].for_display = False |
---|
| 734 | form_fields['automatic'].for_display = True |
---|
| 735 | form_fields['carry_over'].for_display = True |
---|
| 736 | |
---|
| 737 | class CustomEditScoresPage(EditScoresPage): |
---|
| 738 | """Page that filters and lists students. |
---|
| 739 | """ |
---|
| 740 | grok.template('editscorespage') |
---|
| 741 | |
---|
[13937] | 742 | |
---|
| 743 | def _extract_uploadfile(self, uploadfile): |
---|
| 744 | """Get a mapping of student-ids to scores. |
---|
| 745 | |
---|
| 746 | The mapping is constructed by reading contents from `uploadfile`. |
---|
| 747 | |
---|
| 748 | We expect uploadfile to be a regular CSV file with columns |
---|
| 749 | ``student_id``, ``score`` and ``ca`` (other cols are ignored). |
---|
| 750 | """ |
---|
| 751 | result = dict() |
---|
| 752 | data = StringIO(uploadfile.read()) # ensure we have something seekable |
---|
| 753 | reader = csv.DictReader(data) |
---|
| 754 | for row in reader: |
---|
| 755 | if not ('student_id' in row and 'score' in row and 'ca' in row): |
---|
| 756 | continue |
---|
| 757 | result[row['student_id']] = (row['score'], row['ca']) |
---|
| 758 | return result |
---|
| 759 | |
---|
[14288] | 760 | def _update_scores(self, form): |
---|
[13937] | 761 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.', '') |
---|
[14288] | 762 | error = '' |
---|
[13937] | 763 | if 'UPDATE_FILE' in form: |
---|
| 764 | if form['uploadfile']: |
---|
| 765 | try: |
---|
| 766 | formvals = self._extract_uploadfile(form['uploadfile']) |
---|
| 767 | except: |
---|
| 768 | self.flash( |
---|
| 769 | _('Uploaded file contains illegal data. Ignored'), |
---|
| 770 | type="danger") |
---|
[14288] | 771 | return False |
---|
[13937] | 772 | else: |
---|
| 773 | self.flash( |
---|
| 774 | _('No file provided.'), type="danger") |
---|
[14288] | 775 | return False |
---|
[13937] | 776 | else: |
---|
| 777 | formvals = dict(zip(form['sids'], zip(form['scores'], form['cas']))) |
---|
[14149] | 778 | for ticket in self.editable_tickets: |
---|
[13937] | 779 | ticket_error = False |
---|
| 780 | score = ticket.score |
---|
| 781 | ca = ticket.ca |
---|
| 782 | sid = ticket.student.student_id |
---|
| 783 | if formvals[sid][0] == '': |
---|
| 784 | score = None |
---|
| 785 | if formvals[sid][1] == '': |
---|
| 786 | ca = None |
---|
| 787 | try: |
---|
| 788 | if formvals[sid][0]: |
---|
| 789 | score = int(formvals[sid][0]) |
---|
| 790 | if formvals[sid][1]: |
---|
| 791 | ca = int(formvals[sid][1]) |
---|
| 792 | except ValueError: |
---|
| 793 | error += '%s, ' % ticket.student.display_fullname |
---|
| 794 | ticket_error = True |
---|
| 795 | if not ticket_error and ticket.score != score: |
---|
[14113] | 796 | try: |
---|
| 797 | ticket.score = score |
---|
| 798 | except TooBig: |
---|
| 799 | error += '%s, ' % ticket.student.display_fullname |
---|
| 800 | ticket_error = True |
---|
| 801 | pass |
---|
[13937] | 802 | ticket.student.__parent__.logger.info( |
---|
| 803 | '%s - %s %s/%s score updated (%s)' % |
---|
| 804 | (ob_class, ticket.student.student_id, |
---|
| 805 | ticket.level, ticket.code, score)) |
---|
| 806 | if not ticket_error and ticket.ca != ca: |
---|
[14113] | 807 | try: |
---|
| 808 | ticket.ca = ca |
---|
| 809 | except TooBig: |
---|
| 810 | error += '%s, ' % ticket.student.display_fullname |
---|
| 811 | pass |
---|
[13937] | 812 | ticket.student.__parent__.logger.info( |
---|
| 813 | '%s - %s %s/%s ca updated (%s)' % |
---|
| 814 | (ob_class, ticket.student.student_id, |
---|
| 815 | ticket.level, ticket.code, ca)) |
---|
| 816 | if error: |
---|
| 817 | self.flash(_('Error: Score(s) and CA(s) of %s have not be updated. ' |
---|
[14113] | 818 | % error.strip(', ')), type="danger") |
---|
[14288] | 819 | return True |
---|
| 820 | |
---|
| 821 | class EditPreviousSessionScoresPage(CustomEditScoresPage): |
---|
| 822 | |
---|
| 823 | grok.name('edit_prev_scores') |
---|
| 824 | |
---|
| 825 | def update(self, *args, **kw): |
---|
| 826 | form = self.request.form |
---|
| 827 | self.current_academic_session = grok.getSite()[ |
---|
| 828 | 'configuration'].current_academic_session |
---|
| 829 | if self.context.__parent__.__parent__.score_editing_disabled: |
---|
| 830 | self.flash(_('Score editing disabled.'), type="warning") |
---|
| 831 | self.redirect(self.url(self.context)) |
---|
[13939] | 832 | return |
---|
[14288] | 833 | if not self.current_academic_session: |
---|
| 834 | self.flash(_('Current academic session not set.'), type="warning") |
---|
| 835 | self.redirect(self.url(self.context)) |
---|
| 836 | return |
---|
| 837 | previous_session = self.current_academic_session - 1 |
---|
| 838 | self.session_title = academic_sessions_vocab.getTerm( |
---|
| 839 | previous_session).title |
---|
| 840 | self.tickets = self._searchCatalog(previous_session) |
---|
| 841 | if not self.tickets: |
---|
| 842 | self.flash(_('No student found.'), type="warning") |
---|
| 843 | self.redirect(self.url(self.context)) |
---|
| 844 | return |
---|
| 845 | self.editable_tickets = [ |
---|
| 846 | ticket for ticket in self.tickets if ticket.editable_by_lecturer] |
---|
| 847 | if not 'UPDATE_TABLE' in form and not 'UPDATE_FILE' in form: |
---|
| 848 | return |
---|
| 849 | if not self.editable_tickets: |
---|
| 850 | return |
---|
| 851 | success = self._update_scores(form) |
---|
| 852 | if success: |
---|
| 853 | self.flash(_('You successfully updated course results.')) |
---|
[13900] | 854 | return |
---|
| 855 | |
---|
| 856 | class CustomExportPDFScoresSlip(ExportPDFScoresSlip): |
---|
| 857 | """Deliver a PDF slip of course tickets for a lecturer. |
---|
| 858 | """ |
---|
| 859 | |
---|
[14315] | 860 | def data(self, session): |
---|
[13900] | 861 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
---|
| 862 | coursetickets = cat.searchResults( |
---|
| 863 | session=(session, session), |
---|
| 864 | code=(self.context.code, self.context.code) |
---|
| 865 | ) |
---|
[14149] | 866 | # In AAUE only editable tickets can be printed |
---|
| 867 | editable_tickets = [ |
---|
| 868 | ticket for ticket in coursetickets if ticket.editable_by_lecturer] |
---|
[13963] | 869 | header = [[_(''), |
---|
| 870 | _('Matric No.'), |
---|
[13900] | 871 | _('Reg. No.'), |
---|
| 872 | _('Fullname'), |
---|
| 873 | _('Status'), |
---|
[13963] | 874 | _('Course of\nStudies'), |
---|
[13900] | 875 | _('Level'), |
---|
[13963] | 876 | _('Exam\nScore'), |
---|
[13964] | 877 | _(' CA '), |
---|
| 878 | _('Total '), |
---|
[13963] | 879 | _('Grade'), |
---|
| 880 | ],] |
---|
[14288] | 881 | sorted_tickets = sorted(editable_tickets, |
---|
| 882 | key=lambda ticket: ticket.student.certcode + |
---|
| 883 | ticket.student.display_fullname + str(ticket.level)) |
---|
| 884 | no = 1 |
---|
[13907] | 885 | tickets = [] |
---|
[14315] | 886 | passed = 0 |
---|
| 887 | failed = 0 |
---|
[14149] | 888 | # In AAUE only editable tickets can be printed |
---|
[14288] | 889 | for ticket in sorted_tickets: |
---|
[14532] | 890 | if ticket.total_score is None: |
---|
[13963] | 891 | total = 'n/a' |
---|
[13964] | 892 | grade = 'n/a' |
---|
[13963] | 893 | else: |
---|
[14532] | 894 | total = ticket.total_score |
---|
| 895 | grade = ticket._getGradeWeightFromScore[0] |
---|
| 896 | if grade in ('F', '-'): |
---|
[14315] | 897 | failed += 1 |
---|
| 898 | else: |
---|
| 899 | passed += 1 |
---|
[13964] | 900 | fullname = textwrap.fill(ticket.student.display_fullname, 30) |
---|
[13963] | 901 | row = [no, |
---|
| 902 | ticket.student.matric_number, |
---|
[13900] | 903 | ticket.student.reg_number, |
---|
[13964] | 904 | fullname, |
---|
[13900] | 905 | ticket.student.translated_state, |
---|
| 906 | ticket.student.certcode, |
---|
| 907 | ticket.level, |
---|
[13963] | 908 | ticket.ca, |
---|
[13900] | 909 | ticket.score, |
---|
[13963] | 910 | total, |
---|
[13964] | 911 | grade, |
---|
[13963] | 912 | ] |
---|
[13907] | 913 | tickets.append(row) |
---|
[13963] | 914 | no += 1 |
---|
[14317] | 915 | total = passed + failed |
---|
[14320] | 916 | passed_perc = 0 |
---|
| 917 | failed_perc = 0 |
---|
[14317] | 918 | if total: |
---|
[14320] | 919 | passed_perc = 100 * passed / total |
---|
| 920 | failed_perc = 100 * failed / total |
---|
| 921 | return header + tickets, [ |
---|
| 922 | total, passed, passed_perc, failed, failed_perc] |
---|
[14288] | 923 | |
---|
| 924 | class DownloadPreviousSessionScoresView(DownloadScoresView): |
---|
| 925 | """View that exports scores. |
---|
| 926 | """ |
---|
| 927 | grok.name('download_prev_scores') |
---|
| 928 | |
---|
| 929 | def update(self): |
---|
| 930 | self.current_academic_session = grok.getSite()[ |
---|
| 931 | 'configuration'].current_academic_session |
---|
| 932 | if self.context.__parent__.__parent__.score_editing_disabled: |
---|
| 933 | self.flash(_('Score editing disabled.'), type="warning") |
---|
| 934 | self.redirect(self.url(self.context)) |
---|
| 935 | return |
---|
| 936 | if not self.current_academic_session: |
---|
| 937 | self.flash(_('Current academic session not set.'), type="warning") |
---|
| 938 | self.redirect(self.url(self.context)) |
---|
| 939 | return |
---|
| 940 | site = grok.getSite() |
---|
| 941 | exporter = getUtility(ICSVExporter, name='lecturer') |
---|
| 942 | self.csv = exporter.export_filtered(site, filepath=None, |
---|
| 943 | catalog='coursetickets', |
---|
| 944 | session=self.current_academic_session-1, |
---|
| 945 | level=None, |
---|
| 946 | code=self.context.code) |
---|
[14306] | 947 | return |
---|
| 948 | |
---|
| 949 | class AlumniRequestPasswordPage(StudentRequestPasswordPage): |
---|
| 950 | """Captcha'd request password page for students. |
---|
| 951 | """ |
---|
| 952 | grok.name('alumni_requestpw') |
---|
| 953 | grok.require('waeup.Anonymous') |
---|
| 954 | grok.template('alumni_requestpw') |
---|
| 955 | form_fields = grok.AutoFields(IStudentRequestPW).select( |
---|
| 956 | 'lastname','number','email') |
---|
| 957 | label = _('Search student record and send password for first-time login') |
---|
| 958 | |
---|
| 959 | def _redirect_no_student(self): |
---|
| 960 | self.flash(_('No student record found.'), type="warning") |
---|
| 961 | self.redirect(self.application_url() + '/applicants/trans2017/register') |
---|
[14288] | 962 | return |
---|