| 1 | ## $Id: browser.py 18166 2025-09-03 07:38:18Z henrik $ |
|---|
| 2 | ## |
|---|
| 3 | ## Copyright (C) 2011 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 | """UI components for students and related components. |
|---|
| 19 | """ |
|---|
| 20 | import csv |
|---|
| 21 | import grok |
|---|
| 22 | import pytz |
|---|
| 23 | import sys |
|---|
| 24 | import os |
|---|
| 25 | import textwrap |
|---|
| 26 | import segno |
|---|
| 27 | from cStringIO import StringIO |
|---|
| 28 | from datetime import datetime |
|---|
| 29 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
|---|
| 30 | from urllib import urlencode |
|---|
| 31 | from zope.catalog.interfaces import ICatalog |
|---|
| 32 | from zope.component import queryUtility, getUtility, createObject |
|---|
| 33 | from zope.event import notify |
|---|
| 34 | from zope.formlib.textwidgets import BytesDisplayWidget |
|---|
| 35 | from zope.i18n import translate |
|---|
| 36 | from zope.schema.interfaces import ConstraintNotSatisfied, RequiredMissing |
|---|
| 37 | from zope.security import checkPermission |
|---|
| 38 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
|---|
| 39 | from waeup.kofa.smtp import encode_address |
|---|
| 40 | from waeup.kofa.accesscodes import invalidate_accesscode, get_access_code |
|---|
| 41 | from waeup.kofa.accesscodes.workflow import USED |
|---|
| 42 | from waeup.kofa.browser.pdf import ENTRY1_STYLE |
|---|
| 43 | from waeup.kofa.browser.breadcrumbs import Breadcrumb |
|---|
| 44 | from waeup.kofa.browser.interfaces import ICaptchaManager |
|---|
| 45 | from waeup.kofa.browser.layout import ( |
|---|
| 46 | KofaPage, KofaFormPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage, |
|---|
| 47 | NullValidator, jsaction, action, UtilityView) |
|---|
| 48 | from waeup.kofa.browser.pages import ( |
|---|
| 49 | ContactAdminFormPage, ExportCSVView, doll_up, exports_not_allowed, |
|---|
| 50 | LocalRoleAssignmentUtilityView) |
|---|
| 51 | from waeup.kofa.hostels.hostel import NOT_OCCUPIED |
|---|
| 52 | from waeup.kofa.interfaces import ( |
|---|
| 53 | IKofaObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm, |
|---|
| 54 | IKofaUtils, IObjectHistory, academic_sessions, ICSVExporter, |
|---|
| 55 | academic_sessions_vocab, IDataCenter, DOCLINK) |
|---|
| 56 | from waeup.kofa.interfaces import MessageFactory as _ |
|---|
| 57 | from waeup.kofa.mandates.mandate import PasswordMandate, ParentsPasswordMandate |
|---|
| 58 | from waeup.kofa.university.interfaces import ( |
|---|
| 59 | IDepartment, ICertificate, ICourse, IFlashNotice) |
|---|
| 60 | from waeup.kofa.university.certificate import ( |
|---|
| 61 | VirtualCertificateExportJobContainer) |
|---|
| 62 | from waeup.kofa.university.department import ( |
|---|
| 63 | VirtualDepartmentExportJobContainer) |
|---|
| 64 | from waeup.kofa.university.faculty import VirtualFacultyExportJobContainer |
|---|
| 65 | from waeup.kofa.university.facultiescontainer import ( |
|---|
| 66 | VirtualFacultiesExportJobContainer) |
|---|
| 67 | from waeup.kofa.university.course import ( |
|---|
| 68 | VirtualCourseExportJobContainer,) |
|---|
| 69 | from waeup.kofa.university.vocabularies import course_levels |
|---|
| 70 | from waeup.kofa.utils.batching import VirtualExportJobContainer |
|---|
| 71 | from waeup.kofa.utils.helpers import get_current_principal, now |
|---|
| 72 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
|---|
| 73 | from waeup.kofa.students.interfaces import ( |
|---|
| 74 | IStudentsContainer, IStudent, IUGStudentClearance, IPGStudentClearance, |
|---|
| 75 | IStudentPersonal, IStudentPersonalEdit, IStudentBase, IStudentStudyCourse, |
|---|
| 76 | IStudentStudyCourseTransfer, |
|---|
| 77 | IStudentAccommodation, IStudentStudyLevel, ICourseTicket, ICourseTicketAdd, |
|---|
| 78 | IStudentPaymentsContainer, IStudentOnlinePayment, IStudentPreviousPayment, |
|---|
| 79 | IStudentBalancePayment, IBedTicket, IStudentsUtils, IStudentRequestPW, |
|---|
| 80 | ) |
|---|
| 81 | from waeup.kofa.students.catalog import search, StudentQueryResultItem |
|---|
| 82 | from waeup.kofa.students.vocabularies import StudyLevelSource |
|---|
| 83 | from waeup.kofa.students.workflow import ( |
|---|
| 84 | ADMITTED, PAID, CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, |
|---|
| 85 | VALIDATED, GRADUATED, TRANSREQ, TRANSVAL, TRANSREL, FORBIDDEN_POSTGRAD_TRANS |
|---|
| 86 | ) |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | grok.context(IKofaObject) # Make IKofaObject the default context |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | class TicketError(Exception): |
|---|
| 93 | """A course ticket could not be added |
|---|
| 94 | """ |
|---|
| 95 | pass |
|---|
| 96 | |
|---|
| 97 | # Save function used for save methods in pages |
|---|
| 98 | def msave(view, **data): |
|---|
| 99 | changed_fields = view.applyData(view.context, **data) |
|---|
| 100 | # Turn list of lists into single list |
|---|
| 101 | if changed_fields: |
|---|
| 102 | changed_fields = reduce(lambda x, y: x+y, changed_fields.values()) |
|---|
| 103 | # Inform catalog if certificate has changed |
|---|
| 104 | # (applyData does this only for the context) |
|---|
| 105 | if 'certificate' in changed_fields: |
|---|
| 106 | notify(grok.ObjectModifiedEvent(view.context.student)) |
|---|
| 107 | fields_string = ' + '.join(changed_fields) |
|---|
| 108 | view.flash(_('Form has been saved.')) |
|---|
| 109 | if fields_string: |
|---|
| 110 | view.context.writeLogMessage(view, 'saved: %s' % fields_string) |
|---|
| 111 | return |
|---|
| 112 | |
|---|
| 113 | def emit_lock_message(view, msg=None): |
|---|
| 114 | """Flash a lock message. |
|---|
| 115 | """ |
|---|
| 116 | if msg: |
|---|
| 117 | view.flash(msg, type="warning") |
|---|
| 118 | view.redirect(view.url(view.context)) |
|---|
| 119 | return |
|---|
| 120 | view.flash(_('The requested form is locked (read-only).'), type="warning") |
|---|
| 121 | view.redirect(view.url(view.context)) |
|---|
| 122 | return |
|---|
| 123 | |
|---|
| 124 | def translated_values(view): |
|---|
| 125 | """Translate course ticket attribute values to be displayed on |
|---|
| 126 | studylevel pages. |
|---|
| 127 | """ |
|---|
| 128 | lang = view.request.cookies.get('kofa.language') |
|---|
| 129 | for value in view.context.values(): |
|---|
| 130 | # We have to unghostify (according to Tres Seaver) the __dict__ |
|---|
| 131 | # by activating the object, otherwise value_dict will be empty |
|---|
| 132 | # when calling the first time. |
|---|
| 133 | value._p_activate() |
|---|
| 134 | value_dict = dict([i for i in value.__dict__.items()]) |
|---|
| 135 | value_dict['url'] = view.url(value) |
|---|
| 136 | value_dict['removable_by_student'] = value.removable_by_student |
|---|
| 137 | value_dict['mandatory'] = translate(str(value.mandatory), 'zope', |
|---|
| 138 | target_language=lang) |
|---|
| 139 | value_dict['carry_over'] = translate(str(value.carry_over), 'zope', |
|---|
| 140 | target_language=lang) |
|---|
| 141 | value_dict['outstanding'] = translate(str(value.outstanding), 'zope', |
|---|
| 142 | target_language=lang) |
|---|
| 143 | value_dict['automatic'] = translate(str(value.automatic), 'zope', |
|---|
| 144 | target_language=lang) |
|---|
| 145 | value_dict['grade'] = value.grade |
|---|
| 146 | value_dict['weight'] = value.weight |
|---|
| 147 | value_dict['course_category'] = value.course_category |
|---|
| 148 | value_dict['total_score'] = value.total_score |
|---|
| 149 | semester_dict = getUtility(IKofaUtils).SEMESTER_DICT |
|---|
| 150 | value_dict['semester'] = semester_dict[ |
|---|
| 151 | value.semester].replace('mester', 'm.') |
|---|
| 152 | yield value_dict |
|---|
| 153 | |
|---|
| 154 | def addCourseTicket(view, course=None): |
|---|
| 155 | students_utils = getUtility(IStudentsUtils) |
|---|
| 156 | ticket = createObject(u'waeup.CourseTicket') |
|---|
| 157 | ticket.automatic = False |
|---|
| 158 | ticket.carry_over = False |
|---|
| 159 | warning = students_utils.warnCreditsOOR(view.context, course) |
|---|
| 160 | if warning: |
|---|
| 161 | view.flash(warning, type="warning") |
|---|
| 162 | return False |
|---|
| 163 | warning = students_utils.warnCourseAlreadyPassed(view.context, course) |
|---|
| 164 | if warning: |
|---|
| 165 | view.flash(warning, type="warning") |
|---|
| 166 | return False |
|---|
| 167 | try: |
|---|
| 168 | view.context.addCourseTicket(ticket, course) |
|---|
| 169 | except KeyError: |
|---|
| 170 | view.flash(_('The ticket exists.'), type="warning") |
|---|
| 171 | return False |
|---|
| 172 | except TicketError, error: |
|---|
| 173 | # Ticket errors are not being raised in the base package. |
|---|
| 174 | view.flash(error, type="warning") |
|---|
| 175 | return False |
|---|
| 176 | view.flash(_('Successfully added ${a}.', |
|---|
| 177 | mapping = {'a':ticket.code})) |
|---|
| 178 | view.context.writeLogMessage( |
|---|
| 179 | view,'added: %s|%s|%s' % ( |
|---|
| 180 | ticket.code, ticket.level, ticket.level_session)) |
|---|
| 181 | return True |
|---|
| 182 | |
|---|
| 183 | def level_dict(studycourse): |
|---|
| 184 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 185 | level_dict = {} |
|---|
| 186 | studylevelsource = StudyLevelSource().factory |
|---|
| 187 | for code in studylevelsource.getValues(studycourse): |
|---|
| 188 | title = translate(studylevelsource.getTitle(studycourse, code), |
|---|
| 189 | 'waeup.kofa', target_language=portal_language) |
|---|
| 190 | level_dict[code] = title |
|---|
| 191 | return level_dict |
|---|
| 192 | |
|---|
| 193 | class StudentsBreadcrumb(Breadcrumb): |
|---|
| 194 | """A breadcrumb for the students container. |
|---|
| 195 | """ |
|---|
| 196 | grok.context(IStudentsContainer) |
|---|
| 197 | title = _('Students') |
|---|
| 198 | |
|---|
| 199 | @property |
|---|
| 200 | def target(self): |
|---|
| 201 | user = get_current_principal() |
|---|
| 202 | if getattr(user, 'user_type', None) == 'student': |
|---|
| 203 | return None |
|---|
| 204 | return self.viewname |
|---|
| 205 | |
|---|
| 206 | class StudentBreadcrumb(Breadcrumb): |
|---|
| 207 | """A breadcrumb for the student container. |
|---|
| 208 | """ |
|---|
| 209 | grok.context(IStudent) |
|---|
| 210 | |
|---|
| 211 | def title(self): |
|---|
| 212 | return self.context.display_fullname |
|---|
| 213 | |
|---|
| 214 | class SudyCourseBreadcrumb(Breadcrumb): |
|---|
| 215 | """A breadcrumb for the student study course. |
|---|
| 216 | """ |
|---|
| 217 | grok.context(IStudentStudyCourse) |
|---|
| 218 | |
|---|
| 219 | def title(self): |
|---|
| 220 | if self.context.is_current: |
|---|
| 221 | return _('Study Course') |
|---|
| 222 | else: |
|---|
| 223 | return _('Previous Study Course') |
|---|
| 224 | |
|---|
| 225 | class PaymentsBreadcrumb(Breadcrumb): |
|---|
| 226 | """A breadcrumb for the student payments folder. |
|---|
| 227 | """ |
|---|
| 228 | grok.context(IStudentPaymentsContainer) |
|---|
| 229 | title = _('Payments') |
|---|
| 230 | |
|---|
| 231 | class OnlinePaymentBreadcrumb(Breadcrumb): |
|---|
| 232 | """A breadcrumb for payments. |
|---|
| 233 | """ |
|---|
| 234 | grok.context(IStudentOnlinePayment) |
|---|
| 235 | |
|---|
| 236 | @property |
|---|
| 237 | def title(self): |
|---|
| 238 | return self.context.p_id |
|---|
| 239 | |
|---|
| 240 | class AccommodationBreadcrumb(Breadcrumb): |
|---|
| 241 | """A breadcrumb for the student accommodation folder. |
|---|
| 242 | """ |
|---|
| 243 | grok.context(IStudentAccommodation) |
|---|
| 244 | title = _('Accommodation') |
|---|
| 245 | |
|---|
| 246 | class BedTicketBreadcrumb(Breadcrumb): |
|---|
| 247 | """A breadcrumb for bed tickets. |
|---|
| 248 | """ |
|---|
| 249 | grok.context(IBedTicket) |
|---|
| 250 | |
|---|
| 251 | @property |
|---|
| 252 | def title(self): |
|---|
| 253 | return _('Bed Ticket ${a}', |
|---|
| 254 | mapping = {'a':self.context.getSessionString()}) |
|---|
| 255 | |
|---|
| 256 | class StudyLevelBreadcrumb(Breadcrumb): |
|---|
| 257 | """A breadcrumb for course lists. |
|---|
| 258 | """ |
|---|
| 259 | grok.context(IStudentStudyLevel) |
|---|
| 260 | |
|---|
| 261 | @property |
|---|
| 262 | def title(self): |
|---|
| 263 | return self.context.level_title |
|---|
| 264 | |
|---|
| 265 | class StudentsContainerPage(KofaPage): |
|---|
| 266 | """The standard view for student containers. |
|---|
| 267 | """ |
|---|
| 268 | grok.context(IStudentsContainer) |
|---|
| 269 | grok.name('index') |
|---|
| 270 | grok.require('waeup.viewStudentsContainer') |
|---|
| 271 | grok.template('containerpage') |
|---|
| 272 | label = _('Find students') |
|---|
| 273 | search_button = _('Find student(s)') |
|---|
| 274 | pnav = 4 |
|---|
| 275 | |
|---|
| 276 | def update(self, *args, **kw): |
|---|
| 277 | prefix = getUtility(IStudentsUtils).STUDENT_ID_PREFIX |
|---|
| 278 | self.curr_stud_id = "%s%s" % ( |
|---|
| 279 | prefix, self.context._curr_stud_id - 1) |
|---|
| 280 | form = self.request.form |
|---|
| 281 | self.hitlist = [] |
|---|
| 282 | if form.get('searchtype', None) in ( |
|---|
| 283 | 'suspended', TRANSREQ, TRANSVAL, GRADUATED): |
|---|
| 284 | self.searchtype = form['searchtype'] |
|---|
| 285 | self.searchterm = None |
|---|
| 286 | elif 'searchterm' in form and form['searchterm']: |
|---|
| 287 | self.searchterm = form['searchterm'] |
|---|
| 288 | self.searchtype = form['searchtype'] |
|---|
| 289 | elif 'old_searchterm' in form: |
|---|
| 290 | self.searchterm = form['old_searchterm'] |
|---|
| 291 | self.searchtype = form['old_searchtype'] |
|---|
| 292 | else: |
|---|
| 293 | if 'search' in form: |
|---|
| 294 | self.flash(_('Empty search string'), type="warning") |
|---|
| 295 | return |
|---|
| 296 | if self.searchtype == 'current_session': |
|---|
| 297 | try: |
|---|
| 298 | self.searchterm = int(self.searchterm) |
|---|
| 299 | except ValueError: |
|---|
| 300 | self.flash(_('Only year dates allowed (e.g. 2011).'), |
|---|
| 301 | type="danger") |
|---|
| 302 | return |
|---|
| 303 | self.hitlist = search(query=self.searchterm, |
|---|
| 304 | searchtype=self.searchtype, view=self) |
|---|
| 305 | if not self.hitlist: |
|---|
| 306 | self.flash(_('No student found.'), type="warning") |
|---|
| 307 | return |
|---|
| 308 | |
|---|
| 309 | class StudentsContainerManagePage(KofaPage): |
|---|
| 310 | """The manage page for student containers. |
|---|
| 311 | """ |
|---|
| 312 | grok.context(IStudentsContainer) |
|---|
| 313 | grok.name('manage') |
|---|
| 314 | grok.require('waeup.manageStudent') |
|---|
| 315 | grok.template('containermanagepage') |
|---|
| 316 | pnav = 4 |
|---|
| 317 | label = _('Manage students section') |
|---|
| 318 | search_button = _('Find student(s)') |
|---|
| 319 | remove_button = _('Remove selected') |
|---|
| 320 | send_email_button = _('Send bulk email') |
|---|
| 321 | doclink = DOCLINK + '/students.html' |
|---|
| 322 | |
|---|
| 323 | def update(self, *args, **kw): |
|---|
| 324 | form = self.request.form |
|---|
| 325 | self.hitlist = [] |
|---|
| 326 | if form.get('searchtype', None) in ( |
|---|
| 327 | 'suspended', TRANSREQ, TRANSVAL, GRADUATED): |
|---|
| 328 | self.searchtype = form['searchtype'] |
|---|
| 329 | self.searchterm = None |
|---|
| 330 | elif 'searchterm' in form and form['searchterm']: |
|---|
| 331 | self.searchterm = form['searchterm'] |
|---|
| 332 | self.searchtype = form['searchtype'] |
|---|
| 333 | elif 'old_searchterm' in form: |
|---|
| 334 | self.searchterm = form['old_searchterm'] |
|---|
| 335 | self.searchtype = form['old_searchtype'] |
|---|
| 336 | else: |
|---|
| 337 | if 'search' in form: |
|---|
| 338 | self.flash(_('Empty search string'), type="warning") |
|---|
| 339 | return |
|---|
| 340 | if self.searchtype == 'current_session': |
|---|
| 341 | try: |
|---|
| 342 | self.searchterm = int(self.searchterm) |
|---|
| 343 | except ValueError: |
|---|
| 344 | self.flash(_('Only year dates allowed (e.g. 2011).'), |
|---|
| 345 | type="danger") |
|---|
| 346 | return |
|---|
| 347 | if not 'entries' in form: |
|---|
| 348 | self.hitlist = search(query=self.searchterm, |
|---|
| 349 | searchtype=self.searchtype, view=self) |
|---|
| 350 | if not self.hitlist: |
|---|
| 351 | self.flash(_('No student found.'), type="warning") |
|---|
| 352 | if 'remove' in form or 'send_email' in form: |
|---|
| 353 | self.flash(_('No item selected.'), type="warning") |
|---|
| 354 | return |
|---|
| 355 | entries = form['entries'] |
|---|
| 356 | if isinstance(entries, basestring): |
|---|
| 357 | entries = [entries] |
|---|
| 358 | entries.sort() |
|---|
| 359 | if 'send_email' in form and len(entries)>50: |
|---|
| 360 | self.flash(_( |
|---|
| 361 | 'Maximum of 50 emails can be sent. Please select less students.'), |
|---|
| 362 | type="warning") |
|---|
| 363 | return |
|---|
| 364 | deleted = [] |
|---|
| 365 | emails_tobesent = [] |
|---|
| 366 | for entry in entries: |
|---|
| 367 | if 'remove' in form: |
|---|
| 368 | del self.context[entry] |
|---|
| 369 | deleted.append(entry) |
|---|
| 370 | if 'send_email' in form and self.context[entry].email: |
|---|
| 371 | emails_tobesent.append(( |
|---|
| 372 | self.context[entry].email, |
|---|
| 373 | self.context[entry].student_id)) |
|---|
| 374 | if 'send_email' in form and not len(emails_tobesent): |
|---|
| 375 | self.flash(_('No email address found.'), type="warning") |
|---|
| 376 | return |
|---|
| 377 | if len(emails_tobesent): |
|---|
| 378 | args = {'bcc_to': emails_tobesent} |
|---|
| 379 | self.redirect(self.url(self.context) + |
|---|
| 380 | '/send_bulk_email?%s' % urlencode(args)) |
|---|
| 381 | return |
|---|
| 382 | self.hitlist = search(query=self.searchterm, |
|---|
| 383 | searchtype=self.searchtype, view=self) |
|---|
| 384 | if len(deleted): |
|---|
| 385 | self.flash(_('Successfully removed: ${a}', |
|---|
| 386 | mapping = {'a':', '.join(deleted)})) |
|---|
| 387 | return |
|---|
| 388 | |
|---|
| 389 | class StudentAddFormPage(KofaAddFormPage): |
|---|
| 390 | """Add-form to add a student. |
|---|
| 391 | """ |
|---|
| 392 | grok.context(IStudentsContainer) |
|---|
| 393 | grok.require('waeup.manageStudent') |
|---|
| 394 | grok.name('addstudent') |
|---|
| 395 | form_fields = grok.AutoFields(IStudent).select( |
|---|
| 396 | 'firstname', 'middlename', 'lastname', 'reg_number') |
|---|
| 397 | label = _('Add student') |
|---|
| 398 | pnav = 4 |
|---|
| 399 | |
|---|
| 400 | @action(_('Create student'), style='primary') |
|---|
| 401 | def addStudent(self, **data): |
|---|
| 402 | student = createObject(u'waeup.Student') |
|---|
| 403 | self.applyData(student, **data) |
|---|
| 404 | self.context.addStudent(student) |
|---|
| 405 | self.flash(_('Student record created.')) |
|---|
| 406 | self.redirect(self.url(self.context[student.student_id], 'index')) |
|---|
| 407 | return |
|---|
| 408 | |
|---|
| 409 | @action(_('Create graduated student'), style='primary') |
|---|
| 410 | def addGraduatedStudent(self, **data): |
|---|
| 411 | student = createObject(u'waeup.Student') |
|---|
| 412 | self.applyData(student, **data) |
|---|
| 413 | self.context.addStudent(student) |
|---|
| 414 | IWorkflowState(student).setState(GRADUATED) |
|---|
| 415 | notify(grok.ObjectModifiedEvent(student)) |
|---|
| 416 | history = IObjectHistory(student) |
|---|
| 417 | history.addMessage("State 'graduated' set") |
|---|
| 418 | self.flash(_('Graduated student record created.')) |
|---|
| 419 | self.redirect(self.url(self.context[student.student_id], 'index')) |
|---|
| 420 | return |
|---|
| 421 | |
|---|
| 422 | class LoginAsStudentStep1(KofaEditFormPage): |
|---|
| 423 | """ View to temporarily set a student password. |
|---|
| 424 | """ |
|---|
| 425 | grok.context(IStudent) |
|---|
| 426 | grok.name('loginasstep1') |
|---|
| 427 | grok.require('waeup.loginAsStudent') |
|---|
| 428 | grok.template('loginasstep1') |
|---|
| 429 | pnav = 4 |
|---|
| 430 | |
|---|
| 431 | def update(self): |
|---|
| 432 | super(LoginAsStudentStep1, self).update() |
|---|
| 433 | kofa_utils = getUtility(IKofaUtils) |
|---|
| 434 | self.temp_password_minutes = kofa_utils.TEMP_PASSWORD_MINUTES |
|---|
| 435 | return |
|---|
| 436 | |
|---|
| 437 | def label(self): |
|---|
| 438 | return _(u'Set temporary password for ${a}', |
|---|
| 439 | mapping = {'a':self.context.display_fullname}) |
|---|
| 440 | |
|---|
| 441 | @action('Set password now', style='primary') |
|---|
| 442 | def setPassword(self, *args, **data): |
|---|
| 443 | kofa_utils = getUtility(IKofaUtils) |
|---|
| 444 | password = kofa_utils.genPassword() |
|---|
| 445 | self.context.setTempPassword(self.request.principal.id, password) |
|---|
| 446 | self.context.writeLogMessage( |
|---|
| 447 | self, 'temp_password generated: %s' % password) |
|---|
| 448 | args = {'password':password} |
|---|
| 449 | self.redirect(self.url(self.context) + |
|---|
| 450 | '/loginasstep2?%s' % urlencode(args)) |
|---|
| 451 | return |
|---|
| 452 | |
|---|
| 453 | class LoginAsStudentStep2(KofaPage): |
|---|
| 454 | """ View to temporarily login as student with a temporary password. |
|---|
| 455 | """ |
|---|
| 456 | grok.context(IStudent) |
|---|
| 457 | grok.name('loginasstep2') |
|---|
| 458 | grok.require('waeup.Public') |
|---|
| 459 | grok.template('loginasstep2') |
|---|
| 460 | login_button = _('Login now') |
|---|
| 461 | pnav = 4 |
|---|
| 462 | |
|---|
| 463 | def label(self): |
|---|
| 464 | return _(u'Login as ${a}', |
|---|
| 465 | mapping = {'a':self.context.student_id}) |
|---|
| 466 | |
|---|
| 467 | def update(self, SUBMIT=None, password=None): |
|---|
| 468 | self.password = password |
|---|
| 469 | if SUBMIT is not None: |
|---|
| 470 | self.flash(_('You successfully logged in as student.')) |
|---|
| 471 | self.redirect(self.url(self.context)) |
|---|
| 472 | return |
|---|
| 473 | |
|---|
| 474 | class StudentBaseDisplayFormPage(KofaDisplayFormPage): |
|---|
| 475 | """ Page to display student base data |
|---|
| 476 | """ |
|---|
| 477 | grok.context(IStudent) |
|---|
| 478 | grok.name('index') |
|---|
| 479 | grok.require('waeup.viewStudent') |
|---|
| 480 | grok.template('basepage') |
|---|
| 481 | form_fields = grok.AutoFields(IStudentBase).omit( |
|---|
| 482 | 'password', 'suspended', 'suspended_comment', 'flash_notice') |
|---|
| 483 | form_fields[ |
|---|
| 484 | 'password_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 485 | pnav = 4 |
|---|
| 486 | |
|---|
| 487 | @property |
|---|
| 488 | def label(self): |
|---|
| 489 | if self.context.suspended: |
|---|
| 490 | return _('${a}: Base Data (account deactivated)', |
|---|
| 491 | mapping = {'a':self.context.display_fullname}) |
|---|
| 492 | return _('${a}: Base Data', |
|---|
| 493 | mapping = {'a':self.context.display_fullname}) |
|---|
| 494 | |
|---|
| 495 | @property |
|---|
| 496 | def hasPassword(self): |
|---|
| 497 | if self.context.password: |
|---|
| 498 | return _('set') |
|---|
| 499 | return _('unset') |
|---|
| 500 | |
|---|
| 501 | def update(self): |
|---|
| 502 | if self.context.flash_notice: |
|---|
| 503 | self.flash(self.context.flash_notice, type="warning") |
|---|
| 504 | super(StudentBaseDisplayFormPage, self).update() |
|---|
| 505 | return |
|---|
| 506 | |
|---|
| 507 | class StudentBasePDFFormPage(KofaDisplayFormPage): |
|---|
| 508 | """ Page to display student base data in pdf files. |
|---|
| 509 | """ |
|---|
| 510 | |
|---|
| 511 | def __init__(self, context, request, omit_fields=()): |
|---|
| 512 | self.omit_fields = omit_fields |
|---|
| 513 | super(StudentBasePDFFormPage, self).__init__(context, request) |
|---|
| 514 | |
|---|
| 515 | @property |
|---|
| 516 | def form_fields(self): |
|---|
| 517 | form_fields = grok.AutoFields(IStudentBase) |
|---|
| 518 | for field in self.omit_fields: |
|---|
| 519 | form_fields = form_fields.omit(field) |
|---|
| 520 | return form_fields |
|---|
| 521 | |
|---|
| 522 | class ContactStudentFormPage(ContactAdminFormPage): |
|---|
| 523 | grok.context(IStudent) |
|---|
| 524 | grok.name('contactstudent') |
|---|
| 525 | grok.require('waeup.viewStudent') |
|---|
| 526 | pnav = 4 |
|---|
| 527 | form_fields = grok.AutoFields(IContactForm).select('subject', 'body') |
|---|
| 528 | |
|---|
| 529 | def update(self, subject=u'', body=u''): |
|---|
| 530 | super(ContactStudentFormPage, self).update() |
|---|
| 531 | self.form_fields.get('subject').field.default = subject |
|---|
| 532 | self.form_fields.get('body').field.default = body |
|---|
| 533 | return |
|---|
| 534 | |
|---|
| 535 | def label(self): |
|---|
| 536 | return _(u'Send message to ${a}', |
|---|
| 537 | mapping = {'a':self.context.display_fullname}) |
|---|
| 538 | |
|---|
| 539 | @action('Send message now', style='primary') |
|---|
| 540 | def send(self, *args, **data): |
|---|
| 541 | try: |
|---|
| 542 | email = self.request.principal.email |
|---|
| 543 | except AttributeError: |
|---|
| 544 | email = self.config.email_admin |
|---|
| 545 | usertype = getattr(self.request.principal, |
|---|
| 546 | 'user_type', 'system').title() |
|---|
| 547 | kofa_utils = getUtility(IKofaUtils) |
|---|
| 548 | success = kofa_utils.sendContactForm( |
|---|
| 549 | self.request.principal.title,email, |
|---|
| 550 | self.context.display_fullname,self.context.email, |
|---|
| 551 | self.request.principal.id,usertype, |
|---|
| 552 | self.config.name, |
|---|
| 553 | data['body'],data['subject']) |
|---|
| 554 | if success: |
|---|
| 555 | self.flash(_('Your message has been sent.')) |
|---|
| 556 | else: |
|---|
| 557 | self.flash(_('An smtp server error occurred.'), type="danger") |
|---|
| 558 | return |
|---|
| 559 | |
|---|
| 560 | class SendBulEmailsFormPage(ContactAdminFormPage): |
|---|
| 561 | grok.context(IStudentsContainer) |
|---|
| 562 | grok.name('send_bulk_email') |
|---|
| 563 | grok.require('waeup.manageStudent') |
|---|
| 564 | pnav = 4 |
|---|
| 565 | form_fields = grok.AutoFields(IContactForm).select('subject', 'body', 'bcc_to') |
|---|
| 566 | label = _('Send bulk email') |
|---|
| 567 | |
|---|
| 568 | def update(self, bcc_to=u''): |
|---|
| 569 | self.form_fields.get('bcc_to').field.default = bcc_to |
|---|
| 570 | return |
|---|
| 571 | |
|---|
| 572 | @action('Send message now', style='primary') |
|---|
| 573 | def send(self, *args, **data): |
|---|
| 574 | try: |
|---|
| 575 | email = self.request.principal.email |
|---|
| 576 | except AttributeError: |
|---|
| 577 | email = self.config.email_admin |
|---|
| 578 | usertype = getattr(self.request.principal, |
|---|
| 579 | 'user_type', 'system').title() |
|---|
| 580 | kofa_utils = getUtility(IKofaUtils) |
|---|
| 581 | success = kofa_utils.sendContactForm( |
|---|
| 582 | self.request.principal.title,email, |
|---|
| 583 | self.request.principal.title,email, # sent to the sender's address |
|---|
| 584 | self.request.principal.id,usertype, |
|---|
| 585 | self.config.name, |
|---|
| 586 | data['body'],data['subject'], |
|---|
| 587 | eval(data['bcc_to']) |
|---|
| 588 | ) |
|---|
| 589 | if success: |
|---|
| 590 | self.flash(_('Your message has been sent.')) |
|---|
| 591 | else: |
|---|
| 592 | self.flash(_('An smtp server error occurred.'), type="danger") |
|---|
| 593 | return |
|---|
| 594 | |
|---|
| 595 | class ExportPDFAdmissionSlip(UtilityView, grok.View): |
|---|
| 596 | """Deliver a PDF Admission slip. |
|---|
| 597 | """ |
|---|
| 598 | grok.context(IStudent) |
|---|
| 599 | grok.name('admission_slip.pdf') |
|---|
| 600 | grok.require('waeup.viewStudent') |
|---|
| 601 | prefix = 'form' |
|---|
| 602 | |
|---|
| 603 | omit_fields = ('date_of_birth', 'current_level') |
|---|
| 604 | |
|---|
| 605 | form_fields = grok.AutoFields(IStudentBase).select('student_id', 'reg_number') |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | # Can be used for testing. Just replace 'post_text=None' |
|---|
| 609 | # by post_text=self.post_text' |
|---|
| 610 | post_text = ''' |
|---|
| 611 | Conratulations! |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | <img src="${test_signature_img_path}" valign="-20" height="38" width="86" /> |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | John Tester |
|---|
| 618 | - Registrar - |
|---|
| 619 | ''' |
|---|
| 620 | |
|---|
| 621 | @property |
|---|
| 622 | def label(self): |
|---|
| 623 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 624 | return translate(_('Admission Letter of'), |
|---|
| 625 | 'waeup.kofa', target_language=portal_language) \ |
|---|
| 626 | + ' %s' % self.context.display_fullname |
|---|
| 627 | |
|---|
| 628 | def render(self): |
|---|
| 629 | students_utils = getUtility(IStudentsUtils) |
|---|
| 630 | letterhead_path = os.path.join( |
|---|
| 631 | os.path.dirname(__file__), 'static', 'letterhead_admission.jpg') |
|---|
| 632 | if not os.path.exists(letterhead_path): |
|---|
| 633 | letterhead_path = None |
|---|
| 634 | return students_utils.renderPDFAdmissionLetter(self, |
|---|
| 635 | self.context.student, omit_fields=self.omit_fields, |
|---|
| 636 | letterhead_path=letterhead_path, post_text=None) |
|---|
| 637 | |
|---|
| 638 | class QRCodeView(UtilityView, grok.View): |
|---|
| 639 | """View which renders a QRCode only. |
|---|
| 640 | """ |
|---|
| 641 | grok.context(IStudent) |
|---|
| 642 | grok.name('qrcode_admission_letter.png') |
|---|
| 643 | grok.require('waeup.viewStudent') |
|---|
| 644 | scale = 3 |
|---|
| 645 | uri = 'admission_slip.pdf' |
|---|
| 646 | |
|---|
| 647 | def render(self): |
|---|
| 648 | qrcode = segno.make(self.url(self.context, self.uri)) |
|---|
| 649 | self.response.setHeader('Content-Type', 'image/png') |
|---|
| 650 | return qrcode.png_data_uri( |
|---|
| 651 | scale=self.scale).split(',')[1].decode('base64') |
|---|
| 652 | |
|---|
| 653 | class StudentBaseManageFormPage(KofaEditFormPage): |
|---|
| 654 | """ View to manage student base data |
|---|
| 655 | """ |
|---|
| 656 | grok.context(IStudent) |
|---|
| 657 | grok.name('manage_base') |
|---|
| 658 | grok.require('waeup.manageStudent') |
|---|
| 659 | form_fields = grok.AutoFields(IStudentBase).omit( |
|---|
| 660 | 'student_id', 'adm_code', 'suspended', 'password_updated') |
|---|
| 661 | grok.template('basemanagepage') |
|---|
| 662 | label = _('Manage base data') |
|---|
| 663 | deletion_warning = _('Are you sure?') |
|---|
| 664 | pnav = 4 |
|---|
| 665 | |
|---|
| 666 | def update(self): |
|---|
| 667 | super(StudentBaseManageFormPage, self).update() |
|---|
| 668 | self.wf_info = IWorkflowInfo(self.context) |
|---|
| 669 | return |
|---|
| 670 | |
|---|
| 671 | @action(_('Save'), style='primary') |
|---|
| 672 | def save(self, **data): |
|---|
| 673 | form = self.request.form |
|---|
| 674 | password = form.get('password', None) |
|---|
| 675 | password_ctl = form.get('control_password', None) |
|---|
| 676 | if password: |
|---|
| 677 | validator = getUtility(IPasswordValidator) |
|---|
| 678 | errors = validator.validate_password(password, password_ctl) |
|---|
| 679 | if errors: |
|---|
| 680 | self.flash( ' '.join(errors), type="danger") |
|---|
| 681 | return |
|---|
| 682 | changed_fields = self.applyData(self.context, **data) |
|---|
| 683 | # Turn list of lists into single list |
|---|
| 684 | if changed_fields: |
|---|
| 685 | changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) |
|---|
| 686 | else: |
|---|
| 687 | changed_fields = [] |
|---|
| 688 | if password: |
|---|
| 689 | # Now we know that the form has no errors and can set password |
|---|
| 690 | IUserAccount(self.context).setPassword(password) |
|---|
| 691 | changed_fields.append('password') |
|---|
| 692 | fields_string = ' + '.join(changed_fields) |
|---|
| 693 | self.flash(_('Form has been saved.')) |
|---|
| 694 | if fields_string: |
|---|
| 695 | self.context.writeLogMessage(self, 'saved: % s' % fields_string) |
|---|
| 696 | return |
|---|
| 697 | |
|---|
| 698 | class StudentTriggerTransitionFormPage(KofaEditFormPage): |
|---|
| 699 | """ View to trigger student workflow transitions |
|---|
| 700 | """ |
|---|
| 701 | grok.context(IStudent) |
|---|
| 702 | grok.name('trigtrans') |
|---|
| 703 | grok.require('waeup.triggerTransition') |
|---|
| 704 | grok.template('trigtrans') |
|---|
| 705 | label = _('Trigger registration transition') |
|---|
| 706 | pnav = 4 |
|---|
| 707 | |
|---|
| 708 | def getTransitions(self): |
|---|
| 709 | """Return a list of dicts of allowed transition ids and titles. |
|---|
| 710 | |
|---|
| 711 | Each list entry provides keys ``name`` and ``title`` for |
|---|
| 712 | internal name and (human readable) title of a single |
|---|
| 713 | transition. |
|---|
| 714 | """ |
|---|
| 715 | wf_info = IWorkflowInfo(self.context) |
|---|
| 716 | allowed_transitions = [t for t in wf_info.getManualTransitions() |
|---|
| 717 | if not t[0].startswith('pay')] |
|---|
| 718 | if self.context.is_postgrad and not self.context.is_special_postgrad: |
|---|
| 719 | allowed_transitions = [t for t in allowed_transitions |
|---|
| 720 | if not t[0] in FORBIDDEN_POSTGRAD_TRANS] |
|---|
| 721 | return [dict(name='', title=_('No transition'))] +[ |
|---|
| 722 | dict(name=x, title=y) for x, y in allowed_transitions] |
|---|
| 723 | |
|---|
| 724 | @action(_('Save'), style='primary') |
|---|
| 725 | def save(self, **data): |
|---|
| 726 | form = self.request.form |
|---|
| 727 | if 'transition' in form and form['transition']: |
|---|
| 728 | transition_id = form['transition'] |
|---|
| 729 | wf_info = IWorkflowInfo(self.context) |
|---|
| 730 | wf_info.fireTransition(transition_id) |
|---|
| 731 | return |
|---|
| 732 | |
|---|
| 733 | class StudentActivateView(UtilityView, grok.View): |
|---|
| 734 | """ Activate student account |
|---|
| 735 | """ |
|---|
| 736 | grok.context(IStudent) |
|---|
| 737 | grok.name('activate') |
|---|
| 738 | grok.require('waeup.manageStudent') |
|---|
| 739 | |
|---|
| 740 | def update(self): |
|---|
| 741 | self.context.suspended = False |
|---|
| 742 | self.context.writeLogMessage(self, 'account activated') |
|---|
| 743 | history = IObjectHistory(self.context) |
|---|
| 744 | history.addMessage('Student account activated') |
|---|
| 745 | self.flash(_('Student account has been activated.')) |
|---|
| 746 | self.redirect(self.url(self.context)) |
|---|
| 747 | return |
|---|
| 748 | |
|---|
| 749 | def render(self): |
|---|
| 750 | return |
|---|
| 751 | |
|---|
| 752 | class StudentDeactivateView(UtilityView, grok.View): |
|---|
| 753 | """ Deactivate student account |
|---|
| 754 | """ |
|---|
| 755 | grok.context(IStudent) |
|---|
| 756 | grok.name('deactivate') |
|---|
| 757 | grok.require('waeup.manageStudent') |
|---|
| 758 | |
|---|
| 759 | def update(self): |
|---|
| 760 | self.context.suspended = True |
|---|
| 761 | self.context.writeLogMessage(self, 'account deactivated') |
|---|
| 762 | history = IObjectHistory(self.context) |
|---|
| 763 | history.addMessage('Student account deactivated') |
|---|
| 764 | self.flash(_('Student account has been deactivated.')) |
|---|
| 765 | self.redirect(self.url(self.context)) |
|---|
| 766 | return |
|---|
| 767 | |
|---|
| 768 | def render(self): |
|---|
| 769 | return |
|---|
| 770 | |
|---|
| 771 | class StudentClearanceDisplayFormPage(KofaDisplayFormPage): |
|---|
| 772 | """ Page to display student clearance data |
|---|
| 773 | """ |
|---|
| 774 | grok.context(IStudent) |
|---|
| 775 | grok.name('view_clearance') |
|---|
| 776 | grok.require('waeup.viewStudent') |
|---|
| 777 | pnav = 4 |
|---|
| 778 | |
|---|
| 779 | @property |
|---|
| 780 | def separators(self): |
|---|
| 781 | return getUtility(IStudentsUtils).SEPARATORS_DICT |
|---|
| 782 | |
|---|
| 783 | @property |
|---|
| 784 | def form_fields(self): |
|---|
| 785 | if self.context.is_postgrad: |
|---|
| 786 | form_fields = grok.AutoFields(IPGStudentClearance) |
|---|
| 787 | else: |
|---|
| 788 | form_fields = grok.AutoFields(IUGStudentClearance) |
|---|
| 789 | if not getattr(self.context, 'officer_comment'): |
|---|
| 790 | form_fields = form_fields.omit('officer_comment') |
|---|
| 791 | else: |
|---|
| 792 | form_fields['officer_comment'].custom_widget = BytesDisplayWidget |
|---|
| 793 | return form_fields |
|---|
| 794 | |
|---|
| 795 | @property |
|---|
| 796 | def label(self): |
|---|
| 797 | return _('${a}: Clearance Data', |
|---|
| 798 | mapping = {'a':self.context.display_fullname}) |
|---|
| 799 | |
|---|
| 800 | class ExportPDFStudyCourseBaseDataSlip(UtilityView, grok.View): |
|---|
| 801 | """Deliver a PDF base and studycourse data slip. |
|---|
| 802 | """ |
|---|
| 803 | grok.context(IStudentStudyCourse) |
|---|
| 804 | grok.name('studycourse_slip.pdf') |
|---|
| 805 | grok.require('waeup.viewStudent') |
|---|
| 806 | prefix = 'form' |
|---|
| 807 | |
|---|
| 808 | omit_fields = ( |
|---|
| 809 | 'suspended', |
|---|
| 810 | 'adm_code', 'suspended_comment', |
|---|
| 811 | 'current_level', |
|---|
| 812 | 'flash_notice', 'entry_session', |
|---|
| 813 | 'parents_email') |
|---|
| 814 | |
|---|
| 815 | form_fields = grok.AutoFields(IStudentStudyCourse).omit('certificate') |
|---|
| 816 | |
|---|
| 817 | @property |
|---|
| 818 | def title(self): |
|---|
| 819 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 820 | return translate(_('Current Study Course Data'), 'waeup.kofa', |
|---|
| 821 | target_language=portal_language) |
|---|
| 822 | |
|---|
| 823 | @property |
|---|
| 824 | def label(self): |
|---|
| 825 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 826 | return translate(_('Study Course Data of'), |
|---|
| 827 | 'waeup.kofa', target_language=portal_language) \ |
|---|
| 828 | + ' %s' % self.context.student.display_fullname |
|---|
| 829 | |
|---|
| 830 | def render(self): |
|---|
| 831 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 832 | self.request, self.omit_fields) |
|---|
| 833 | students_utils = getUtility(IStudentsUtils) |
|---|
| 834 | return students_utils.renderPDF( |
|---|
| 835 | self, 'basedata_slip_%s.pdf' % self.context.student.student_id, |
|---|
| 836 | self.context.student, studentview, |
|---|
| 837 | omit_fields=self.omit_fields) |
|---|
| 838 | |
|---|
| 839 | class ExportPDFPersonalDataSlip(UtilityView, grok.View): |
|---|
| 840 | """Deliver a PDF base and personal data slip. |
|---|
| 841 | """ |
|---|
| 842 | grok.context(IStudent) |
|---|
| 843 | grok.name('personal_slip.pdf') |
|---|
| 844 | grok.require('waeup.viewStudent') |
|---|
| 845 | prefix = 'form' |
|---|
| 846 | |
|---|
| 847 | omit_fields = ( |
|---|
| 848 | 'suspended', |
|---|
| 849 | 'adm_code', 'suspended_comment', |
|---|
| 850 | 'current_level', |
|---|
| 851 | 'flash_notice', 'entry_session', |
|---|
| 852 | 'parents_email') |
|---|
| 853 | |
|---|
| 854 | form_fields = grok.AutoFields(IStudentPersonal) |
|---|
| 855 | |
|---|
| 856 | @property |
|---|
| 857 | def title(self): |
|---|
| 858 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 859 | return translate(_('Personal Data'), 'waeup.kofa', |
|---|
| 860 | target_language=portal_language) |
|---|
| 861 | |
|---|
| 862 | @property |
|---|
| 863 | def label(self): |
|---|
| 864 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 865 | return translate(_('Personal Data of'), |
|---|
| 866 | 'waeup.kofa', target_language=portal_language) \ |
|---|
| 867 | + ' %s' % self.context.student.display_fullname |
|---|
| 868 | |
|---|
| 869 | def render(self): |
|---|
| 870 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 871 | self.request, self.omit_fields) |
|---|
| 872 | students_utils = getUtility(IStudentsUtils) |
|---|
| 873 | return students_utils.renderPDF( |
|---|
| 874 | self, 'personal_slip_%s.pdf' % self.context.student.student_id, |
|---|
| 875 | self.context.student, studentview, |
|---|
| 876 | omit_fields=self.omit_fields) |
|---|
| 877 | |
|---|
| 878 | class ExportPDFClearanceSlip(grok.View): |
|---|
| 879 | """Deliver a PDF slip of the context. |
|---|
| 880 | """ |
|---|
| 881 | grok.context(IStudent) |
|---|
| 882 | grok.name('clearance_slip.pdf') |
|---|
| 883 | grok.require('waeup.viewStudent') |
|---|
| 884 | prefix = 'form' |
|---|
| 885 | omit_fields = ( |
|---|
| 886 | 'suspended', 'phone', |
|---|
| 887 | 'adm_code', 'suspended_comment', |
|---|
| 888 | 'date_of_birth', 'current_level', |
|---|
| 889 | 'flash_notice') |
|---|
| 890 | |
|---|
| 891 | @property |
|---|
| 892 | def form_fields(self): |
|---|
| 893 | if self.context.is_postgrad: |
|---|
| 894 | form_fields = grok.AutoFields(IPGStudentClearance) |
|---|
| 895 | else: |
|---|
| 896 | form_fields = grok.AutoFields(IUGStudentClearance) |
|---|
| 897 | if not getattr(self.context, 'officer_comment'): |
|---|
| 898 | form_fields = form_fields.omit('officer_comment') |
|---|
| 899 | return form_fields |
|---|
| 900 | |
|---|
| 901 | @property |
|---|
| 902 | def title(self): |
|---|
| 903 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 904 | return translate(_('Clearance Data'), 'waeup.kofa', |
|---|
| 905 | target_language=portal_language) |
|---|
| 906 | |
|---|
| 907 | @property |
|---|
| 908 | def label(self): |
|---|
| 909 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 910 | return translate(_('Clearance Slip of'), |
|---|
| 911 | 'waeup.kofa', target_language=portal_language) \ |
|---|
| 912 | + ' %s' % self.context.display_fullname |
|---|
| 913 | |
|---|
| 914 | # XXX: not used in waeup.kofa and thus not tested |
|---|
| 915 | def _signatures(self): |
|---|
| 916 | isStudent = getattr( |
|---|
| 917 | self.request.principal, 'user_type', None) == 'student' |
|---|
| 918 | if not isStudent and self.context.state in (CLEARED, ): |
|---|
| 919 | return ([_('Student Signature')], |
|---|
| 920 | [_('Clearance Officer Signature')]) |
|---|
| 921 | return |
|---|
| 922 | |
|---|
| 923 | def _sigsInFooter(self): |
|---|
| 924 | isStudent = getattr( |
|---|
| 925 | self.request.principal, 'user_type', None) == 'student' |
|---|
| 926 | if not isStudent and self.context.state in (CLEARED, ): |
|---|
| 927 | return (_('Date, Student Signature'), |
|---|
| 928 | _('Date, Clearance Officer Signature'), |
|---|
| 929 | ) |
|---|
| 930 | return () |
|---|
| 931 | |
|---|
| 932 | def render(self): |
|---|
| 933 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 934 | self.request, self.omit_fields) |
|---|
| 935 | students_utils = getUtility(IStudentsUtils) |
|---|
| 936 | return students_utils.renderPDF( |
|---|
| 937 | self, 'clearance_slip_%s.pdf' % self.context.student.student_id, |
|---|
| 938 | self.context.student, studentview, signatures=self._signatures(), |
|---|
| 939 | sigs_in_footer=self._sigsInFooter(), |
|---|
| 940 | omit_fields=self.omit_fields) |
|---|
| 941 | |
|---|
| 942 | class StudentClearanceManageFormPage(KofaEditFormPage): |
|---|
| 943 | """ Page to manage student clearance data |
|---|
| 944 | """ |
|---|
| 945 | grok.context(IStudent) |
|---|
| 946 | grok.name('manage_clearance') |
|---|
| 947 | grok.require('waeup.manageStudent') |
|---|
| 948 | grok.template('clearanceeditpage') |
|---|
| 949 | label = _('Manage clearance data') |
|---|
| 950 | deletion_warning = _('Are you sure?') |
|---|
| 951 | pnav = 4 |
|---|
| 952 | |
|---|
| 953 | @property |
|---|
| 954 | def separators(self): |
|---|
| 955 | return getUtility(IStudentsUtils).SEPARATORS_DICT |
|---|
| 956 | |
|---|
| 957 | @property |
|---|
| 958 | def form_fields(self): |
|---|
| 959 | if self.context.is_postgrad: |
|---|
| 960 | form_fields = grok.AutoFields(IPGStudentClearance).omit('clr_code') |
|---|
| 961 | else: |
|---|
| 962 | form_fields = grok.AutoFields(IUGStudentClearance).omit('clr_code') |
|---|
| 963 | return form_fields |
|---|
| 964 | |
|---|
| 965 | @property |
|---|
| 966 | def do_not_render_buttons(self): |
|---|
| 967 | if self.context.state != CLEARANCE: |
|---|
| 968 | return ('Save and request clearance',) |
|---|
| 969 | return () |
|---|
| 970 | |
|---|
| 971 | @action(_('Save'), style='primary') |
|---|
| 972 | def save(self, **data): |
|---|
| 973 | msave(self, **data) |
|---|
| 974 | return |
|---|
| 975 | |
|---|
| 976 | class StudentClearView(UtilityView, grok.View): |
|---|
| 977 | """ Clear student by clearance officer |
|---|
| 978 | """ |
|---|
| 979 | grok.context(IStudent) |
|---|
| 980 | grok.name('clear') |
|---|
| 981 | grok.require('waeup.clearStudent') |
|---|
| 982 | |
|---|
| 983 | def update(self): |
|---|
| 984 | cdm = getUtility(IStudentsUtils).clearance_disabled_message( |
|---|
| 985 | self.context) |
|---|
| 986 | if cdm: |
|---|
| 987 | self.flash(cdm) |
|---|
| 988 | self.redirect(self.url(self.context,'view_clearance')) |
|---|
| 989 | return |
|---|
| 990 | if self.context.state == REQUESTED: |
|---|
| 991 | IWorkflowInfo(self.context).fireTransition('clear') |
|---|
| 992 | self.flash(_('Student has been cleared.')) |
|---|
| 993 | else: |
|---|
| 994 | self.flash(_('Student is in wrong state.'), type="warning") |
|---|
| 995 | self.redirect(self.url(self.context,'view_clearance')) |
|---|
| 996 | return |
|---|
| 997 | |
|---|
| 998 | def render(self): |
|---|
| 999 | return |
|---|
| 1000 | |
|---|
| 1001 | class StudentTempClearancePage(KofaEditFormPage): |
|---|
| 1002 | """ Temporarily clearance by clearance officers. |
|---|
| 1003 | """ |
|---|
| 1004 | grok.context(IStudent) |
|---|
| 1005 | grok.name('temp_clearance') |
|---|
| 1006 | label = _('Clear student temporarily') |
|---|
| 1007 | grok.require('waeup.clearStudent') |
|---|
| 1008 | form_fields = grok.AutoFields( |
|---|
| 1009 | IUGStudentClearance).select('officer_comment') |
|---|
| 1010 | |
|---|
| 1011 | def update(self): |
|---|
| 1012 | cdm = getUtility(IStudentsUtils).clearance_disabled_message( |
|---|
| 1013 | self.context) |
|---|
| 1014 | if cdm: |
|---|
| 1015 | self.flash(cdm, type="warning") |
|---|
| 1016 | self.redirect(self.url(self.context,'view_clearance')) |
|---|
| 1017 | return |
|---|
| 1018 | return super(StudentTempClearancePage, self).update() |
|---|
| 1019 | |
|---|
| 1020 | @action(_('Save comment and clear student temporarily now'), style='primary') |
|---|
| 1021 | def temp_clear(self, **data): |
|---|
| 1022 | if self.context.state == REQUESTED: |
|---|
| 1023 | if self.context.officer_comment \ |
|---|
| 1024 | and self.context.officer_comment.startswith('Temporarily cleared'): |
|---|
| 1025 | self.flash( |
|---|
| 1026 | _('Not allowed: student has already been ' |
|---|
| 1027 | 'temporarily cleared.'), |
|---|
| 1028 | type="warning") |
|---|
| 1029 | self.redirect(self.url(self.context,'view_clearance')) |
|---|
| 1030 | return |
|---|
| 1031 | if not data['officer_comment']: |
|---|
| 1032 | self.flash(_('Please write a comment.'), type="warning") |
|---|
| 1033 | self.redirect(self.url(self.context,'view_clearance')) |
|---|
| 1034 | return |
|---|
| 1035 | message = _('Student has been temporarily cleared.') |
|---|
| 1036 | self.flash(message) |
|---|
| 1037 | else: |
|---|
| 1038 | self.flash(_('Student is in wrong state.'), type="warning") |
|---|
| 1039 | self.redirect(self.url(self.context,'view_clearance')) |
|---|
| 1040 | return |
|---|
| 1041 | user = get_current_principal() |
|---|
| 1042 | if user is None: |
|---|
| 1043 | usertitle = 'system' |
|---|
| 1044 | else: |
|---|
| 1045 | usertitle = getattr(user, 'public_name', None) |
|---|
| 1046 | if not usertitle: |
|---|
| 1047 | usertitle = user.title |
|---|
| 1048 | comment = data['officer_comment'] |
|---|
| 1049 | data['officer_comment'] = translate( |
|---|
| 1050 | _('Temporarily cleared by ${a}. Officer\'s comment:\n${b}', |
|---|
| 1051 | mapping = {'a':usertitle, 'b':comment})) |
|---|
| 1052 | self.applyData(self.context, **data) |
|---|
| 1053 | self.context.writeLogMessage( |
|---|
| 1054 | self, 'comment: %s' % comment.replace('\n', '<br>')) |
|---|
| 1055 | args = {'subject':'You have been temporarily cleared.', 'body':comment} |
|---|
| 1056 | self.redirect(self.url(self.context) + |
|---|
| 1057 | '/contactstudent?%s' % urlencode(args)) |
|---|
| 1058 | return |
|---|
| 1059 | |
|---|
| 1060 | class StudentRejectClearancePage(KofaEditFormPage): |
|---|
| 1061 | """ Reject clearance by clearance officers. |
|---|
| 1062 | """ |
|---|
| 1063 | grok.context(IStudent) |
|---|
| 1064 | grok.name('reject_clearance') |
|---|
| 1065 | label = _('Reject clearance') |
|---|
| 1066 | grok.require('waeup.clearStudent') |
|---|
| 1067 | form_fields = grok.AutoFields( |
|---|
| 1068 | IUGStudentClearance).select('officer_comment') |
|---|
| 1069 | |
|---|
| 1070 | def update(self): |
|---|
| 1071 | cdm = getUtility(IStudentsUtils).clearance_disabled_message( |
|---|
| 1072 | self.context) |
|---|
| 1073 | if cdm: |
|---|
| 1074 | self.flash(cdm, type="warning") |
|---|
| 1075 | self.redirect(self.url(self.context,'view_clearance')) |
|---|
| 1076 | return |
|---|
| 1077 | return super(StudentRejectClearancePage, self).update() |
|---|
| 1078 | |
|---|
| 1079 | @action(_('Save comment and reject clearance now'), style='primary') |
|---|
| 1080 | def reject(self, **data): |
|---|
| 1081 | if self.context.state == CLEARED: |
|---|
| 1082 | IWorkflowInfo(self.context).fireTransition('reset4') |
|---|
| 1083 | message = _('Clearance has been annulled.') |
|---|
| 1084 | self.flash(message, type="warning") |
|---|
| 1085 | elif self.context.state == REQUESTED: |
|---|
| 1086 | IWorkflowInfo(self.context).fireTransition('reset3') |
|---|
| 1087 | message = _('Clearance request has been rejected.') |
|---|
| 1088 | self.flash(message, type="warning") |
|---|
| 1089 | else: |
|---|
| 1090 | self.flash(_('Student is in wrong state.'), type="warning") |
|---|
| 1091 | self.redirect(self.url(self.context,'view_clearance')) |
|---|
| 1092 | return |
|---|
| 1093 | self.applyData(self.context, **data) |
|---|
| 1094 | comment = data['officer_comment'] |
|---|
| 1095 | if comment: |
|---|
| 1096 | self.context.writeLogMessage( |
|---|
| 1097 | self, 'comment: %s' % comment.replace('\n', '<br>')) |
|---|
| 1098 | args = {'subject':message, 'body':comment} |
|---|
| 1099 | else: |
|---|
| 1100 | args = {'subject':message,} |
|---|
| 1101 | self.redirect(self.url(self.context) + |
|---|
| 1102 | '/contactstudent?%s' % urlencode(args)) |
|---|
| 1103 | return |
|---|
| 1104 | |
|---|
| 1105 | class StudentPersonalDisplayFormPage(KofaDisplayFormPage): |
|---|
| 1106 | """ Page to display student personal data |
|---|
| 1107 | """ |
|---|
| 1108 | grok.context(IStudent) |
|---|
| 1109 | grok.name('view_personal') |
|---|
| 1110 | grok.require('waeup.viewStudent') |
|---|
| 1111 | form_fields = grok.AutoFields(IStudentPersonal) |
|---|
| 1112 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
|---|
| 1113 | form_fields[ |
|---|
| 1114 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 1115 | pnav = 4 |
|---|
| 1116 | |
|---|
| 1117 | @property |
|---|
| 1118 | def label(self): |
|---|
| 1119 | return _('${a}: Personal Data', |
|---|
| 1120 | mapping = {'a':self.context.display_fullname}) |
|---|
| 1121 | |
|---|
| 1122 | class StudentPersonalManageFormPage(KofaEditFormPage): |
|---|
| 1123 | """ Page to manage personal data |
|---|
| 1124 | """ |
|---|
| 1125 | grok.context(IStudent) |
|---|
| 1126 | grok.name('manage_personal') |
|---|
| 1127 | grok.require('waeup.manageStudent') |
|---|
| 1128 | form_fields = grok.AutoFields(IStudentPersonal) |
|---|
| 1129 | form_fields['personal_updated'].for_display = True |
|---|
| 1130 | form_fields[ |
|---|
| 1131 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 1132 | label = _('Manage personal data') |
|---|
| 1133 | pnav = 4 |
|---|
| 1134 | |
|---|
| 1135 | @action(_('Save'), style='primary') |
|---|
| 1136 | def save(self, **data): |
|---|
| 1137 | msave(self, **data) |
|---|
| 1138 | return |
|---|
| 1139 | |
|---|
| 1140 | class StudentPersonalEditFormPage(KofaEditFormPage): |
|---|
| 1141 | """ Page to edit personal data |
|---|
| 1142 | """ |
|---|
| 1143 | grok.context(IStudent) |
|---|
| 1144 | grok.name('edit_personal') |
|---|
| 1145 | grok.require('waeup.handleStudent') |
|---|
| 1146 | form_fields = grok.AutoFields(IStudentPersonalEdit).omit('personal_updated') |
|---|
| 1147 | label = _('Edit personal data') |
|---|
| 1148 | pnav = 4 |
|---|
| 1149 | |
|---|
| 1150 | @action(_('Save/Confirm'), style='primary') |
|---|
| 1151 | def save(self, **data): |
|---|
| 1152 | msave(self, **data) |
|---|
| 1153 | self.context.personal_updated = datetime.utcnow() |
|---|
| 1154 | return |
|---|
| 1155 | |
|---|
| 1156 | class StudyCourseDisplayFormPage(KofaDisplayFormPage): |
|---|
| 1157 | """ Page to display the student study course data |
|---|
| 1158 | """ |
|---|
| 1159 | grok.context(IStudentStudyCourse) |
|---|
| 1160 | grok.name('index') |
|---|
| 1161 | grok.require('waeup.viewStudent') |
|---|
| 1162 | grok.template('studycoursepage') |
|---|
| 1163 | pnav = 4 |
|---|
| 1164 | |
|---|
| 1165 | @property |
|---|
| 1166 | def form_fields(self): |
|---|
| 1167 | if self.context.is_postgrad: |
|---|
| 1168 | form_fields = grok.AutoFields(IStudentStudyCourse).omit( |
|---|
| 1169 | 'previous_verdict') |
|---|
| 1170 | else: |
|---|
| 1171 | form_fields = grok.AutoFields(IStudentStudyCourse) |
|---|
| 1172 | return form_fields |
|---|
| 1173 | |
|---|
| 1174 | @property |
|---|
| 1175 | def label(self): |
|---|
| 1176 | if self.context.is_current: |
|---|
| 1177 | return _('${a}: Study Course', |
|---|
| 1178 | mapping = {'a':self.context.__parent__.display_fullname}) |
|---|
| 1179 | else: |
|---|
| 1180 | return _('${a}: Previous Study Course', |
|---|
| 1181 | mapping = {'a':self.context.__parent__.display_fullname}) |
|---|
| 1182 | |
|---|
| 1183 | @property |
|---|
| 1184 | def current_mode(self): |
|---|
| 1185 | if self.context.certificate is not None: |
|---|
| 1186 | studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
|---|
| 1187 | return studymodes_dict[self.context.certificate.study_mode] |
|---|
| 1188 | return |
|---|
| 1189 | |
|---|
| 1190 | @property |
|---|
| 1191 | def department(self): |
|---|
| 1192 | try: |
|---|
| 1193 | if self.context.certificate is not None: |
|---|
| 1194 | return self.context.certificate.__parent__.__parent__ |
|---|
| 1195 | except AttributeError: |
|---|
| 1196 | # handle_certificate_removed does only clear |
|---|
| 1197 | # studycourses with certificate code 'studycourse' but not |
|---|
| 1198 | # 'studycourse_1' or 'studycourse_2'. These certificates do |
|---|
| 1199 | # still exist but have no parents. |
|---|
| 1200 | pass |
|---|
| 1201 | return |
|---|
| 1202 | |
|---|
| 1203 | @property |
|---|
| 1204 | def faculty(self): |
|---|
| 1205 | try: |
|---|
| 1206 | if self.context.certificate is not None: |
|---|
| 1207 | return self.context.certificate.__parent__.__parent__.__parent__ |
|---|
| 1208 | except AttributeError: |
|---|
| 1209 | # handle_certificate_removed does only clear |
|---|
| 1210 | # studycourses with certificate code 'studycourse' but not |
|---|
| 1211 | # 'studycourse_1' or 'studycourse_2'. These certificates do |
|---|
| 1212 | # still exist but have no parents. |
|---|
| 1213 | pass |
|---|
| 1214 | return |
|---|
| 1215 | |
|---|
| 1216 | @property |
|---|
| 1217 | def prev_studycourses(self): |
|---|
| 1218 | if self.context.is_current: |
|---|
| 1219 | if self.context.__parent__.get('studycourse_2', None) is not None: |
|---|
| 1220 | return ( |
|---|
| 1221 | {'href':self.url(self.context.student) + '/studycourse_1', |
|---|
| 1222 | 'title':_('First Study Course, ')}, |
|---|
| 1223 | {'href':self.url(self.context.student) + '/studycourse_2', |
|---|
| 1224 | 'title':_('Second Study Course')} |
|---|
| 1225 | ) |
|---|
| 1226 | if self.context.__parent__.get('studycourse_1', None) is not None: |
|---|
| 1227 | return ( |
|---|
| 1228 | {'href':self.url(self.context.student) + '/studycourse_1', |
|---|
| 1229 | 'title':_('First Study Course')}, |
|---|
| 1230 | ) |
|---|
| 1231 | return |
|---|
| 1232 | |
|---|
| 1233 | class StudyCourseManageFormPage(KofaEditFormPage): |
|---|
| 1234 | """ Page to edit the student study course data |
|---|
| 1235 | """ |
|---|
| 1236 | grok.context(IStudentStudyCourse) |
|---|
| 1237 | grok.name('manage') |
|---|
| 1238 | grok.require('waeup.manageStudent') |
|---|
| 1239 | grok.template('studycoursemanagepage') |
|---|
| 1240 | label = _('Manage study course') |
|---|
| 1241 | pnav = 4 |
|---|
| 1242 | taboneactions = [_('Save'),_('Cancel')] |
|---|
| 1243 | tabtwoactions = [_('Remove selected levels'),_('Cancel')] |
|---|
| 1244 | tabthreeactions = [_('Add study level')] |
|---|
| 1245 | |
|---|
| 1246 | @property |
|---|
| 1247 | def form_fields(self): |
|---|
| 1248 | if self.context.is_postgrad: |
|---|
| 1249 | form_fields = grok.AutoFields(IStudentStudyCourse).omit( |
|---|
| 1250 | 'previous_verdict') |
|---|
| 1251 | else: |
|---|
| 1252 | form_fields = grok.AutoFields(IStudentStudyCourse) |
|---|
| 1253 | return form_fields |
|---|
| 1254 | |
|---|
| 1255 | def update(self): |
|---|
| 1256 | if not self.context.is_current \ |
|---|
| 1257 | or self.context.student.studycourse_locked: |
|---|
| 1258 | emit_lock_message(self) |
|---|
| 1259 | return |
|---|
| 1260 | super(StudyCourseManageFormPage, self).update() |
|---|
| 1261 | return |
|---|
| 1262 | |
|---|
| 1263 | @action(_('Save'), style='primary') |
|---|
| 1264 | def save(self, **data): |
|---|
| 1265 | try: |
|---|
| 1266 | msave(self, **data) |
|---|
| 1267 | except ConstraintNotSatisfied: |
|---|
| 1268 | # The selected level might not exist in certificate |
|---|
| 1269 | self.flash(_('Current level not available for certificate.'), |
|---|
| 1270 | type="warning") |
|---|
| 1271 | return |
|---|
| 1272 | notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
|---|
| 1273 | return |
|---|
| 1274 | |
|---|
| 1275 | @property |
|---|
| 1276 | def level_dicts(self): |
|---|
| 1277 | studylevelsource = StudyLevelSource().factory |
|---|
| 1278 | for code in studylevelsource.getValues(self.context): |
|---|
| 1279 | title = studylevelsource.getTitle(self.context, code) |
|---|
| 1280 | yield(dict(code=code, title=title)) |
|---|
| 1281 | |
|---|
| 1282 | @property |
|---|
| 1283 | def session_dicts(self): |
|---|
| 1284 | yield(dict(code='', title='--')) |
|---|
| 1285 | for item in academic_sessions(): |
|---|
| 1286 | code = item[1] |
|---|
| 1287 | title = item[0] |
|---|
| 1288 | yield(dict(code=code, title=title)) |
|---|
| 1289 | |
|---|
| 1290 | @action(_('Add study level'), style='primary') |
|---|
| 1291 | def addStudyLevel(self, **data): |
|---|
| 1292 | level_code = self.request.form.get('addlevel', None) |
|---|
| 1293 | level_session = self.request.form.get('level_session', None) |
|---|
| 1294 | if not level_session and not level_code == '0': |
|---|
| 1295 | self.flash(_('You must select a session for the level.'), |
|---|
| 1296 | type="warning") |
|---|
| 1297 | self.redirect(self.url(self.context, u'@@manage')+'#tab2') |
|---|
| 1298 | return |
|---|
| 1299 | if level_session and level_code == '0': |
|---|
| 1300 | self.flash(_('Level zero must not be assigned a session.'), |
|---|
| 1301 | type="warning") |
|---|
| 1302 | self.redirect(self.url(self.context, u'@@manage')+'#tab2') |
|---|
| 1303 | return |
|---|
| 1304 | studylevel = createObject(u'waeup.StudentStudyLevel') |
|---|
| 1305 | studylevel.level = int(level_code) |
|---|
| 1306 | if level_code != '0': |
|---|
| 1307 | studylevel.level_session = int(level_session) |
|---|
| 1308 | try: |
|---|
| 1309 | self.context.addStudentStudyLevel( |
|---|
| 1310 | self.context.certificate,studylevel) |
|---|
| 1311 | self.flash(_('Study level has been added.')) |
|---|
| 1312 | except KeyError: |
|---|
| 1313 | self.flash(_('This level exists.'), type="warning") |
|---|
| 1314 | self.redirect(self.url(self.context, u'@@manage')+'#tab2') |
|---|
| 1315 | return |
|---|
| 1316 | |
|---|
| 1317 | @jsaction(_('Remove selected levels')) |
|---|
| 1318 | def delStudyLevels(self, **data): |
|---|
| 1319 | form = self.request.form |
|---|
| 1320 | if 'val_id' in form: |
|---|
| 1321 | child_id = form['val_id'] |
|---|
| 1322 | else: |
|---|
| 1323 | self.flash(_('No study level selected.'), type="warning") |
|---|
| 1324 | self.redirect(self.url(self.context, '@@manage')+'#tab2') |
|---|
| 1325 | return |
|---|
| 1326 | if not isinstance(child_id, list): |
|---|
| 1327 | child_id = [child_id] |
|---|
| 1328 | deleted = [] |
|---|
| 1329 | for id in child_id: |
|---|
| 1330 | del self.context[id] |
|---|
| 1331 | deleted.append(id) |
|---|
| 1332 | if len(deleted): |
|---|
| 1333 | self.flash(_('Successfully removed: ${a}', |
|---|
| 1334 | mapping = {'a':', '.join(deleted)})) |
|---|
| 1335 | self.context.writeLogMessage( |
|---|
| 1336 | self,'removed: %s' % ', '.join(deleted)) |
|---|
| 1337 | self.redirect(self.url(self.context, u'@@manage')+'#tab2') |
|---|
| 1338 | return |
|---|
| 1339 | |
|---|
| 1340 | class StudentTranscriptRequestPage(KofaPage): |
|---|
| 1341 | """ Page to request transcript by student |
|---|
| 1342 | """ |
|---|
| 1343 | grok.context(IStudent) |
|---|
| 1344 | grok.name('request_transcript') |
|---|
| 1345 | grok.require('waeup.handleStudent') |
|---|
| 1346 | grok.template('transcriptrequest') |
|---|
| 1347 | label = _('Request transcript') |
|---|
| 1348 | ac_prefix = 'TSC' |
|---|
| 1349 | notice = '' |
|---|
| 1350 | pnav = 4 |
|---|
| 1351 | buttonname = _('Request now') |
|---|
| 1352 | with_ac = True |
|---|
| 1353 | |
|---|
| 1354 | def update(self, SUBMIT=None): |
|---|
| 1355 | super(StudentTranscriptRequestPage, self).update() |
|---|
| 1356 | if not self.context.state == GRADUATED: |
|---|
| 1357 | self.flash(_("Wrong state"), type="danger") |
|---|
| 1358 | self.redirect(self.url(self.context)) |
|---|
| 1359 | return |
|---|
| 1360 | if self.with_ac: |
|---|
| 1361 | self.ac_series = self.request.form.get('ac_series', None) |
|---|
| 1362 | self.ac_number = self.request.form.get('ac_number', None) |
|---|
| 1363 | if getattr( |
|---|
| 1364 | self.context['studycourse'], 'transcript_comment', None) is not None: |
|---|
| 1365 | self.correspondence = self.context[ |
|---|
| 1366 | 'studycourse'].transcript_comment.replace( |
|---|
| 1367 | '\n', '<br>') |
|---|
| 1368 | else: |
|---|
| 1369 | self.correspondence = '' |
|---|
| 1370 | if SUBMIT is None: |
|---|
| 1371 | return |
|---|
| 1372 | if self.with_ac: |
|---|
| 1373 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
|---|
| 1374 | code = get_access_code(pin) |
|---|
| 1375 | if not code: |
|---|
| 1376 | self.flash(_('Activation code is invalid.'), type="warning") |
|---|
| 1377 | return |
|---|
| 1378 | if code.state == USED: |
|---|
| 1379 | self.flash(_('Activation code has already been used.'), |
|---|
| 1380 | type="warning") |
|---|
| 1381 | return |
|---|
| 1382 | # Mark pin as used (this also fires a pin related transition) |
|---|
| 1383 | # and fire transition request_transcript |
|---|
| 1384 | comment = _(u"invalidated") |
|---|
| 1385 | # Here we know that the ac is in state initialized so we do not |
|---|
| 1386 | # expect an exception, but the owner might be different |
|---|
| 1387 | if not invalidate_accesscode(pin, comment, self.context.student_id): |
|---|
| 1388 | self.flash(_('You are not the owner of this access code.'), |
|---|
| 1389 | type="warning") |
|---|
| 1390 | return |
|---|
| 1391 | self.context.clr_code = pin |
|---|
| 1392 | IWorkflowInfo(self.context).fireTransition('request_transcript') |
|---|
| 1393 | comment = self.request.form.get('comment', '').replace('\r', '') |
|---|
| 1394 | address = self.request.form.get('address', '').replace('\r', '') |
|---|
| 1395 | tz = getattr(queryUtility(IKofaUtils), 'tzinfo', pytz.utc) |
|---|
| 1396 | today = now(tz).strftime('%d/%m/%Y %H:%M:%S %Z') |
|---|
| 1397 | old_transcript_comment = getattr( |
|---|
| 1398 | self.context['studycourse'], 'transcript_comment', None) |
|---|
| 1399 | if old_transcript_comment == None: |
|---|
| 1400 | old_transcript_comment = '' |
|---|
| 1401 | self.context['studycourse'].transcript_comment = '''On %s %s wrote: |
|---|
| 1402 | |
|---|
| 1403 | %s |
|---|
| 1404 | |
|---|
| 1405 | Dispatch Address: |
|---|
| 1406 | %s |
|---|
| 1407 | |
|---|
| 1408 | %s''' % (today, self.request.principal.id, comment, address, |
|---|
| 1409 | old_transcript_comment) |
|---|
| 1410 | self.context.writeLogMessage( |
|---|
| 1411 | self, 'comment: %s' % comment.replace('\n', '<br>')) |
|---|
| 1412 | self.flash(_('Transcript processing has been started.')) |
|---|
| 1413 | self.redirect(self.url(self.context)) |
|---|
| 1414 | return |
|---|
| 1415 | |
|---|
| 1416 | class TOStudentTranscriptRequestPage(StudentTranscriptRequestPage): |
|---|
| 1417 | """ Page to request transcript by student |
|---|
| 1418 | """ |
|---|
| 1419 | grok.context(IStudent) |
|---|
| 1420 | grok.name('request_transcript_for_student') |
|---|
| 1421 | grok.require('waeup.processTranscript') |
|---|
| 1422 | grok.template('transcriptrequest') |
|---|
| 1423 | label = _('Request transcript for student') |
|---|
| 1424 | with_ac = False |
|---|
| 1425 | |
|---|
| 1426 | class StudentTranscriptSignView(UtilityView, grok.View): |
|---|
| 1427 | """ View to sign transcript |
|---|
| 1428 | """ |
|---|
| 1429 | grok.context(IStudentStudyCourse) |
|---|
| 1430 | grok.name('sign_transcript') |
|---|
| 1431 | grok.require('waeup.signTranscript') |
|---|
| 1432 | |
|---|
| 1433 | def update(self, SUBMIT=None): |
|---|
| 1434 | if self.context.student.state != TRANSVAL: |
|---|
| 1435 | self.flash(_('Student is in wrong state.'), type="warning") |
|---|
| 1436 | self.redirect(self.url(self.context)) |
|---|
| 1437 | return |
|---|
| 1438 | prev_transcript_signees = getattr( |
|---|
| 1439 | self.context, 'transcript_signees', None) |
|---|
| 1440 | if prev_transcript_signees \ |
|---|
| 1441 | and '(%s)' % self.request.principal.id in prev_transcript_signees: |
|---|
| 1442 | self.flash(_('You have already signed this transcript.'), |
|---|
| 1443 | type="warning") |
|---|
| 1444 | self.redirect(self.url(self.context) + '/transcript') |
|---|
| 1445 | return |
|---|
| 1446 | self.flash(_('Transcript signed.')) |
|---|
| 1447 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
|---|
| 1448 | self.context.student.__parent__.logger.info( |
|---|
| 1449 | '%s - %s - Transcript signed' |
|---|
| 1450 | % (ob_class, self.context.student.student_id)) |
|---|
| 1451 | self.context.student.history.addMessage('Transcript signed') |
|---|
| 1452 | tz = getattr(queryUtility(IKofaUtils), 'tzinfo', pytz.utc) |
|---|
| 1453 | today = now(tz).strftime('%d/%m/%Y %H:%M:%S %Z') |
|---|
| 1454 | if prev_transcript_signees == None: |
|---|
| 1455 | prev_transcript_signees = '' |
|---|
| 1456 | self.context.transcript_signees = ( |
|---|
| 1457 | u"Electronically signed by %s (%s) on %s\n%s" |
|---|
| 1458 | % (self.request.principal.title, self.request.principal.id, today, |
|---|
| 1459 | prev_transcript_signees)) |
|---|
| 1460 | self.redirect(self.url(self.context) + '/transcript') |
|---|
| 1461 | return |
|---|
| 1462 | |
|---|
| 1463 | def render(self): |
|---|
| 1464 | return |
|---|
| 1465 | |
|---|
| 1466 | class StudentTranscriptValidateFormPage(KofaEditFormPage): |
|---|
| 1467 | """ Page to validate transcript |
|---|
| 1468 | """ |
|---|
| 1469 | grok.context(IStudentStudyCourse) |
|---|
| 1470 | grok.name('validate_transcript') |
|---|
| 1471 | grok.require('waeup.processTranscript') |
|---|
| 1472 | grok.template('transcriptprocess') |
|---|
| 1473 | label = _('Validate transcript') |
|---|
| 1474 | buttonname1 = _('Save comment') |
|---|
| 1475 | buttonname2 = _('Save comment and validate transcript') |
|---|
| 1476 | pnav = 4 |
|---|
| 1477 | |
|---|
| 1478 | @property |
|---|
| 1479 | def remarks(self): |
|---|
| 1480 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 1481 | levelremarks = '' |
|---|
| 1482 | studylevelsource = StudyLevelSource().factory |
|---|
| 1483 | for studylevel in self.context.values(): |
|---|
| 1484 | leveltitle = studylevelsource.getTitle( |
|---|
| 1485 | self.context, studylevel.level) |
|---|
| 1486 | url = self.url(self.context) + '/%s/remark' % studylevel.level |
|---|
| 1487 | button_title = translate( |
|---|
| 1488 | _('Edit'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1489 | levelremarks += ( |
|---|
| 1490 | '<tr>' |
|---|
| 1491 | '<td>%s:</td>' |
|---|
| 1492 | '<td>%s</td> ' |
|---|
| 1493 | '<td><a class="btn btn-primary btn-xs" href="%s">%s</a></td>' |
|---|
| 1494 | '</tr>' |
|---|
| 1495 | ) % ( |
|---|
| 1496 | leveltitle, studylevel.transcript_remark, url, button_title) |
|---|
| 1497 | return levelremarks |
|---|
| 1498 | |
|---|
| 1499 | def update(self, SUBMIT=None, SAVE=None): |
|---|
| 1500 | super(StudentTranscriptValidateFormPage, self).update() |
|---|
| 1501 | if self.context.student.state != TRANSREQ: |
|---|
| 1502 | self.flash(_('Student is in wrong state.'), type="warning") |
|---|
| 1503 | self.redirect(self.url(self.context)) |
|---|
| 1504 | return |
|---|
| 1505 | if getattr(self.context, 'transcript_comment', None) is not None: |
|---|
| 1506 | self.correspondence = self.context.transcript_comment.replace( |
|---|
| 1507 | '\n', '<br>') |
|---|
| 1508 | else: |
|---|
| 1509 | self.correspondence = '' |
|---|
| 1510 | if getattr(self.context, 'transcript_signees', None) is not None: |
|---|
| 1511 | self.signees = self.context.transcript_signees.replace( |
|---|
| 1512 | '\n', '<br><br>') |
|---|
| 1513 | else: |
|---|
| 1514 | self.signees = '' |
|---|
| 1515 | if SUBMIT is None and SAVE is None: |
|---|
| 1516 | return |
|---|
| 1517 | if SAVE or SUBMIT: |
|---|
| 1518 | # Save comment and append old comment |
|---|
| 1519 | comment = self.request.form.get('comment', '').replace('\r', '') |
|---|
| 1520 | tz = getattr(queryUtility(IKofaUtils), 'tzinfo', pytz.utc) |
|---|
| 1521 | today = now(tz).strftime('%d/%m/%Y %H:%M:%S %Z') |
|---|
| 1522 | old_transcript_comment = getattr( |
|---|
| 1523 | self.context, 'transcript_comment', None) |
|---|
| 1524 | if old_transcript_comment == None: |
|---|
| 1525 | old_transcript_comment = '' |
|---|
| 1526 | self.context.transcript_comment = '''On %s %s wrote: |
|---|
| 1527 | |
|---|
| 1528 | %s |
|---|
| 1529 | |
|---|
| 1530 | %s''' % (today, self.request.principal.id, comment, old_transcript_comment) |
|---|
| 1531 | self.context.writeLogMessage( |
|---|
| 1532 | self, 'comment: %s' % comment.replace('\n', '<br>')) |
|---|
| 1533 | if SUBMIT: |
|---|
| 1534 | # Fire transition |
|---|
| 1535 | IWorkflowInfo(self.context.student).fireTransition('validate_transcript') |
|---|
| 1536 | self.flash(_('Transcript validated.')) |
|---|
| 1537 | self.redirect(self.url(self.context) + '/transcript') |
|---|
| 1538 | return |
|---|
| 1539 | |
|---|
| 1540 | class StudentTranscriptReleaseFormPage(KofaEditFormPage): |
|---|
| 1541 | """ Page to release transcript |
|---|
| 1542 | """ |
|---|
| 1543 | grok.context(IStudentStudyCourse) |
|---|
| 1544 | grok.name('release_transcript') |
|---|
| 1545 | grok.require('waeup.processTranscript') |
|---|
| 1546 | grok.template('transcriptprocess') |
|---|
| 1547 | label = _('Release transcript') |
|---|
| 1548 | buttonname1 = None |
|---|
| 1549 | buttonname2 = _('Save comment and release transcript') |
|---|
| 1550 | pnav = 4 |
|---|
| 1551 | |
|---|
| 1552 | @property |
|---|
| 1553 | def remarks(self): |
|---|
| 1554 | levelremarks = '' |
|---|
| 1555 | studylevelsource = StudyLevelSource().factory |
|---|
| 1556 | for studylevel in self.context.values(): |
|---|
| 1557 | leveltitle = studylevelsource.getTitle( |
|---|
| 1558 | self.context, studylevel.level) |
|---|
| 1559 | levelremarks += "%s: %s <br><br>" % ( |
|---|
| 1560 | leveltitle, studylevel.transcript_remark) |
|---|
| 1561 | return levelremarks |
|---|
| 1562 | |
|---|
| 1563 | def update(self, SUBMIT=None): |
|---|
| 1564 | super(StudentTranscriptReleaseFormPage, self).update() |
|---|
| 1565 | if self.context.student.state != TRANSVAL: |
|---|
| 1566 | self.flash(_('Student is in wrong state.'), type="warning") |
|---|
| 1567 | self.redirect(self.url(self.context)) |
|---|
| 1568 | return |
|---|
| 1569 | if getattr(self.context, 'transcript_comment', None) is not None: |
|---|
| 1570 | self.correspondence = self.context.transcript_comment.replace( |
|---|
| 1571 | '\n', '<br>') |
|---|
| 1572 | else: |
|---|
| 1573 | self.correspondence = '' |
|---|
| 1574 | if getattr(self.context, 'transcript_signees', None) is not None: |
|---|
| 1575 | self.signees = self.context.transcript_signees.replace( |
|---|
| 1576 | '\n', '<br><br>') |
|---|
| 1577 | else: |
|---|
| 1578 | self.signees = '' |
|---|
| 1579 | if SUBMIT is None: |
|---|
| 1580 | return |
|---|
| 1581 | # Fire transition |
|---|
| 1582 | IWorkflowInfo(self.context.student).fireTransition('release_transcript') |
|---|
| 1583 | self.flash(_('Transcript released and final transcript file saved.')) |
|---|
| 1584 | comment = self.request.form.get('comment', '').replace('\r', '') |
|---|
| 1585 | tz = getattr(queryUtility(IKofaUtils), 'tzinfo', pytz.utc) |
|---|
| 1586 | today = now(tz).strftime('%d/%m/%Y %H:%M:%S %Z') |
|---|
| 1587 | old_transcript_comment = getattr( |
|---|
| 1588 | self.context, 'transcript_comment', None) |
|---|
| 1589 | if old_transcript_comment == None: |
|---|
| 1590 | old_transcript_comment = '' |
|---|
| 1591 | self.context.transcript_comment = '''On %s %s wrote: |
|---|
| 1592 | |
|---|
| 1593 | %s |
|---|
| 1594 | |
|---|
| 1595 | %s''' % (today, self.request.principal.id, comment, |
|---|
| 1596 | old_transcript_comment) |
|---|
| 1597 | self.context.writeLogMessage( |
|---|
| 1598 | self, 'comment: %s' % comment.replace('\n', '<br>')) |
|---|
| 1599 | # Produce transcript file |
|---|
| 1600 | self.redirect(self.url(self.context) + '/transcript.pdf') |
|---|
| 1601 | return |
|---|
| 1602 | |
|---|
| 1603 | class StudyCourseTranscriptPage(KofaDisplayFormPage): |
|---|
| 1604 | """ Page to display the student's transcript. |
|---|
| 1605 | """ |
|---|
| 1606 | grok.context(IStudentStudyCourse) |
|---|
| 1607 | grok.name('transcript') |
|---|
| 1608 | grok.require('waeup.viewTranscript') |
|---|
| 1609 | grok.template('transcript') |
|---|
| 1610 | pnav = 4 |
|---|
| 1611 | |
|---|
| 1612 | def format_float(self, value, prec): |
|---|
| 1613 | format_float = getUtility(IKofaUtils).format_float |
|---|
| 1614 | return format_float(value, prec) |
|---|
| 1615 | |
|---|
| 1616 | def update(self): |
|---|
| 1617 | final_slip = getUtility(IExtFileStore).getFileByContext( |
|---|
| 1618 | self.context.student, attr='final_transcript') |
|---|
| 1619 | if not self.context.student.transcript_enabled or final_slip: |
|---|
| 1620 | self.flash(_('Forbidden!'), type="warning") |
|---|
| 1621 | self.redirect(self.url(self.context)) |
|---|
| 1622 | return |
|---|
| 1623 | self.tdata = self.context.getTranscriptData() |
|---|
| 1624 | #if not self.tdata[1]: |
|---|
| 1625 | # self.flash(_('No results yet!'), type="warning") |
|---|
| 1626 | # self.redirect(self.url(self.context)) |
|---|
| 1627 | # return |
|---|
| 1628 | super(StudyCourseTranscriptPage, self).update() |
|---|
| 1629 | self.semester_dict = getUtility(IKofaUtils).SEMESTER_DICT |
|---|
| 1630 | self.level_dict = level_dict(self.context) |
|---|
| 1631 | self.session_dict = dict([(None, 'None'),] + |
|---|
| 1632 | [(item[1], item[0]) for item in academic_sessions()]) |
|---|
| 1633 | self.studymode_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
|---|
| 1634 | return |
|---|
| 1635 | |
|---|
| 1636 | @property |
|---|
| 1637 | def label(self): |
|---|
| 1638 | # Here we know that the cookie has been set |
|---|
| 1639 | return _('${a}: Transcript Data', mapping = { |
|---|
| 1640 | 'a':self.context.student.display_fullname}) |
|---|
| 1641 | |
|---|
| 1642 | class ExportPDFTranscriptSlip(UtilityView, grok.View): |
|---|
| 1643 | """Deliver a PDF slip of the context. |
|---|
| 1644 | """ |
|---|
| 1645 | grok.context(IStudentStudyCourse) |
|---|
| 1646 | grok.name('transcript.pdf') |
|---|
| 1647 | grok.require('waeup.downloadTranscript') |
|---|
| 1648 | prefix = 'form' |
|---|
| 1649 | omit_fields = ( |
|---|
| 1650 | 'department', 'faculty', 'current_mode', 'entry_session', 'certificate', |
|---|
| 1651 | 'password', 'suspended', 'phone', 'email', 'parents_email', |
|---|
| 1652 | 'adm_code', 'suspended_comment', 'current_level', 'flash_notice') |
|---|
| 1653 | |
|---|
| 1654 | def update(self): |
|---|
| 1655 | final_slip = getUtility(IExtFileStore).getFileByContext( |
|---|
| 1656 | self.context.student, attr='final_transcript') |
|---|
| 1657 | if not self.context.student.transcript_enabled \ |
|---|
| 1658 | or final_slip: |
|---|
| 1659 | self.flash(_('Forbidden!'), type="warning") |
|---|
| 1660 | self.redirect(self.url(self.context)) |
|---|
| 1661 | return |
|---|
| 1662 | tdata = self.context.getTranscriptData() |
|---|
| 1663 | #if not tdata[1]: |
|---|
| 1664 | # self.flash(_('No results yet!'), type="warning") |
|---|
| 1665 | # self.redirect(self.url(self.context)) |
|---|
| 1666 | # return |
|---|
| 1667 | super(ExportPDFTranscriptSlip, self).update() |
|---|
| 1668 | self.semester_dict = getUtility(IKofaUtils).SEMESTER_DICT |
|---|
| 1669 | self.level_dict = level_dict(self.context) |
|---|
| 1670 | self.session_dict = dict([(None, 'None'),] + |
|---|
| 1671 | [(item[1], item[0]) for item in academic_sessions()]) |
|---|
| 1672 | self.studymode_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
|---|
| 1673 | self.verdict_dict = getUtility(IKofaUtils).VERDICTS_DICT |
|---|
| 1674 | return |
|---|
| 1675 | |
|---|
| 1676 | @property |
|---|
| 1677 | def label(self): |
|---|
| 1678 | # Here we know that the cookie has been set |
|---|
| 1679 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 1680 | return translate(_('Academic Transcript'), |
|---|
| 1681 | 'waeup.kofa', target_language=portal_language) |
|---|
| 1682 | |
|---|
| 1683 | def _sigsInFooter(self): |
|---|
| 1684 | if getattr( |
|---|
| 1685 | self.context.student['studycourse'], 'transcript_signees', None): |
|---|
| 1686 | return () |
|---|
| 1687 | return (_('CERTIFIED TRUE COPY'),) |
|---|
| 1688 | |
|---|
| 1689 | def _signatures(self): |
|---|
| 1690 | return () |
|---|
| 1691 | |
|---|
| 1692 | def _digital_sigs(self): |
|---|
| 1693 | if getattr( |
|---|
| 1694 | self.context.student['studycourse'], 'transcript_signees', None): |
|---|
| 1695 | return self.context.student['studycourse'].transcript_signees |
|---|
| 1696 | return () |
|---|
| 1697 | |
|---|
| 1698 | def _save_file(self): |
|---|
| 1699 | if self.context.student.state == TRANSREL: |
|---|
| 1700 | return True |
|---|
| 1701 | return False |
|---|
| 1702 | |
|---|
| 1703 | def render(self): |
|---|
| 1704 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 1705 | Term = translate(_('Term'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1706 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1707 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1708 | Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1709 | Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1710 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1711 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 1712 | self.request, self.omit_fields) |
|---|
| 1713 | students_utils = getUtility(IStudentsUtils) |
|---|
| 1714 | |
|---|
| 1715 | tableheader = [(Code,'code', 2.5), |
|---|
| 1716 | (Title,'title', 7), |
|---|
| 1717 | (Term, 'semester', 1.5), |
|---|
| 1718 | (Cred, 'credits', 1.5), |
|---|
| 1719 | (Score, 'total_score', 1.5), |
|---|
| 1720 | (Grade, 'grade', 1.5), |
|---|
| 1721 | ] |
|---|
| 1722 | |
|---|
| 1723 | pdfstream = students_utils.renderPDFTranscript( |
|---|
| 1724 | self, 'transcript_%s.pdf' % self.context.student.student_id, |
|---|
| 1725 | self.context.student, studentview, |
|---|
| 1726 | omit_fields=self.omit_fields, |
|---|
| 1727 | tableheader=tableheader, |
|---|
| 1728 | signatures=self._signatures(), |
|---|
| 1729 | sigs_in_footer=self._sigsInFooter(), |
|---|
| 1730 | digital_sigs=self._digital_sigs(), |
|---|
| 1731 | save_file=self._save_file(), |
|---|
| 1732 | ) |
|---|
| 1733 | if not pdfstream: |
|---|
| 1734 | self.redirect(self.url(self.context.student)) |
|---|
| 1735 | return |
|---|
| 1736 | return pdfstream |
|---|
| 1737 | |
|---|
| 1738 | class StudentTransferFormPage(KofaAddFormPage): |
|---|
| 1739 | """Page to transfer the student. |
|---|
| 1740 | """ |
|---|
| 1741 | grok.context(IStudent) |
|---|
| 1742 | grok.name('transfer') |
|---|
| 1743 | grok.require('waeup.manageStudent') |
|---|
| 1744 | label = _('Transfer student') |
|---|
| 1745 | form_fields = grok.AutoFields(IStudentStudyCourseTransfer).omit( |
|---|
| 1746 | 'entry_mode', 'entry_session') |
|---|
| 1747 | pnav = 4 |
|---|
| 1748 | |
|---|
| 1749 | @jsaction(_('Transfer')) |
|---|
| 1750 | def transferStudent(self, **data): |
|---|
| 1751 | error = self.context.transfer(**data) |
|---|
| 1752 | if error == -1: |
|---|
| 1753 | self.flash(_('Current level does not match certificate levels.'), |
|---|
| 1754 | type="warning") |
|---|
| 1755 | elif error == -2: |
|---|
| 1756 | self.flash(_('Former study course record incomplete.'), |
|---|
| 1757 | type="warning") |
|---|
| 1758 | elif error == -3: |
|---|
| 1759 | self.flash(_('Maximum number of transfers exceeded.'), |
|---|
| 1760 | type="warning") |
|---|
| 1761 | else: |
|---|
| 1762 | self.flash(_('Successfully transferred.')) |
|---|
| 1763 | return |
|---|
| 1764 | |
|---|
| 1765 | class RevertTransferFormPage(KofaEditFormPage): |
|---|
| 1766 | """View that reverts the previous transfer. |
|---|
| 1767 | """ |
|---|
| 1768 | grok.context(IStudent) |
|---|
| 1769 | grok.name('revert_transfer') |
|---|
| 1770 | grok.require('waeup.manageStudent') |
|---|
| 1771 | grok.template('reverttransfer') |
|---|
| 1772 | label = _('Revert previous transfer') |
|---|
| 1773 | |
|---|
| 1774 | def update(self): |
|---|
| 1775 | if not self.context.has_key('studycourse_1'): |
|---|
| 1776 | self.flash(_('No previous transfer.'), type="warning") |
|---|
| 1777 | self.redirect(self.url(self.context)) |
|---|
| 1778 | return |
|---|
| 1779 | return |
|---|
| 1780 | |
|---|
| 1781 | @jsaction(_('Revert now')) |
|---|
| 1782 | def transferStudent(self, **data): |
|---|
| 1783 | self.context.revert_transfer() |
|---|
| 1784 | self.flash(_('Previous transfer reverted.')) |
|---|
| 1785 | self.redirect(self.url(self.context, 'studycourse')) |
|---|
| 1786 | return |
|---|
| 1787 | |
|---|
| 1788 | class StudyLevelDisplayFormPage(KofaDisplayFormPage): |
|---|
| 1789 | """ Page to display student study levels |
|---|
| 1790 | """ |
|---|
| 1791 | grok.context(IStudentStudyLevel) |
|---|
| 1792 | grok.name('index') |
|---|
| 1793 | grok.require('waeup.viewStudent') |
|---|
| 1794 | form_fields = grok.AutoFields(IStudentStudyLevel).omit('level') |
|---|
| 1795 | form_fields[ |
|---|
| 1796 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 1797 | grok.template('studylevelpage') |
|---|
| 1798 | pnav = 4 |
|---|
| 1799 | |
|---|
| 1800 | def update(self): |
|---|
| 1801 | super(StudyLevelDisplayFormPage, self).update() |
|---|
| 1802 | if self.context.level == 0: |
|---|
| 1803 | self.form_fields = self.form_fields.omit('gpa') |
|---|
| 1804 | return |
|---|
| 1805 | |
|---|
| 1806 | @property |
|---|
| 1807 | def translated_values(self): |
|---|
| 1808 | return translated_values(self) |
|---|
| 1809 | |
|---|
| 1810 | @property |
|---|
| 1811 | def label(self): |
|---|
| 1812 | # Here we know that the cookie has been set |
|---|
| 1813 | lang = self.request.cookies.get('kofa.language') |
|---|
| 1814 | level_title = translate(self.context.level_title, 'waeup.kofa', |
|---|
| 1815 | target_language=lang) |
|---|
| 1816 | return _('${a}: ${b}', mapping = { |
|---|
| 1817 | 'a':self.context.student.display_fullname, |
|---|
| 1818 | 'b':level_title}) |
|---|
| 1819 | |
|---|
| 1820 | class ExportPDFCourseRegistrationSlip(UtilityView, grok.View): |
|---|
| 1821 | """Deliver a PDF slip of the context. |
|---|
| 1822 | """ |
|---|
| 1823 | grok.context(IStudentStudyLevel) |
|---|
| 1824 | grok.name('course_registration_slip.pdf') |
|---|
| 1825 | grok.require('waeup.viewStudent') |
|---|
| 1826 | form_fields = grok.AutoFields(IStudentStudyLevel).omit( |
|---|
| 1827 | 'level', 'gpa', 'transcript_remark') |
|---|
| 1828 | form_fields[ |
|---|
| 1829 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 1830 | prefix = 'form' |
|---|
| 1831 | omit_fields = ( |
|---|
| 1832 | 'password', 'suspended', 'phone', 'date_of_birth', |
|---|
| 1833 | 'adm_code', 'sex', 'suspended_comment', 'current_level', |
|---|
| 1834 | 'flash_notice') |
|---|
| 1835 | |
|---|
| 1836 | @property |
|---|
| 1837 | def title(self): |
|---|
| 1838 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 1839 | return translate(_('Level Data'), 'waeup.kofa', |
|---|
| 1840 | target_language=portal_language) |
|---|
| 1841 | |
|---|
| 1842 | @property |
|---|
| 1843 | def label(self): |
|---|
| 1844 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 1845 | lang = self.request.cookies.get('kofa.language', portal_language) |
|---|
| 1846 | level_title = translate(self.context.level_title, 'waeup.kofa', |
|---|
| 1847 | target_language=lang) |
|---|
| 1848 | return translate(_('Course Registration Slip'), |
|---|
| 1849 | 'waeup.kofa', target_language=portal_language) \ |
|---|
| 1850 | + ' %s' % level_title |
|---|
| 1851 | |
|---|
| 1852 | @property |
|---|
| 1853 | def tabletitle(self): |
|---|
| 1854 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 1855 | tabletitle = [] |
|---|
| 1856 | tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa', |
|---|
| 1857 | target_language=portal_language)) |
|---|
| 1858 | tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa', |
|---|
| 1859 | target_language=portal_language)) |
|---|
| 1860 | tabletitle.append(translate(_('Level Courses'), 'waeup.kofa', |
|---|
| 1861 | target_language=portal_language)) |
|---|
| 1862 | return tabletitle |
|---|
| 1863 | |
|---|
| 1864 | def _signatures(self): |
|---|
| 1865 | return () |
|---|
| 1866 | |
|---|
| 1867 | def _sigsInFooter(self): |
|---|
| 1868 | return () |
|---|
| 1869 | |
|---|
| 1870 | def render(self): |
|---|
| 1871 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 1872 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1873 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1874 | Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1875 | Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1876 | Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1877 | #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1878 | Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1879 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
|---|
| 1880 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 1881 | self.request, self.omit_fields) |
|---|
| 1882 | students_utils = getUtility(IStudentsUtils) |
|---|
| 1883 | |
|---|
| 1884 | tabledata = [] |
|---|
| 1885 | tableheader = [] |
|---|
| 1886 | for i in range(1,7): |
|---|
| 1887 | tabledata.append(sorted( |
|---|
| 1888 | [value for value in self.context.values() if value.semester == i], |
|---|
| 1889 | key=lambda value: str(value.semester) + value.code)) |
|---|
| 1890 | tableheader.append([(Code,'code', 2.5), |
|---|
| 1891 | (Title,'title', 5), |
|---|
| 1892 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
|---|
| 1893 | (Cred, 'credits', 1.5), |
|---|
| 1894 | #(Mand, 'mandatory', 1.5), |
|---|
| 1895 | (Score, 'score', 1.5), |
|---|
| 1896 | (Grade, 'grade', 1.5), |
|---|
| 1897 | #('Auto', 'automatic', 1.5) |
|---|
| 1898 | ]) |
|---|
| 1899 | return students_utils.renderPDF( |
|---|
| 1900 | self, 'course_registration_slip_%s.pdf' % self.context.student.student_id, |
|---|
| 1901 | self.context.student, studentview, |
|---|
| 1902 | tableheader=tableheader, |
|---|
| 1903 | tabledata=tabledata, |
|---|
| 1904 | omit_fields=self.omit_fields, |
|---|
| 1905 | signatures=self._signatures(), |
|---|
| 1906 | sigs_in_footer=self._sigsInFooter(), |
|---|
| 1907 | ) |
|---|
| 1908 | |
|---|
| 1909 | class StudyLevelManageFormPage(KofaEditFormPage): |
|---|
| 1910 | """ Page to edit the student study level data |
|---|
| 1911 | """ |
|---|
| 1912 | grok.context(IStudentStudyLevel) |
|---|
| 1913 | grok.name('manage') |
|---|
| 1914 | grok.require('waeup.manageStudent') |
|---|
| 1915 | grok.template('studylevelmanagepage') |
|---|
| 1916 | form_fields = grok.AutoFields(IStudentStudyLevel).omit( |
|---|
| 1917 | 'validation_date', 'validated_by', 'total_credits', 'gpa', 'level') |
|---|
| 1918 | pnav = 4 |
|---|
| 1919 | taboneactions = [_('Save'),_('Cancel')] |
|---|
| 1920 | tabtwoactions = [_('Add course ticket'), |
|---|
| 1921 | _('Remove selected tickets'),_('Cancel')] |
|---|
| 1922 | placeholder = _('Enter valid course code') |
|---|
| 1923 | |
|---|
| 1924 | def update(self, ADD=None, course=None): |
|---|
| 1925 | if not self.context.__parent__.is_current \ |
|---|
| 1926 | or self.context.student.studycourse_locked: |
|---|
| 1927 | emit_lock_message(self) |
|---|
| 1928 | return |
|---|
| 1929 | super(StudyLevelManageFormPage, self).update() |
|---|
| 1930 | if ADD is not None: |
|---|
| 1931 | if not course: |
|---|
| 1932 | self.flash(_('No valid course code entered.'), type="warning") |
|---|
| 1933 | self.redirect(self.url(self.context, u'@@manage')+'#tab2') |
|---|
| 1934 | return |
|---|
| 1935 | cat = queryUtility(ICatalog, name='courses_catalog') |
|---|
| 1936 | result = cat.searchResults(code=(course, course)) |
|---|
| 1937 | if len(result) != 1: |
|---|
| 1938 | self.flash(_('Course not found.'), type="warning") |
|---|
| 1939 | else: |
|---|
| 1940 | course = list(result)[0] |
|---|
| 1941 | addCourseTicket(self, course) |
|---|
| 1942 | self.redirect(self.url(self.context, u'@@manage')+'#tab2') |
|---|
| 1943 | return |
|---|
| 1944 | |
|---|
| 1945 | @property |
|---|
| 1946 | def translated_values(self): |
|---|
| 1947 | return translated_values(self) |
|---|
| 1948 | |
|---|
| 1949 | @property |
|---|
| 1950 | def label(self): |
|---|
| 1951 | # Here we know that the cookie has been set |
|---|
| 1952 | lang = self.request.cookies.get('kofa.language') |
|---|
| 1953 | level_title = translate(self.context.level_title, 'waeup.kofa', |
|---|
| 1954 | target_language=lang) |
|---|
| 1955 | return _('Manage ${a}', |
|---|
| 1956 | mapping = {'a':level_title}) |
|---|
| 1957 | |
|---|
| 1958 | @action(_('Save'), style='primary') |
|---|
| 1959 | def save(self, **data): |
|---|
| 1960 | msave(self, **data) |
|---|
| 1961 | return |
|---|
| 1962 | |
|---|
| 1963 | @jsaction(_('Remove selected tickets')) |
|---|
| 1964 | def delCourseTicket(self, **data): |
|---|
| 1965 | form = self.request.form |
|---|
| 1966 | if 'val_id' in form: |
|---|
| 1967 | child_id = form['val_id'] |
|---|
| 1968 | else: |
|---|
| 1969 | self.flash(_('No ticket selected.'), type="warning") |
|---|
| 1970 | self.redirect(self.url(self.context, '@@manage')+'#tab2') |
|---|
| 1971 | return |
|---|
| 1972 | if not isinstance(child_id, list): |
|---|
| 1973 | child_id = [child_id] |
|---|
| 1974 | deleted = [] |
|---|
| 1975 | for id in child_id: |
|---|
| 1976 | del self.context[id] |
|---|
| 1977 | deleted.append(id) |
|---|
| 1978 | if len(deleted): |
|---|
| 1979 | self.flash(_('Successfully removed: ${a}', |
|---|
| 1980 | mapping = {'a':', '.join(deleted)})) |
|---|
| 1981 | self.context.writeLogMessage( |
|---|
| 1982 | self,'removed: %s' % (', '.join(deleted))) |
|---|
| 1983 | self.redirect(self.url(self.context, u'@@manage')+'#tab2') |
|---|
| 1984 | return |
|---|
| 1985 | |
|---|
| 1986 | class StudyLevelRemarkFormPage(KofaEditFormPage): |
|---|
| 1987 | """ Page to edit the student study level transcript remark only |
|---|
| 1988 | """ |
|---|
| 1989 | grok.context(IStudentStudyLevel) |
|---|
| 1990 | grok.name('remark') |
|---|
| 1991 | grok.require('waeup.processTranscript') |
|---|
| 1992 | grok.template('studylevelremarkpage') |
|---|
| 1993 | form_fields = grok.AutoFields(IStudentStudyLevel).omit('level') |
|---|
| 1994 | form_fields['level_session'].for_display = True |
|---|
| 1995 | form_fields['level_verdict'].for_display = True |
|---|
| 1996 | form_fields['validation_date'].for_display = True |
|---|
| 1997 | form_fields['validated_by'].for_display = True |
|---|
| 1998 | |
|---|
| 1999 | def update(self, ADD=None, course=None): |
|---|
| 2000 | if self.context.student.studycourse_locked: |
|---|
| 2001 | emit_lock_message(self) |
|---|
| 2002 | return |
|---|
| 2003 | super(StudyLevelRemarkFormPage, self).update() |
|---|
| 2004 | |
|---|
| 2005 | @property |
|---|
| 2006 | def label(self): |
|---|
| 2007 | lang = self.request.cookies.get('kofa.language') |
|---|
| 2008 | level_title = translate(self.context.level_title, 'waeup.kofa', |
|---|
| 2009 | target_language=lang) |
|---|
| 2010 | return _( |
|---|
| 2011 | 'Edit transcript remark of level ${a}', mapping = {'a':level_title}) |
|---|
| 2012 | |
|---|
| 2013 | @property |
|---|
| 2014 | def translated_values(self): |
|---|
| 2015 | return translated_values(self) |
|---|
| 2016 | |
|---|
| 2017 | @action(_('Save remark and go and back to transcript validation page'), |
|---|
| 2018 | style='primary') |
|---|
| 2019 | def save(self, **data): |
|---|
| 2020 | msave(self, **data) |
|---|
| 2021 | self.redirect(self.url(self.context.student) |
|---|
| 2022 | + '/studycourse/validate_transcript#tab4') |
|---|
| 2023 | return |
|---|
| 2024 | |
|---|
| 2025 | class ValidateCoursesView(UtilityView, grok.View): |
|---|
| 2026 | """ Validate course list by course adviser |
|---|
| 2027 | """ |
|---|
| 2028 | grok.context(IStudentStudyLevel) |
|---|
| 2029 | grok.name('validate_courses') |
|---|
| 2030 | grok.require('waeup.validateStudent') |
|---|
| 2031 | |
|---|
| 2032 | def update(self): |
|---|
| 2033 | if not self.context.__parent__.is_current: |
|---|
| 2034 | emit_lock_message(self) |
|---|
| 2035 | return |
|---|
| 2036 | if str(self.context.student.current_level) != self.context.__name__: |
|---|
| 2037 | self.flash(_('This is not the student\'s current level.'), |
|---|
| 2038 | type="danger") |
|---|
| 2039 | elif self.context.student.state == REGISTERED: |
|---|
| 2040 | IWorkflowInfo(self.context.student).fireTransition( |
|---|
| 2041 | 'validate_courses') |
|---|
| 2042 | self.flash(_('Course list has been validated.')) |
|---|
| 2043 | else: |
|---|
| 2044 | self.flash(_('Student is in the wrong state.'), type="warning") |
|---|
| 2045 | self.redirect(self.url(self.context)) |
|---|
| 2046 | return |
|---|
| 2047 | |
|---|
| 2048 | def render(self): |
|---|
| 2049 | return |
|---|
| 2050 | |
|---|
| 2051 | class RejectCoursesView(UtilityView, grok.View): |
|---|
| 2052 | """ Reject course list by course adviser |
|---|
| 2053 | """ |
|---|
| 2054 | grok.context(IStudentStudyLevel) |
|---|
| 2055 | grok.name('reject_courses') |
|---|
| 2056 | grok.require('waeup.validateStudent') |
|---|
| 2057 | |
|---|
| 2058 | def update(self): |
|---|
| 2059 | if not self.context.__parent__.is_current: |
|---|
| 2060 | emit_lock_message(self) |
|---|
| 2061 | return |
|---|
| 2062 | if str(self.context.__parent__.current_level) != self.context.__name__: |
|---|
| 2063 | self.flash(_('This is not the student\'s current level.'), |
|---|
| 2064 | type="danger") |
|---|
| 2065 | self.redirect(self.url(self.context)) |
|---|
| 2066 | return |
|---|
| 2067 | elif self.context.student.state == VALIDATED: |
|---|
| 2068 | IWorkflowInfo(self.context.student).fireTransition('reset8') |
|---|
| 2069 | message = _('Course list request has been annulled.') |
|---|
| 2070 | self.flash(message) |
|---|
| 2071 | elif self.context.student.state == REGISTERED: |
|---|
| 2072 | IWorkflowInfo(self.context.student).fireTransition('reset7') |
|---|
| 2073 | message = _('Course list has been unregistered.') |
|---|
| 2074 | self.flash(message) |
|---|
| 2075 | else: |
|---|
| 2076 | self.flash(_('Student is in the wrong state.'), type="warning") |
|---|
| 2077 | self.redirect(self.url(self.context)) |
|---|
| 2078 | return |
|---|
| 2079 | args = {'subject':message} |
|---|
| 2080 | self.redirect(self.url(self.context.student) + |
|---|
| 2081 | '/contactstudent?%s' % urlencode(args)) |
|---|
| 2082 | return |
|---|
| 2083 | |
|---|
| 2084 | def render(self): |
|---|
| 2085 | return |
|---|
| 2086 | |
|---|
| 2087 | class UnregisterCoursesView(UtilityView, grok.View): |
|---|
| 2088 | """Unregister course list by student |
|---|
| 2089 | """ |
|---|
| 2090 | grok.context(IStudentStudyLevel) |
|---|
| 2091 | grok.name('unregister_courses') |
|---|
| 2092 | grok.require('waeup.handleStudent') |
|---|
| 2093 | |
|---|
| 2094 | def update(self): |
|---|
| 2095 | if not self.context.__parent__.is_current: |
|---|
| 2096 | emit_lock_message(self) |
|---|
| 2097 | return |
|---|
| 2098 | try: |
|---|
| 2099 | deadline = grok.getSite()['configuration'][ |
|---|
| 2100 | str(self.context.level_session)].coursereg_deadline |
|---|
| 2101 | except (TypeError, KeyError): |
|---|
| 2102 | deadline = None |
|---|
| 2103 | if deadline and deadline < datetime.now(pytz.utc): |
|---|
| 2104 | self.flash(_( |
|---|
| 2105 | "Course registration has ended. " |
|---|
| 2106 | "Unregistration is disabled."), type="warning") |
|---|
| 2107 | elif str(self.context.__parent__.current_level) != self.context.__name__: |
|---|
| 2108 | self.flash(_('This is not your current level.'), type="danger") |
|---|
| 2109 | elif self.context.student.state == REGISTERED: |
|---|
| 2110 | IWorkflowInfo(self.context.student).fireTransition('reset7') |
|---|
| 2111 | message = _('Course list has been unregistered.') |
|---|
| 2112 | self.flash(message) |
|---|
| 2113 | else: |
|---|
| 2114 | self.flash(_('You are in the wrong state.'), type="warning") |
|---|
| 2115 | self.redirect(self.url(self.context)) |
|---|
| 2116 | return |
|---|
| 2117 | |
|---|
| 2118 | def render(self): |
|---|
| 2119 | return |
|---|
| 2120 | |
|---|
| 2121 | class CourseTicketAddFormPage(KofaAddFormPage): |
|---|
| 2122 | """Add a course ticket. |
|---|
| 2123 | """ |
|---|
| 2124 | grok.context(IStudentStudyLevel) |
|---|
| 2125 | grok.name('add') |
|---|
| 2126 | grok.require('waeup.manageStudent') |
|---|
| 2127 | label = _('Add course ticket') |
|---|
| 2128 | form_fields = grok.AutoFields(ICourseTicketAdd) |
|---|
| 2129 | pnav = 4 |
|---|
| 2130 | |
|---|
| 2131 | def update(self): |
|---|
| 2132 | if not self.context.__parent__.is_current \ |
|---|
| 2133 | or self.context.student.studycourse_locked: |
|---|
| 2134 | emit_lock_message(self) |
|---|
| 2135 | return |
|---|
| 2136 | super(CourseTicketAddFormPage, self).update() |
|---|
| 2137 | return |
|---|
| 2138 | |
|---|
| 2139 | @action(_('Add course ticket'), style='primary') |
|---|
| 2140 | def addCourseTicket(self, **data): |
|---|
| 2141 | course = data['course'] |
|---|
| 2142 | success = addCourseTicket(self, course) |
|---|
| 2143 | if success: |
|---|
| 2144 | self.redirect(self.url(self.context, u'@@manage')+'#tab2') |
|---|
| 2145 | return |
|---|
| 2146 | |
|---|
| 2147 | @action(_('Cancel'), validator=NullValidator) |
|---|
| 2148 | def cancel(self, **data): |
|---|
| 2149 | self.redirect(self.url(self.context)) |
|---|
| 2150 | |
|---|
| 2151 | class CourseTicketDisplayFormPage(KofaDisplayFormPage): |
|---|
| 2152 | """ Page to display course tickets |
|---|
| 2153 | """ |
|---|
| 2154 | grok.context(ICourseTicket) |
|---|
| 2155 | grok.name('index') |
|---|
| 2156 | grok.require('waeup.viewStudent') |
|---|
| 2157 | form_fields = grok.AutoFields(ICourseTicket).omit('course_category', |
|---|
| 2158 | 'ticket_session') |
|---|
| 2159 | grok.template('courseticketpage') |
|---|
| 2160 | pnav = 4 |
|---|
| 2161 | |
|---|
| 2162 | @property |
|---|
| 2163 | def label(self): |
|---|
| 2164 | return _('${a}: Course Ticket ${b}', mapping = { |
|---|
| 2165 | 'a':self.context.student.display_fullname, |
|---|
| 2166 | 'b':self.context.code}) |
|---|
| 2167 | |
|---|
| 2168 | class CourseTicketManageFormPage(KofaEditFormPage): |
|---|
| 2169 | """ Page to manage course tickets |
|---|
| 2170 | """ |
|---|
| 2171 | grok.context(ICourseTicket) |
|---|
| 2172 | grok.name('manage') |
|---|
| 2173 | grok.require('waeup.manageStudent') |
|---|
| 2174 | form_fields = grok.AutoFields(ICourseTicket).omit('course_category') |
|---|
| 2175 | form_fields['title'].for_display = True |
|---|
| 2176 | form_fields['fcode'].for_display = True |
|---|
| 2177 | form_fields['dcode'].for_display = True |
|---|
| 2178 | form_fields['semester'].for_display = True |
|---|
| 2179 | form_fields['passmark'].for_display = True |
|---|
| 2180 | form_fields['credits'].for_display = True |
|---|
| 2181 | form_fields['mandatory'].for_display = False |
|---|
| 2182 | form_fields['automatic'].for_display = True |
|---|
| 2183 | form_fields['carry_over'].for_display = True |
|---|
| 2184 | form_fields['ticket_session'].for_display = True |
|---|
| 2185 | pnav = 4 |
|---|
| 2186 | grok.template('courseticketmanagepage') |
|---|
| 2187 | |
|---|
| 2188 | def update(self): |
|---|
| 2189 | if not self.context.__parent__.__parent__.is_current \ |
|---|
| 2190 | or self.context.student.studycourse_locked: |
|---|
| 2191 | emit_lock_message(self) |
|---|
| 2192 | return |
|---|
| 2193 | super(CourseTicketManageFormPage, self).update() |
|---|
| 2194 | return |
|---|
| 2195 | |
|---|
| 2196 | @property |
|---|
| 2197 | def label(self): |
|---|
| 2198 | return _('Manage course ticket ${a}', mapping = {'a':self.context.code}) |
|---|
| 2199 | |
|---|
| 2200 | @action('Save', style='primary') |
|---|
| 2201 | def save(self, **data): |
|---|
| 2202 | msave(self, **data) |
|---|
| 2203 | return |
|---|
| 2204 | |
|---|
| 2205 | class PaymentsManageFormPage(KofaEditFormPage): |
|---|
| 2206 | """ Page to manage the student payments |
|---|
| 2207 | |
|---|
| 2208 | This manage form page is for both students and students officers. |
|---|
| 2209 | """ |
|---|
| 2210 | grok.context(IStudentPaymentsContainer) |
|---|
| 2211 | grok.name('index') |
|---|
| 2212 | grok.require('waeup.viewStudent') |
|---|
| 2213 | form_fields = grok.AutoFields(IStudentPaymentsContainer) |
|---|
| 2214 | grok.template('paymentsmanagepage') |
|---|
| 2215 | pnav = 4 |
|---|
| 2216 | |
|---|
| 2217 | @property |
|---|
| 2218 | def manage_payments_allowed(self): |
|---|
| 2219 | return checkPermission('waeup.payStudent', self.context) |
|---|
| 2220 | |
|---|
| 2221 | def unremovable(self, ticket): |
|---|
| 2222 | usertype = getattr(self.request.principal, 'user_type', None) |
|---|
| 2223 | if not usertype: |
|---|
| 2224 | return False |
|---|
| 2225 | if not self.manage_payments_allowed: |
|---|
| 2226 | return True |
|---|
| 2227 | return (self.request.principal.user_type == 'student' and ticket.r_code) |
|---|
| 2228 | |
|---|
| 2229 | @property |
|---|
| 2230 | def label(self): |
|---|
| 2231 | return _('${a}: Payments', |
|---|
| 2232 | mapping = {'a':self.context.__parent__.display_fullname}) |
|---|
| 2233 | |
|---|
| 2234 | @jsaction(_('Remove selected tickets')) |
|---|
| 2235 | def delPaymentTicket(self, **data): |
|---|
| 2236 | form = self.request.form |
|---|
| 2237 | if 'val_id' in form: |
|---|
| 2238 | child_id = form['val_id'] |
|---|
| 2239 | else: |
|---|
| 2240 | self.flash(_('No payment selected.'), type="warning") |
|---|
| 2241 | self.redirect(self.url(self.context)) |
|---|
| 2242 | return |
|---|
| 2243 | if not isinstance(child_id, list): |
|---|
| 2244 | child_id = [child_id] |
|---|
| 2245 | deleted = [] |
|---|
| 2246 | for id in child_id: |
|---|
| 2247 | # Students are not allowed to remove used payment tickets |
|---|
| 2248 | ticket = self.context.get(id, None) |
|---|
| 2249 | if ticket is not None and not self.unremovable(ticket): |
|---|
| 2250 | del self.context[id] |
|---|
| 2251 | deleted.append(id) |
|---|
| 2252 | if len(deleted): |
|---|
| 2253 | self.flash(_('Successfully removed: ${a}', |
|---|
| 2254 | mapping = {'a': ', '.join(deleted)})) |
|---|
| 2255 | self.context.writeLogMessage( |
|---|
| 2256 | self,'removed: %s' % ', '.join(deleted)) |
|---|
| 2257 | self.redirect(self.url(self.context)) |
|---|
| 2258 | return |
|---|
| 2259 | |
|---|
| 2260 | class OnlinePaymentAddFormPage(KofaAddFormPage): |
|---|
| 2261 | """ Page to add an online payment ticket |
|---|
| 2262 | """ |
|---|
| 2263 | grok.context(IStudentPaymentsContainer) |
|---|
| 2264 | grok.name('addop') |
|---|
| 2265 | grok.template('onlinepaymentaddform') |
|---|
| 2266 | grok.require('waeup.payStudent') |
|---|
| 2267 | form_fields = grok.AutoFields(IStudentOnlinePayment).select('p_combi') |
|---|
| 2268 | label = _('Add online payment') |
|---|
| 2269 | pnav = 4 |
|---|
| 2270 | |
|---|
| 2271 | @property |
|---|
| 2272 | def selectable_categories(self): |
|---|
| 2273 | student = self.context.__parent__ |
|---|
| 2274 | categories = getUtility( |
|---|
| 2275 | IKofaUtils).selectable_payment_categories(student) |
|---|
| 2276 | return sorted(categories.items(), key=lambda value: value[1]) |
|---|
| 2277 | |
|---|
| 2278 | @property |
|---|
| 2279 | def selectable_payment_options(self): |
|---|
| 2280 | student = self.context.__parent__ |
|---|
| 2281 | options = getUtility( |
|---|
| 2282 | IKofaUtils).selectable_payment_options(student) |
|---|
| 2283 | return sorted(options.items(), key=lambda value: value[1]) |
|---|
| 2284 | |
|---|
| 2285 | @action(_('Create ticket'), style='primary') |
|---|
| 2286 | def createTicket(self, **data): |
|---|
| 2287 | form = self.request.form |
|---|
| 2288 | p_category = form.get('form.p_category', None) |
|---|
| 2289 | p_option = form.get('form.p_option', None) |
|---|
| 2290 | p_combi = form.get('form.p_combi', []) |
|---|
| 2291 | if isinstance(form.get('form.p_combi', None), unicode): |
|---|
| 2292 | p_combi = [p_combi,] |
|---|
| 2293 | student = self.context.__parent__ |
|---|
| 2294 | students_utils = getUtility(IStudentsUtils) |
|---|
| 2295 | # The hostel_application payment category is temporarily used |
|---|
| 2296 | # by Uniben. |
|---|
| 2297 | accommodation_session = grok.getSite()['hostels'].accommodation_session |
|---|
| 2298 | if p_category in ('bed_allocation', 'hostel_application') \ |
|---|
| 2299 | and accommodation_session - student[ |
|---|
| 2300 | 'studycourse'].current_session > students_utils.ACCOMMODATION_SPAN: |
|---|
| 2301 | self.flash( |
|---|
| 2302 | _('Your current session does not allow ' + \ |
|---|
| 2303 | 'to book accommodation.'), type="danger") |
|---|
| 2304 | return |
|---|
| 2305 | if 'maintenance' in p_category: |
|---|
| 2306 | if str(accommodation_session) not in student['accommodation']: |
|---|
| 2307 | self.flash(_('You have not yet booked accommodation.'), |
|---|
| 2308 | type="warning") |
|---|
| 2309 | return |
|---|
| 2310 | error, payment = students_utils.setPaymentDetails( |
|---|
| 2311 | p_category, student, None, None, p_combi) |
|---|
| 2312 | if error is not None: |
|---|
| 2313 | self.flash(error, type="danger") |
|---|
| 2314 | return |
|---|
| 2315 | if p_category == 'transfer': |
|---|
| 2316 | payment.p_item = form['new_programme'] |
|---|
| 2317 | if p_option: |
|---|
| 2318 | payment.p_option = p_option |
|---|
| 2319 | self.context[payment.p_id] = payment |
|---|
| 2320 | self.flash(_('Payment ticket created.')) |
|---|
| 2321 | self.context.writeLogMessage(self,'added: %s' % payment.p_id) |
|---|
| 2322 | self.redirect(self.url(payment)) |
|---|
| 2323 | return |
|---|
| 2324 | |
|---|
| 2325 | @action(_('Cancel'), validator=NullValidator) |
|---|
| 2326 | def cancel(self, **data): |
|---|
| 2327 | self.redirect(self.url(self.context)) |
|---|
| 2328 | |
|---|
| 2329 | class PreviousPaymentAddFormPage(KofaAddFormPage): |
|---|
| 2330 | """ Page to add an online payment ticket for previous sessions. |
|---|
| 2331 | """ |
|---|
| 2332 | grok.context(IStudentPaymentsContainer) |
|---|
| 2333 | grok.name('addpp') |
|---|
| 2334 | grok.template('previouspaymentaddform') |
|---|
| 2335 | grok.require('waeup.payStudent') |
|---|
| 2336 | form_fields = grok.AutoFields(IStudentPreviousPayment) |
|---|
| 2337 | label = _('Add previous session online payment') |
|---|
| 2338 | pnav = 4 |
|---|
| 2339 | |
|---|
| 2340 | def update(self): |
|---|
| 2341 | if self.context.student.before_payment: |
|---|
| 2342 | self.flash(_("No previous payment to be made."), type="warning") |
|---|
| 2343 | self.redirect(self.url(self.context)) |
|---|
| 2344 | super(PreviousPaymentAddFormPage, self).update() |
|---|
| 2345 | return |
|---|
| 2346 | |
|---|
| 2347 | @property |
|---|
| 2348 | def selectable_payment_options(self): |
|---|
| 2349 | student = self.context.__parent__ |
|---|
| 2350 | options = getUtility( |
|---|
| 2351 | IKofaUtils).selectable_payment_options(student) |
|---|
| 2352 | return sorted(options.items(), key=lambda value: value[1]) |
|---|
| 2353 | |
|---|
| 2354 | @action(_('Create ticket'), style='primary') |
|---|
| 2355 | def createTicket(self, **data): |
|---|
| 2356 | p_category = data['p_category'] |
|---|
| 2357 | form = self.request.form |
|---|
| 2358 | p_option = form.get('form.p_option', None) |
|---|
| 2359 | previous_session = data.get('p_session', None) |
|---|
| 2360 | previous_level = data.get('p_level', None) |
|---|
| 2361 | student = self.context.__parent__ |
|---|
| 2362 | students_utils = getUtility(IStudentsUtils) |
|---|
| 2363 | error, payment = students_utils.setPaymentDetails( |
|---|
| 2364 | p_category, student, previous_session, previous_level, None) |
|---|
| 2365 | if error is not None: |
|---|
| 2366 | self.flash(error, type="danger") |
|---|
| 2367 | return |
|---|
| 2368 | if p_option: |
|---|
| 2369 | payment.p_option = p_option |
|---|
| 2370 | self.context[payment.p_id] = payment |
|---|
| 2371 | self.flash(_('Payment ticket created.')) |
|---|
| 2372 | self.context.writeLogMessage(self,'added: %s' % payment.p_id) |
|---|
| 2373 | self.redirect(self.url(payment)) |
|---|
| 2374 | return |
|---|
| 2375 | |
|---|
| 2376 | @action(_('Cancel'), validator=NullValidator) |
|---|
| 2377 | def cancel(self, **data): |
|---|
| 2378 | self.redirect(self.url(self.context)) |
|---|
| 2379 | |
|---|
| 2380 | class BalancePaymentAddFormPage(KofaAddFormPage): |
|---|
| 2381 | """ Page to add an online payment which can balance s previous session |
|---|
| 2382 | payment. |
|---|
| 2383 | """ |
|---|
| 2384 | grok.context(IStudentPaymentsContainer) |
|---|
| 2385 | grok.name('addbp') |
|---|
| 2386 | grok.template('previouspaymentaddform') |
|---|
| 2387 | grok.require('waeup.manageStudent') |
|---|
| 2388 | form_fields = grok.AutoFields(IStudentBalancePayment) |
|---|
| 2389 | label = _('Add balance') |
|---|
| 2390 | pnav = 4 |
|---|
| 2391 | |
|---|
| 2392 | @property |
|---|
| 2393 | def selectable_payment_options(self): |
|---|
| 2394 | student = self.context.__parent__ |
|---|
| 2395 | options = getUtility( |
|---|
| 2396 | IKofaUtils).selectable_payment_options(student) |
|---|
| 2397 | return sorted(options.items(), key=lambda value: value[1]) |
|---|
| 2398 | |
|---|
| 2399 | @action(_('Create ticket'), style='primary') |
|---|
| 2400 | def createTicket(self, **data): |
|---|
| 2401 | p_category = data['p_category'] |
|---|
| 2402 | form = self.request.form |
|---|
| 2403 | p_option = form.get('form.p_option', None) |
|---|
| 2404 | balance_session = data.get('balance_session', None) |
|---|
| 2405 | balance_level = data.get('balance_level', None) |
|---|
| 2406 | balance_amount = data.get('balance_amount', None) |
|---|
| 2407 | student = self.context.__parent__ |
|---|
| 2408 | students_utils = getUtility(IStudentsUtils) |
|---|
| 2409 | error, payment = students_utils.setBalanceDetails( |
|---|
| 2410 | p_category, student, balance_session, |
|---|
| 2411 | balance_level, balance_amount) |
|---|
| 2412 | if error is not None: |
|---|
| 2413 | self.flash(error, type="danger") |
|---|
| 2414 | return |
|---|
| 2415 | if p_option: |
|---|
| 2416 | payment.p_option = p_option |
|---|
| 2417 | self.context[payment.p_id] = payment |
|---|
| 2418 | self.flash(_('Payment ticket created.')) |
|---|
| 2419 | self.context.writeLogMessage(self,'added: %s' % payment.p_id) |
|---|
| 2420 | self.redirect(self.url(payment)) |
|---|
| 2421 | return |
|---|
| 2422 | |
|---|
| 2423 | @action(_('Cancel'), validator=NullValidator) |
|---|
| 2424 | def cancel(self, **data): |
|---|
| 2425 | self.redirect(self.url(self.context)) |
|---|
| 2426 | |
|---|
| 2427 | class OnlinePaymentDisplayFormPage(KofaDisplayFormPage): |
|---|
| 2428 | """ Page to view an online payment ticket |
|---|
| 2429 | """ |
|---|
| 2430 | grok.context(IStudentOnlinePayment) |
|---|
| 2431 | grok.name('index') |
|---|
| 2432 | grok.require('waeup.viewStudent') |
|---|
| 2433 | form_fields = grok.AutoFields(IStudentOnlinePayment).omit( |
|---|
| 2434 | 'p_item', 'p_combi') |
|---|
| 2435 | form_fields[ |
|---|
| 2436 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 2437 | form_fields[ |
|---|
| 2438 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 2439 | pnav = 4 |
|---|
| 2440 | |
|---|
| 2441 | @property |
|---|
| 2442 | def label(self): |
|---|
| 2443 | return _('${a}: Online Payment Ticket ${b}', mapping = { |
|---|
| 2444 | 'a':self.context.student.display_fullname, |
|---|
| 2445 | 'b':self.context.p_id}) |
|---|
| 2446 | |
|---|
| 2447 | class OnlinePaymentApproveView(UtilityView, grok.View): |
|---|
| 2448 | """ Callback view |
|---|
| 2449 | """ |
|---|
| 2450 | grok.context(IStudentOnlinePayment) |
|---|
| 2451 | grok.name('approve') |
|---|
| 2452 | grok.require('waeup.managePortal') |
|---|
| 2453 | |
|---|
| 2454 | def update(self): |
|---|
| 2455 | flashtype, msg, log = self.context.approveStudentPayment() |
|---|
| 2456 | if log is not None: |
|---|
| 2457 | # Add log message to students.log |
|---|
| 2458 | self.context.writeLogMessage(self,log) |
|---|
| 2459 | # Add log message to payments.log |
|---|
| 2460 | self.context.logger.info( |
|---|
| 2461 | '%s,%s,%s,%s,%s,,,,,,' % ( |
|---|
| 2462 | self.context.student.student_id, |
|---|
| 2463 | self.context.p_id, self.context.p_category, |
|---|
| 2464 | self.context.amount_auth, self.context.r_code)) |
|---|
| 2465 | self.flash(msg, type=flashtype) |
|---|
| 2466 | return |
|---|
| 2467 | |
|---|
| 2468 | def render(self): |
|---|
| 2469 | self.redirect(self.url(self.context, '@@index')) |
|---|
| 2470 | return |
|---|
| 2471 | |
|---|
| 2472 | class OnlinePaymentFakeApproveView(OnlinePaymentApproveView): |
|---|
| 2473 | """ Approval view for students. |
|---|
| 2474 | |
|---|
| 2475 | This view is used for browser tests only and |
|---|
| 2476 | must be neutralized on custom pages! |
|---|
| 2477 | """ |
|---|
| 2478 | grok.name('fake_approve') |
|---|
| 2479 | grok.require('waeup.payStudent') |
|---|
| 2480 | |
|---|
| 2481 | class ExportPDFPaymentSlip(UtilityView, grok.View): |
|---|
| 2482 | """Deliver a PDF slip of the context. |
|---|
| 2483 | """ |
|---|
| 2484 | grok.context(IStudentOnlinePayment) |
|---|
| 2485 | grok.name('payment_slip.pdf') |
|---|
| 2486 | grok.require('waeup.viewStudent') |
|---|
| 2487 | form_fields = grok.AutoFields(IStudentOnlinePayment).omit( |
|---|
| 2488 | 'p_item', 'p_combi') |
|---|
| 2489 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 2490 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 2491 | prefix = 'form' |
|---|
| 2492 | note = None |
|---|
| 2493 | omit_fields = ( |
|---|
| 2494 | 'password', 'suspended', 'phone', 'date_of_birth', |
|---|
| 2495 | 'adm_code', 'sex', 'suspended_comment', 'current_level', |
|---|
| 2496 | 'flash_notice') |
|---|
| 2497 | |
|---|
| 2498 | @property |
|---|
| 2499 | def title(self): |
|---|
| 2500 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 2501 | return translate(_('Payment Data'), 'waeup.kofa', |
|---|
| 2502 | target_language=portal_language) |
|---|
| 2503 | |
|---|
| 2504 | @property |
|---|
| 2505 | def label(self): |
|---|
| 2506 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 2507 | return translate(_('Online Payment Slip'), |
|---|
| 2508 | 'waeup.kofa', target_language=portal_language) \ |
|---|
| 2509 | + ' %s' % self.context.p_id |
|---|
| 2510 | |
|---|
| 2511 | def render(self): |
|---|
| 2512 | #if self.context.p_state != 'paid': |
|---|
| 2513 | # self.flash('Ticket not yet paid.') |
|---|
| 2514 | # self.redirect(self.url(self.context)) |
|---|
| 2515 | # return |
|---|
| 2516 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 2517 | self.request, self.omit_fields) |
|---|
| 2518 | students_utils = getUtility(IStudentsUtils) |
|---|
| 2519 | return students_utils.renderPDF(self, |
|---|
| 2520 | 'payment_slip_%s_%s.pdf' % ( |
|---|
| 2521 | self.context.student.student_id, self.context.p_id), |
|---|
| 2522 | self.context.student, studentview, note=self.note, |
|---|
| 2523 | omit_fields=self.omit_fields) |
|---|
| 2524 | |
|---|
| 2525 | class AccommodationDisplayFormPage(KofaDisplayFormPage): |
|---|
| 2526 | """ Page to view bed tickets. |
|---|
| 2527 | This manage form page is for both students and students officers. |
|---|
| 2528 | """ |
|---|
| 2529 | grok.context(IStudentAccommodation) |
|---|
| 2530 | grok.name('index') |
|---|
| 2531 | grok.require('waeup.viewStudent') |
|---|
| 2532 | form_fields = grok.AutoFields(IStudentAccommodation) |
|---|
| 2533 | grok.template('accommodationpage') |
|---|
| 2534 | pnav = 4 |
|---|
| 2535 | with_hostel_selection = True |
|---|
| 2536 | |
|---|
| 2537 | @property |
|---|
| 2538 | def label(self): |
|---|
| 2539 | return _('${a}: Accommodation', |
|---|
| 2540 | mapping = {'a':self.context.__parent__.display_fullname}) |
|---|
| 2541 | |
|---|
| 2542 | @property |
|---|
| 2543 | def desired_hostel(self): |
|---|
| 2544 | if self.context.desired_hostel == 'no': |
|---|
| 2545 | return _('No favoured hostel') |
|---|
| 2546 | if self.context.desired_hostel: |
|---|
| 2547 | hostel = grok.getSite()['hostels'].get(self.context.desired_hostel) |
|---|
| 2548 | if hostel is not None: |
|---|
| 2549 | return hostel.hostel_name |
|---|
| 2550 | return |
|---|
| 2551 | |
|---|
| 2552 | def update(self): |
|---|
| 2553 | if checkPermission('waeup.handleAccommodation', self.context): |
|---|
| 2554 | self.redirect(self.url(self.context, 'manage')) |
|---|
| 2555 | |
|---|
| 2556 | class AccommodationManageFormPage(KofaEditFormPage): |
|---|
| 2557 | """ Page to manage bed tickets. |
|---|
| 2558 | |
|---|
| 2559 | This manage form page is for both students and students officers. |
|---|
| 2560 | """ |
|---|
| 2561 | grok.context(IStudentAccommodation) |
|---|
| 2562 | grok.name('manage') |
|---|
| 2563 | grok.require('waeup.handleAccommodation') |
|---|
| 2564 | form_fields = grok.AutoFields(IStudentAccommodation) |
|---|
| 2565 | grok.template('accommodationmanagepage') |
|---|
| 2566 | pnav = 4 |
|---|
| 2567 | with_hostel_selection = True |
|---|
| 2568 | |
|---|
| 2569 | @property |
|---|
| 2570 | def booking_allowed(self): |
|---|
| 2571 | students_utils = getUtility(IStudentsUtils) |
|---|
| 2572 | acc_details = students_utils.getAccommodationDetails(self.context.student) |
|---|
| 2573 | error_message = students_utils.checkAccommodationRequirements( |
|---|
| 2574 | self.context.student, acc_details) |
|---|
| 2575 | if error_message: |
|---|
| 2576 | return False |
|---|
| 2577 | return True |
|---|
| 2578 | |
|---|
| 2579 | @property |
|---|
| 2580 | def actionsgroup1(self): |
|---|
| 2581 | if not self.booking_allowed: |
|---|
| 2582 | return [] |
|---|
| 2583 | if not self.with_hostel_selection: |
|---|
| 2584 | return [] |
|---|
| 2585 | return [_('Save')] |
|---|
| 2586 | |
|---|
| 2587 | @property |
|---|
| 2588 | def actionsgroup2(self): |
|---|
| 2589 | if getattr(self.request.principal, 'user_type', None) == 'student': |
|---|
| 2590 | ## Book button can be disabled in custom packages by |
|---|
| 2591 | ## uncommenting the following lines. |
|---|
| 2592 | #if not self.booking_allowed: |
|---|
| 2593 | # return [] |
|---|
| 2594 | return [_('Book accommodation')] |
|---|
| 2595 | return [_('Book accommodation'), _('Remove selected')] |
|---|
| 2596 | |
|---|
| 2597 | @property |
|---|
| 2598 | def label(self): |
|---|
| 2599 | return _('${a}: Accommodation', |
|---|
| 2600 | mapping = {'a':self.context.__parent__.display_fullname}) |
|---|
| 2601 | |
|---|
| 2602 | @property |
|---|
| 2603 | def desired_hostel(self): |
|---|
| 2604 | if self.context.desired_hostel == 'no': |
|---|
| 2605 | return _('No favoured hostel') |
|---|
| 2606 | if self.context.desired_hostel: |
|---|
| 2607 | hostel = grok.getSite()['hostels'].get(self.context.desired_hostel) |
|---|
| 2608 | if hostel is not None: |
|---|
| 2609 | return hostel.hostel_name |
|---|
| 2610 | return |
|---|
| 2611 | |
|---|
| 2612 | def getHostels(self): |
|---|
| 2613 | """Get a list of all stored hostels. |
|---|
| 2614 | """ |
|---|
| 2615 | yield(dict(name=None, title='--', selected='')) |
|---|
| 2616 | selected = '' |
|---|
| 2617 | if self.context.desired_hostel == 'no': |
|---|
| 2618 | selected = 'selected' |
|---|
| 2619 | yield(dict(name='no', title=_('No favoured hostel'), selected=selected)) |
|---|
| 2620 | for val in grok.getSite()['hostels'].values(): |
|---|
| 2621 | if val.special_handling == 'blocked': |
|---|
| 2622 | continue |
|---|
| 2623 | selected = '' |
|---|
| 2624 | if val.hostel_id == self.context.desired_hostel: |
|---|
| 2625 | selected = 'selected' |
|---|
| 2626 | yield(dict(name=val.hostel_id, title=val.hostel_name, |
|---|
| 2627 | selected=selected)) |
|---|
| 2628 | |
|---|
| 2629 | @action(_('Save'), style='primary') |
|---|
| 2630 | def save(self): |
|---|
| 2631 | hostel = self.request.form.get('hostel', None) |
|---|
| 2632 | self.context.desired_hostel = hostel |
|---|
| 2633 | self.flash(_('Your selection has been saved.')) |
|---|
| 2634 | return |
|---|
| 2635 | |
|---|
| 2636 | @action(_('Book accommodation'), style='primary') |
|---|
| 2637 | def bookAccommodation(self, **data): |
|---|
| 2638 | self.redirect(self.url(self.context, 'add')) |
|---|
| 2639 | return |
|---|
| 2640 | |
|---|
| 2641 | @jsaction(_('Remove selected')) |
|---|
| 2642 | def delBedTickets(self, **data): |
|---|
| 2643 | if getattr(self.request.principal, 'user_type', None) == 'student': |
|---|
| 2644 | self.flash(_('You are not allowed to remove bed tickets.'), |
|---|
| 2645 | type="warning") |
|---|
| 2646 | self.redirect(self.url(self.context)) |
|---|
| 2647 | return |
|---|
| 2648 | form = self.request.form |
|---|
| 2649 | if 'val_id' in form: |
|---|
| 2650 | child_id = form['val_id'] |
|---|
| 2651 | else: |
|---|
| 2652 | self.flash(_('No bed ticket selected.'), type="warning") |
|---|
| 2653 | self.redirect(self.url(self.context)) |
|---|
| 2654 | return |
|---|
| 2655 | if not isinstance(child_id, list): |
|---|
| 2656 | child_id = [child_id] |
|---|
| 2657 | deleted = [] |
|---|
| 2658 | for id in child_id: |
|---|
| 2659 | del self.context[id] |
|---|
| 2660 | deleted.append(id) |
|---|
| 2661 | if len(deleted): |
|---|
| 2662 | self.flash(_('Successfully removed: ${a}', |
|---|
| 2663 | mapping = {'a':', '.join(deleted)})) |
|---|
| 2664 | self.context.writeLogMessage( |
|---|
| 2665 | self,'removed: % s' % ', '.join(deleted)) |
|---|
| 2666 | self.redirect(self.url(self.context)) |
|---|
| 2667 | return |
|---|
| 2668 | |
|---|
| 2669 | class BedTicketAddPage(KofaPage): |
|---|
| 2670 | """ Page to add a bed ticket |
|---|
| 2671 | """ |
|---|
| 2672 | grok.context(IStudentAccommodation) |
|---|
| 2673 | grok.name('add') |
|---|
| 2674 | grok.require('waeup.handleAccommodation') |
|---|
| 2675 | #grok.template('enterpin') |
|---|
| 2676 | ac_prefix = 'HOS' |
|---|
| 2677 | label = _('Add bed ticket') |
|---|
| 2678 | pnav = 4 |
|---|
| 2679 | buttonname = _('Create bed ticket') |
|---|
| 2680 | notice = '' |
|---|
| 2681 | with_ac = True |
|---|
| 2682 | with_bedselection = True |
|---|
| 2683 | |
|---|
| 2684 | @property |
|---|
| 2685 | def getAvailableBeds(self): |
|---|
| 2686 | """Get a list of all available beds. |
|---|
| 2687 | """ |
|---|
| 2688 | cat = queryUtility(ICatalog, name='beds_catalog', default=None) |
|---|
| 2689 | entries = cat.searchResults( |
|---|
| 2690 | bed_type=(self.acc_details['bt'],self.acc_details['bt'])) |
|---|
| 2691 | available_beds = [ |
|---|
| 2692 | entry for entry in entries if entry.owner == NOT_OCCUPIED] |
|---|
| 2693 | desired_hostel = self.context.desired_hostel |
|---|
| 2694 | # Filter desired hostel beds |
|---|
| 2695 | if desired_hostel and desired_hostel != 'no': |
|---|
| 2696 | filtered_beds = [bed for bed in available_beds |
|---|
| 2697 | if bed.bed_id.split('_')[0] == desired_hostel] |
|---|
| 2698 | available_beds = filtered_beds |
|---|
| 2699 | # Add legible bed coordinates |
|---|
| 2700 | for bed in available_beds: |
|---|
| 2701 | hall_title = bed.__parent__.hostel_name |
|---|
| 2702 | coordinates = bed.coordinates[1:] |
|---|
| 2703 | block, room_nr, bed_nr = coordinates |
|---|
| 2704 | bed.temp_bed_coordinates = _( |
|---|
| 2705 | '${a}, Block ${b}, Room ${c}, Bed ${d}', mapping = { |
|---|
| 2706 | 'a':hall_title, 'b':block, |
|---|
| 2707 | 'c':room_nr, 'd':bed_nr}) |
|---|
| 2708 | return available_beds |
|---|
| 2709 | |
|---|
| 2710 | def update(self, SUBMIT=None): |
|---|
| 2711 | student = self.context.student |
|---|
| 2712 | students_utils = getUtility(IStudentsUtils) |
|---|
| 2713 | self.acc_details = students_utils.getAccommodationDetails(student) |
|---|
| 2714 | error_message = students_utils.checkAccommodationRequirements( |
|---|
| 2715 | student, self.acc_details) |
|---|
| 2716 | cat = queryUtility(ICatalog, name='beds_catalog', default=None) |
|---|
| 2717 | entries = cat.searchResults( |
|---|
| 2718 | owner=(student.student_id,student.student_id)) |
|---|
| 2719 | self.show_available_beds = False |
|---|
| 2720 | if error_message: |
|---|
| 2721 | self.flash(error_message, type="warning") |
|---|
| 2722 | self.redirect(self.url(self.context)) |
|---|
| 2723 | return |
|---|
| 2724 | if self.with_ac: |
|---|
| 2725 | self.ac_series = self.request.form.get('ac_series', None) |
|---|
| 2726 | self.ac_number = self.request.form.get('ac_number', None) |
|---|
| 2727 | available_beds = self.getAvailableBeds |
|---|
| 2728 | if SUBMIT is None: |
|---|
| 2729 | if self.with_bedselection and available_beds and not len(entries): |
|---|
| 2730 | self.show_available_beds = True |
|---|
| 2731 | return |
|---|
| 2732 | if self.with_ac: |
|---|
| 2733 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
|---|
| 2734 | code = get_access_code(pin) |
|---|
| 2735 | if not code: |
|---|
| 2736 | self.flash(_('Activation code is invalid.'), type="warning") |
|---|
| 2737 | return |
|---|
| 2738 | # Search and book bed |
|---|
| 2739 | if len(entries): |
|---|
| 2740 | # If bed space has been manually allocated use this bed ... |
|---|
| 2741 | manual = True |
|---|
| 2742 | bed = list(entries)[0] |
|---|
| 2743 | else: |
|---|
| 2744 | # ... else search for available beds |
|---|
| 2745 | manual = False |
|---|
| 2746 | selected_bed = self.request.form.get('bed', None) |
|---|
| 2747 | if selected_bed: |
|---|
| 2748 | # Use selected bed |
|---|
| 2749 | beds = cat.searchResults( |
|---|
| 2750 | bed_id=(selected_bed,selected_bed)) |
|---|
| 2751 | bed = list(beds)[0] |
|---|
| 2752 | bed.bookBed(student.student_id) |
|---|
| 2753 | elif available_beds: |
|---|
| 2754 | # Select bed according to selectBed method |
|---|
| 2755 | students_utils = getUtility(IStudentsUtils) |
|---|
| 2756 | bed = students_utils.selectBed(available_beds) |
|---|
| 2757 | bed.bookBed(student.student_id) |
|---|
| 2758 | else: |
|---|
| 2759 | self.flash(_('There is no free bed in your category ${a}.', |
|---|
| 2760 | mapping = {'a':self.acc_details['bt']}), type="warning") |
|---|
| 2761 | self.redirect(self.url(self.context)) |
|---|
| 2762 | return |
|---|
| 2763 | if self.with_ac: |
|---|
| 2764 | # Mark pin as used (this also fires a pin related transition) |
|---|
| 2765 | if code.state == USED: |
|---|
| 2766 | self.flash(_('Activation code has already been used.'), |
|---|
| 2767 | type="warning") |
|---|
| 2768 | if not manual: |
|---|
| 2769 | # Release the previously booked bed |
|---|
| 2770 | bed.owner = NOT_OCCUPIED |
|---|
| 2771 | # Catalog must be informed |
|---|
| 2772 | notify(grok.ObjectModifiedEvent(bed)) |
|---|
| 2773 | return |
|---|
| 2774 | else: |
|---|
| 2775 | comment = _(u'invalidated') |
|---|
| 2776 | # Here we know that the ac is in state initialized so we do not |
|---|
| 2777 | # expect an exception, but the owner might be different |
|---|
| 2778 | success = invalidate_accesscode( |
|---|
| 2779 | pin, comment, self.context.student.student_id) |
|---|
| 2780 | if not success: |
|---|
| 2781 | self.flash(_('You are not the owner of this access code.'), |
|---|
| 2782 | type="warning") |
|---|
| 2783 | if not manual: |
|---|
| 2784 | # Release the previously booked bed |
|---|
| 2785 | bed.owner = NOT_OCCUPIED |
|---|
| 2786 | # Catalog must be informed |
|---|
| 2787 | notify(grok.ObjectModifiedEvent(bed)) |
|---|
| 2788 | return |
|---|
| 2789 | # Create bed ticket |
|---|
| 2790 | bedticket = createObject(u'waeup.BedTicket') |
|---|
| 2791 | if self.with_ac: |
|---|
| 2792 | bedticket.booking_code = pin |
|---|
| 2793 | bedticket.booking_session = self.acc_details['booking_session'] |
|---|
| 2794 | bedticket.bed_type = self.acc_details['bt'] |
|---|
| 2795 | bedticket.bed = bed |
|---|
| 2796 | hall_title = bed.__parent__.hostel_name |
|---|
| 2797 | coordinates = bed.coordinates[1:] |
|---|
| 2798 | block, room_nr, bed_nr = coordinates |
|---|
| 2799 | bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = { |
|---|
| 2800 | 'a':hall_title, 'b':block, |
|---|
| 2801 | 'c':room_nr, 'd':bed_nr, |
|---|
| 2802 | 'e':bed.bed_type}) |
|---|
| 2803 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 2804 | bedticket.bed_coordinates = translate( |
|---|
| 2805 | bc, 'waeup.kofa',target_language=portal_language) |
|---|
| 2806 | self.context.addBedTicket(bedticket) |
|---|
| 2807 | self.context.writeLogMessage(self, 'booked: %s' % bed.bed_id) |
|---|
| 2808 | self.flash(_('Bed ticket created and bed booked: ${a}', |
|---|
| 2809 | mapping = {'a':bedticket.display_coordinates})) |
|---|
| 2810 | self.redirect(self.url(self.context)) |
|---|
| 2811 | return |
|---|
| 2812 | |
|---|
| 2813 | class BedTicketDisplayFormPage(KofaDisplayFormPage): |
|---|
| 2814 | """ Page to display bed tickets |
|---|
| 2815 | """ |
|---|
| 2816 | grok.context(IBedTicket) |
|---|
| 2817 | grok.name('index') |
|---|
| 2818 | grok.require('waeup.viewStudent') |
|---|
| 2819 | form_fields = grok.AutoFields(IBedTicket).omit('bed_coordinates') |
|---|
| 2820 | form_fields['booking_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 2821 | pnav = 4 |
|---|
| 2822 | |
|---|
| 2823 | @property |
|---|
| 2824 | def label(self): |
|---|
| 2825 | return _('Bed Ticket for Session ${a}', |
|---|
| 2826 | mapping = {'a':self.context.getSessionString()}) |
|---|
| 2827 | |
|---|
| 2828 | class ExportPDFBedTicketSlip(UtilityView, grok.View): |
|---|
| 2829 | """Deliver a PDF slip of the context. |
|---|
| 2830 | """ |
|---|
| 2831 | grok.context(IBedTicket) |
|---|
| 2832 | grok.name('bed_allocation_slip.pdf') |
|---|
| 2833 | grok.require('waeup.viewStudent') |
|---|
| 2834 | form_fields = grok.AutoFields(IBedTicket).omit('bed_coordinates') |
|---|
| 2835 | form_fields['booking_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 2836 | prefix = 'form' |
|---|
| 2837 | omit_fields = ( |
|---|
| 2838 | 'password', 'suspended', 'phone', 'adm_code', |
|---|
| 2839 | 'suspended_comment', 'date_of_birth', 'current_level', |
|---|
| 2840 | 'flash_notice') |
|---|
| 2841 | |
|---|
| 2842 | @property |
|---|
| 2843 | def title(self): |
|---|
| 2844 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 2845 | return translate(_('Bed Allocation Data'), 'waeup.kofa', |
|---|
| 2846 | target_language=portal_language) |
|---|
| 2847 | |
|---|
| 2848 | @property |
|---|
| 2849 | def label(self): |
|---|
| 2850 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 2851 | #return translate(_('Bed Allocation: '), |
|---|
| 2852 | # 'waeup.kofa', target_language=portal_language) \ |
|---|
| 2853 | # + ' %s' % self.context.bed_coordinates |
|---|
| 2854 | return translate(_('Bed Allocation Slip'), |
|---|
| 2855 | 'waeup.kofa', target_language=portal_language) \ |
|---|
| 2856 | + ' %s' % self.context.getSessionString() |
|---|
| 2857 | |
|---|
| 2858 | def render(self): |
|---|
| 2859 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 2860 | self.request, self.omit_fields) |
|---|
| 2861 | students_utils = getUtility(IStudentsUtils) |
|---|
| 2862 | note = None |
|---|
| 2863 | n = grok.getSite()['hostels'].allocation_expiration |
|---|
| 2864 | if n: |
|---|
| 2865 | note = _(""" |
|---|
| 2866 | <br /><br /><br /><br /><br /><font size="12"> |
|---|
| 2867 | Please endeavour to pay your hostel maintenance charge within ${a} days |
|---|
| 2868 | of being allocated a space or else you are deemed to have |
|---|
| 2869 | voluntarily forfeited it and it goes back into circulation to be |
|---|
| 2870 | available for booking afresh!</font>) |
|---|
| 2871 | """) |
|---|
| 2872 | note = _(note, mapping={'a': n}) |
|---|
| 2873 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 2874 | note = translate( |
|---|
| 2875 | note, 'waeup.kofa', target_language=portal_language) |
|---|
| 2876 | return students_utils.renderPDF( |
|---|
| 2877 | self, 'bed_allocation_slip.pdf', |
|---|
| 2878 | self.context.student, studentview, |
|---|
| 2879 | omit_fields=self.omit_fields, |
|---|
| 2880 | note=note) |
|---|
| 2881 | |
|---|
| 2882 | class BedTicketRelocationView(UtilityView, grok.View): |
|---|
| 2883 | """ Callback view |
|---|
| 2884 | """ |
|---|
| 2885 | grok.context(IBedTicket) |
|---|
| 2886 | grok.name('relocate') |
|---|
| 2887 | grok.require('waeup.manageHostels') |
|---|
| 2888 | |
|---|
| 2889 | # Relocate student if student parameters have changed or the bed_type |
|---|
| 2890 | # of the bed has changed |
|---|
| 2891 | def update(self): |
|---|
| 2892 | success, msg = self.context.relocateStudent() |
|---|
| 2893 | if not success: |
|---|
| 2894 | self.flash(msg, type="warning") |
|---|
| 2895 | else: |
|---|
| 2896 | self.flash(msg) |
|---|
| 2897 | self.redirect(self.url(self.context)) |
|---|
| 2898 | return |
|---|
| 2899 | |
|---|
| 2900 | def render(self): |
|---|
| 2901 | return |
|---|
| 2902 | |
|---|
| 2903 | class StudentHistoryPage(KofaPage): |
|---|
| 2904 | """ Page to display student history |
|---|
| 2905 | """ |
|---|
| 2906 | grok.context(IStudent) |
|---|
| 2907 | grok.name('history') |
|---|
| 2908 | grok.require('waeup.viewStudent') |
|---|
| 2909 | grok.template('studenthistory') |
|---|
| 2910 | pnav = 4 |
|---|
| 2911 | |
|---|
| 2912 | @property |
|---|
| 2913 | def label(self): |
|---|
| 2914 | return _('${a}: History', mapping = {'a':self.context.display_fullname}) |
|---|
| 2915 | |
|---|
| 2916 | # Pages for students only |
|---|
| 2917 | |
|---|
| 2918 | class StudentBaseEditFormPage(KofaEditFormPage): |
|---|
| 2919 | """ View to edit student base data |
|---|
| 2920 | """ |
|---|
| 2921 | grok.context(IStudent) |
|---|
| 2922 | grok.name('edit_base') |
|---|
| 2923 | grok.require('waeup.handleStudent') |
|---|
| 2924 | form_fields = grok.AutoFields(IStudentBase).select( |
|---|
| 2925 | 'email', 'phone', 'parents_email') |
|---|
| 2926 | label = _('Edit base data') |
|---|
| 2927 | pnav = 4 |
|---|
| 2928 | |
|---|
| 2929 | @action(_('Save'), style='primary') |
|---|
| 2930 | def save(self, **data): |
|---|
| 2931 | msave(self, **data) |
|---|
| 2932 | return |
|---|
| 2933 | |
|---|
| 2934 | class StudentChangePasswordPage(KofaEditFormPage): |
|---|
| 2935 | """ View to edit student passwords |
|---|
| 2936 | """ |
|---|
| 2937 | grok.context(IStudent) |
|---|
| 2938 | grok.name('change_password') |
|---|
| 2939 | grok.require('waeup.handleStudent') |
|---|
| 2940 | grok.template('change_password') |
|---|
| 2941 | label = _('Change password') |
|---|
| 2942 | pnav = 4 |
|---|
| 2943 | |
|---|
| 2944 | @action(_('Save'), style='primary') |
|---|
| 2945 | def save(self, **data): |
|---|
| 2946 | form = self.request.form |
|---|
| 2947 | password = form.get('change_password', None) |
|---|
| 2948 | password_ctl = form.get('change_password_repeat', None) |
|---|
| 2949 | if password: |
|---|
| 2950 | validator = getUtility(IPasswordValidator) |
|---|
| 2951 | errors = validator.validate_password(password, password_ctl) |
|---|
| 2952 | if not errors: |
|---|
| 2953 | IUserAccount(self.context).setPassword(password) |
|---|
| 2954 | # Unset temporary password |
|---|
| 2955 | self.context.temp_password = None |
|---|
| 2956 | self.context.writeLogMessage(self, 'saved: password') |
|---|
| 2957 | self.flash(_('Password changed.')) |
|---|
| 2958 | else: |
|---|
| 2959 | self.flash( ' '.join(errors), type="warning") |
|---|
| 2960 | return |
|---|
| 2961 | |
|---|
| 2962 | class StudentFilesUploadPage(KofaPage): |
|---|
| 2963 | """ View to upload passport picture by student. The class name |
|---|
| 2964 | is historical. The page is only used for the student's portrait. |
|---|
| 2965 | """ |
|---|
| 2966 | grok.context(IStudent) |
|---|
| 2967 | grok.name('change_portrait') |
|---|
| 2968 | grok.require('waeup.uploadStudentFile') |
|---|
| 2969 | grok.template('filesuploadpage') |
|---|
| 2970 | label = _('Upload portrait') |
|---|
| 2971 | pnav = 4 |
|---|
| 2972 | |
|---|
| 2973 | def update(self): |
|---|
| 2974 | if not getUtility(IStudentsUtils).allowPortraitChange(self.context): |
|---|
| 2975 | emit_lock_message(self, |
|---|
| 2976 | _('The requested form is locked.')) |
|---|
| 2977 | return |
|---|
| 2978 | super(StudentFilesUploadPage, self).update() |
|---|
| 2979 | return |
|---|
| 2980 | |
|---|
| 2981 | class StudentSignatureUploadPage(KofaPage): |
|---|
| 2982 | """ View to upload scanned signature by student. Not active |
|---|
| 2983 | in base package. |
|---|
| 2984 | """ |
|---|
| 2985 | grok.context(IStudent) |
|---|
| 2986 | grok.name('change_signature') |
|---|
| 2987 | grok.require('waeup.uploadStudentFile') |
|---|
| 2988 | grok.template('filesuploadpage') |
|---|
| 2989 | label = _('Upload signature') |
|---|
| 2990 | pnav = 4 |
|---|
| 2991 | |
|---|
| 2992 | def update(self): |
|---|
| 2993 | SIGNATURE_CHANGE_STATES = getUtility(IStudentsUtils).SIGNATURE_CHANGE_STATES |
|---|
| 2994 | if self.context.student.state not in SIGNATURE_CHANGE_STATES: |
|---|
| 2995 | emit_lock_message(self, |
|---|
| 2996 | _('This form is locked. You are in the wrong state.')) |
|---|
| 2997 | return |
|---|
| 2998 | super(StudentSignatureUploadPage, self).update() |
|---|
| 2999 | return |
|---|
| 3000 | |
|---|
| 3001 | class StudentFinalClearanceUploadPage(KofaPage): |
|---|
| 3002 | """View to upload scanned final clearance routing slip by student. Not active |
|---|
| 3003 | in base package. |
|---|
| 3004 | """ |
|---|
| 3005 | grok.context(IStudent) |
|---|
| 3006 | grok.name('routing_slip_upload') |
|---|
| 3007 | grok.require('waeup.uploadStudentFile') |
|---|
| 3008 | grok.template('finalclearanceuploadpage') |
|---|
| 3009 | label = _('Upload final clearance routing slip') |
|---|
| 3010 | deletion_warning = _('Are you sure?') |
|---|
| 3011 | pnav = 4 |
|---|
| 3012 | |
|---|
| 3013 | def update(self): |
|---|
| 3014 | final_clearance_enabled = getUtility( |
|---|
| 3015 | IStudentsUtils).final_clearance_enabled(self.context) |
|---|
| 3016 | if not final_clearance_enabled: |
|---|
| 3017 | emit_lock_message(self, |
|---|
| 3018 | _('This form is locked.')) |
|---|
| 3019 | return |
|---|
| 3020 | super(StudentFinalClearanceUploadPage, self).update() |
|---|
| 3021 | return |
|---|
| 3022 | |
|---|
| 3023 | class ExportPDFFinalClearanceSlip(UtilityView, grok.View): |
|---|
| 3024 | """Deliver a PDF document. |
|---|
| 3025 | """ |
|---|
| 3026 | grok.context(IStudent) |
|---|
| 3027 | grok.name('final_clearance_slip.pdf') |
|---|
| 3028 | grok.require('waeup.viewStudent') |
|---|
| 3029 | prefix = 'form' |
|---|
| 3030 | form_fields = None |
|---|
| 3031 | |
|---|
| 3032 | omit_fields = ( |
|---|
| 3033 | 'suspended', |
|---|
| 3034 | 'adm_code', |
|---|
| 3035 | 'suspended_comment', |
|---|
| 3036 | 'current_level', |
|---|
| 3037 | 'flash_notice', |
|---|
| 3038 | 'entry_session', |
|---|
| 3039 | 'parents_email', |
|---|
| 3040 | 'email', |
|---|
| 3041 | 'phone', |
|---|
| 3042 | 'date_of_birth', |
|---|
| 3043 | 'sex',) |
|---|
| 3044 | |
|---|
| 3045 | @property |
|---|
| 3046 | def label(self): |
|---|
| 3047 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 3048 | return translate(_('Final Document Upload Indicator Slip'), 'waeup.kofa', |
|---|
| 3049 | target_language=portal_language) |
|---|
| 3050 | |
|---|
| 3051 | def render(self): |
|---|
| 3052 | final_slip = getUtility(IExtFileStore).getFileByContext( |
|---|
| 3053 | self.context.student, attr='routingslip.pdf') |
|---|
| 3054 | if not final_slip: |
|---|
| 3055 | emit_lock_message(self, |
|---|
| 3056 | _('The requested form is locked.')) |
|---|
| 3057 | return |
|---|
| 3058 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 3059 | self.request, self.omit_fields) |
|---|
| 3060 | students_utils = getUtility(IStudentsUtils) |
|---|
| 3061 | note = _(''' |
|---|
| 3062 | The final clearance routing slip has been successfully uploaded onto the Kofa portal. |
|---|
| 3063 | |
|---|
| 3064 | Take this slip to the Exams and Records Division for the collection of Statement of Results. |
|---|
| 3065 | |
|---|
| 3066 | Exams and Records Division will send notification for date of collection. |
|---|
| 3067 | ''') |
|---|
| 3068 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 3069 | note = translate( |
|---|
| 3070 | note, 'waeup.kofa', target_language=portal_language) |
|---|
| 3071 | return students_utils.renderPDF( |
|---|
| 3072 | self, 'final_clearance_slip_%s.pdf' % self.context.student.student_id, |
|---|
| 3073 | self.context.student, studentview, |
|---|
| 3074 | omit_fields=self.omit_fields, |
|---|
| 3075 | note=note) |
|---|
| 3076 | |
|---|
| 3077 | class StartClearancePage(KofaPage): |
|---|
| 3078 | grok.context(IStudent) |
|---|
| 3079 | grok.name('start_clearance') |
|---|
| 3080 | grok.require('waeup.handleStudent') |
|---|
| 3081 | grok.template('enterpin') |
|---|
| 3082 | label = _('Start clearance') |
|---|
| 3083 | ac_prefix = 'CLR' |
|---|
| 3084 | notice = '' |
|---|
| 3085 | pnav = 4 |
|---|
| 3086 | buttonname = _('Start clearance now') |
|---|
| 3087 | with_ac = True |
|---|
| 3088 | |
|---|
| 3089 | @property |
|---|
| 3090 | def all_required_fields_filled(self): |
|---|
| 3091 | if not self.context.email: |
|---|
| 3092 | return _("Email address is missing."), 'edit_base' |
|---|
| 3093 | if not self.context.phone: |
|---|
| 3094 | return _("Phone number is missing."), 'edit_base' |
|---|
| 3095 | return |
|---|
| 3096 | |
|---|
| 3097 | @property |
|---|
| 3098 | def portrait_uploaded(self): |
|---|
| 3099 | store = getUtility(IExtFileStore) |
|---|
| 3100 | if store.getFileByContext(self.context, attr=u'passport.jpg'): |
|---|
| 3101 | return True |
|---|
| 3102 | return False |
|---|
| 3103 | |
|---|
| 3104 | def update(self, SUBMIT=None): |
|---|
| 3105 | if not self.context.state == ADMITTED: |
|---|
| 3106 | self.flash(_("Wrong state"), type="warning") |
|---|
| 3107 | self.redirect(self.url(self.context)) |
|---|
| 3108 | return |
|---|
| 3109 | if not self.portrait_uploaded: |
|---|
| 3110 | self.flash(_("No portrait uploaded."), type="warning") |
|---|
| 3111 | self.redirect(self.url(self.context, 'change_portrait')) |
|---|
| 3112 | return |
|---|
| 3113 | if self.all_required_fields_filled: |
|---|
| 3114 | arf_warning = self.all_required_fields_filled[0] |
|---|
| 3115 | arf_redirect = self.all_required_fields_filled[1] |
|---|
| 3116 | self.flash(arf_warning, type="warning") |
|---|
| 3117 | self.redirect(self.url(self.context, arf_redirect)) |
|---|
| 3118 | return |
|---|
| 3119 | if self.with_ac: |
|---|
| 3120 | self.ac_series = self.request.form.get('ac_series', None) |
|---|
| 3121 | self.ac_number = self.request.form.get('ac_number', None) |
|---|
| 3122 | if SUBMIT is None: |
|---|
| 3123 | return |
|---|
| 3124 | if self.with_ac: |
|---|
| 3125 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
|---|
| 3126 | code = get_access_code(pin) |
|---|
| 3127 | if not code: |
|---|
| 3128 | self.flash(_('Activation code is invalid.'), type="warning") |
|---|
| 3129 | return |
|---|
| 3130 | if code.state == USED: |
|---|
| 3131 | self.flash(_('Activation code has already been used.'), |
|---|
| 3132 | type="warning") |
|---|
| 3133 | return |
|---|
| 3134 | # Mark pin as used (this also fires a pin related transition) |
|---|
| 3135 | # and fire transition start_clearance |
|---|
| 3136 | comment = _(u"invalidated") |
|---|
| 3137 | # Here we know that the ac is in state initialized so we do not |
|---|
| 3138 | # expect an exception, but the owner might be different |
|---|
| 3139 | if not invalidate_accesscode(pin, comment, self.context.student_id): |
|---|
| 3140 | self.flash(_('You are not the owner of this access code.'), |
|---|
| 3141 | type="warning") |
|---|
| 3142 | return |
|---|
| 3143 | self.context.clr_code = pin |
|---|
| 3144 | IWorkflowInfo(self.context).fireTransition('start_clearance') |
|---|
| 3145 | self.flash(_('Clearance process has been started.')) |
|---|
| 3146 | self.redirect(self.url(self.context,'cedit')) |
|---|
| 3147 | return |
|---|
| 3148 | |
|---|
| 3149 | class StudentClearanceEditFormPage(StudentClearanceManageFormPage): |
|---|
| 3150 | """ View to edit student clearance data by student |
|---|
| 3151 | """ |
|---|
| 3152 | grok.context(IStudent) |
|---|
| 3153 | grok.name('cedit') |
|---|
| 3154 | grok.require('waeup.handleStudent') |
|---|
| 3155 | label = _('Edit clearance data') |
|---|
| 3156 | |
|---|
| 3157 | @property |
|---|
| 3158 | def form_fields(self): |
|---|
| 3159 | if self.context.is_postgrad: |
|---|
| 3160 | form_fields = grok.AutoFields(IPGStudentClearance).omit( |
|---|
| 3161 | 'clr_code', 'officer_comment') |
|---|
| 3162 | else: |
|---|
| 3163 | form_fields = grok.AutoFields(IUGStudentClearance).omit( |
|---|
| 3164 | 'clr_code', 'officer_comment') |
|---|
| 3165 | return form_fields |
|---|
| 3166 | |
|---|
| 3167 | def update(self): |
|---|
| 3168 | if self.context.clearance_locked: |
|---|
| 3169 | emit_lock_message(self) |
|---|
| 3170 | return |
|---|
| 3171 | return super(StudentClearanceEditFormPage, self).update() |
|---|
| 3172 | |
|---|
| 3173 | @action(_('Save'), style='primary') |
|---|
| 3174 | def save(self, **data): |
|---|
| 3175 | self.applyData(self.context, **data) |
|---|
| 3176 | self.flash(_('Clearance form has been saved.')) |
|---|
| 3177 | return |
|---|
| 3178 | |
|---|
| 3179 | def dataNotComplete(self): |
|---|
| 3180 | """To be implemented in the customization package. |
|---|
| 3181 | """ |
|---|
| 3182 | return False |
|---|
| 3183 | |
|---|
| 3184 | @action(_('Save and request clearance'), style='primary', |
|---|
| 3185 | warning=_('You can not edit your data after ' |
|---|
| 3186 | 'requesting clearance. You really want to request clearance now?')) |
|---|
| 3187 | def requestClearance(self, **data): |
|---|
| 3188 | self.applyData(self.context, **data) |
|---|
| 3189 | if self.dataNotComplete(): |
|---|
| 3190 | self.flash(self.dataNotComplete(), type="warning") |
|---|
| 3191 | return |
|---|
| 3192 | self.flash(_('Clearance form has been saved.')) |
|---|
| 3193 | if self.context.clr_code: |
|---|
| 3194 | self.redirect(self.url(self.context, 'request_clearance')) |
|---|
| 3195 | else: |
|---|
| 3196 | # We bypass the request_clearance page if student |
|---|
| 3197 | # has been imported in state 'clearance started' and |
|---|
| 3198 | # no clr_code was entered before. |
|---|
| 3199 | state = IWorkflowState(self.context).getState() |
|---|
| 3200 | if state != CLEARANCE: |
|---|
| 3201 | # This shouldn't happen, but the application officer |
|---|
| 3202 | # might have forgotten to lock the form after changing the state |
|---|
| 3203 | self.flash(_('This form cannot be submitted. Wrong state!'), |
|---|
| 3204 | type="danger") |
|---|
| 3205 | return |
|---|
| 3206 | IWorkflowInfo(self.context).fireTransition('request_clearance') |
|---|
| 3207 | self.flash(_('Clearance has been requested.')) |
|---|
| 3208 | self.redirect(self.url(self.context)) |
|---|
| 3209 | return |
|---|
| 3210 | |
|---|
| 3211 | class RequestClearancePage(KofaPage): |
|---|
| 3212 | grok.context(IStudent) |
|---|
| 3213 | grok.name('request_clearance') |
|---|
| 3214 | grok.require('waeup.handleStudent') |
|---|
| 3215 | grok.template('enterpin') |
|---|
| 3216 | label = _('Request clearance') |
|---|
| 3217 | notice = _('Enter the CLR access code used for starting clearance.') |
|---|
| 3218 | ac_prefix = 'CLR' |
|---|
| 3219 | pnav = 4 |
|---|
| 3220 | buttonname = _('Request clearance now') |
|---|
| 3221 | with_ac = True |
|---|
| 3222 | |
|---|
| 3223 | def update(self, SUBMIT=None): |
|---|
| 3224 | if self.with_ac: |
|---|
| 3225 | self.ac_series = self.request.form.get('ac_series', None) |
|---|
| 3226 | self.ac_number = self.request.form.get('ac_number', None) |
|---|
| 3227 | if SUBMIT is None: |
|---|
| 3228 | return |
|---|
| 3229 | if self.with_ac: |
|---|
| 3230 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
|---|
| 3231 | if self.context.clr_code and self.context.clr_code != pin: |
|---|
| 3232 | self.flash(_("This isn't your CLR access code."), type="danger") |
|---|
| 3233 | return |
|---|
| 3234 | state = IWorkflowState(self.context).getState() |
|---|
| 3235 | if state != CLEARANCE: |
|---|
| 3236 | # This shouldn't happen, but the application officer |
|---|
| 3237 | # might have forgotten to lock the form after changing the state |
|---|
| 3238 | self.flash(_('This form cannot be submitted. Wrong state!'), |
|---|
| 3239 | type="danger") |
|---|
| 3240 | return |
|---|
| 3241 | IWorkflowInfo(self.context).fireTransition('request_clearance') |
|---|
| 3242 | self.flash(_('Clearance has been requested.')) |
|---|
| 3243 | self.redirect(self.url(self.context)) |
|---|
| 3244 | return |
|---|
| 3245 | |
|---|
| 3246 | class StartSessionPage(KofaPage): |
|---|
| 3247 | grok.context(IStudentStudyCourse) |
|---|
| 3248 | grok.name('start_session') |
|---|
| 3249 | grok.require('waeup.handleStudent') |
|---|
| 3250 | grok.template('enterpin') |
|---|
| 3251 | label = _('Start session') |
|---|
| 3252 | ac_prefix = 'SFE' |
|---|
| 3253 | notice = '' |
|---|
| 3254 | pnav = 4 |
|---|
| 3255 | buttonname = _('Start now') |
|---|
| 3256 | with_ac = True |
|---|
| 3257 | |
|---|
| 3258 | def update(self, SUBMIT=None): |
|---|
| 3259 | if not self.context.is_current: |
|---|
| 3260 | emit_lock_message(self) |
|---|
| 3261 | return |
|---|
| 3262 | super(StartSessionPage, self).update() |
|---|
| 3263 | if not self.context.next_session_allowed: |
|---|
| 3264 | self.flash(_("You are not entitled to start session."), |
|---|
| 3265 | type="warning") |
|---|
| 3266 | self.redirect(self.url(self.context)) |
|---|
| 3267 | return |
|---|
| 3268 | if self.with_ac: |
|---|
| 3269 | self.ac_series = self.request.form.get('ac_series', None) |
|---|
| 3270 | self.ac_number = self.request.form.get('ac_number', None) |
|---|
| 3271 | if SUBMIT is None: |
|---|
| 3272 | return |
|---|
| 3273 | if self.with_ac: |
|---|
| 3274 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
|---|
| 3275 | code = get_access_code(pin) |
|---|
| 3276 | if not code: |
|---|
| 3277 | self.flash(_('Activation code is invalid.'), type="warning") |
|---|
| 3278 | return |
|---|
| 3279 | # Mark pin as used (this also fires a pin related transition) |
|---|
| 3280 | if code.state == USED: |
|---|
| 3281 | self.flash(_('Activation code has already been used.'), |
|---|
| 3282 | type="warning") |
|---|
| 3283 | return |
|---|
| 3284 | else: |
|---|
| 3285 | comment = _(u"invalidated") |
|---|
| 3286 | # Here we know that the ac is in state initialized so we do not |
|---|
| 3287 | # expect an error, but the owner might be different |
|---|
| 3288 | if not invalidate_accesscode( |
|---|
| 3289 | pin,comment,self.context.student.student_id): |
|---|
| 3290 | self.flash(_('You are not the owner of this access code.'), |
|---|
| 3291 | type="warning") |
|---|
| 3292 | return |
|---|
| 3293 | try: |
|---|
| 3294 | if self.context.student.state == CLEARED: |
|---|
| 3295 | IWorkflowInfo(self.context.student).fireTransition( |
|---|
| 3296 | 'pay_first_school_fee') |
|---|
| 3297 | elif self.context.student.state == RETURNING: |
|---|
| 3298 | IWorkflowInfo(self.context.student).fireTransition( |
|---|
| 3299 | 'pay_school_fee') |
|---|
| 3300 | elif self.context.student.state == PAID: |
|---|
| 3301 | IWorkflowInfo(self.context.student).fireTransition( |
|---|
| 3302 | 'pay_pg_fee') |
|---|
| 3303 | except ConstraintNotSatisfied: |
|---|
| 3304 | self.flash(_('An error occurred, please contact the system administrator.'), |
|---|
| 3305 | type="danger") |
|---|
| 3306 | return |
|---|
| 3307 | self.flash(_('Session started.')) |
|---|
| 3308 | self.redirect(self.url(self.context)) |
|---|
| 3309 | return |
|---|
| 3310 | |
|---|
| 3311 | class AddStudyLevelFormPage(KofaEditFormPage): |
|---|
| 3312 | """ Page for students to add current study levels |
|---|
| 3313 | """ |
|---|
| 3314 | grok.context(IStudentStudyCourse) |
|---|
| 3315 | grok.name('add') |
|---|
| 3316 | grok.require('waeup.handleStudent') |
|---|
| 3317 | grok.template('studyleveladdpage') |
|---|
| 3318 | form_fields = grok.AutoFields(IStudentStudyCourse) |
|---|
| 3319 | pnav = 4 |
|---|
| 3320 | |
|---|
| 3321 | @property |
|---|
| 3322 | def label(self): |
|---|
| 3323 | studylevelsource = StudyLevelSource().factory |
|---|
| 3324 | code = self.context.current_level |
|---|
| 3325 | title = studylevelsource.getTitle(self.context, code) |
|---|
| 3326 | return _('Add current level ${a}', mapping = {'a':title}) |
|---|
| 3327 | |
|---|
| 3328 | def update(self): |
|---|
| 3329 | if not self.context.is_current \ |
|---|
| 3330 | or self.context.student.studycourse_locked: |
|---|
| 3331 | emit_lock_message(self) |
|---|
| 3332 | return |
|---|
| 3333 | if self.context.student.state != PAID: |
|---|
| 3334 | emit_lock_message(self) |
|---|
| 3335 | return |
|---|
| 3336 | code = self.context.current_level |
|---|
| 3337 | if code is None: |
|---|
| 3338 | self.flash(_('Your data are incomplete'), type="danger") |
|---|
| 3339 | self.redirect(self.url(self.context)) |
|---|
| 3340 | return |
|---|
| 3341 | super(AddStudyLevelFormPage, self).update() |
|---|
| 3342 | return |
|---|
| 3343 | |
|---|
| 3344 | @action(_('Create course list now'), style='primary') |
|---|
| 3345 | def addStudyLevel(self, **data): |
|---|
| 3346 | studylevel = createObject(u'waeup.StudentStudyLevel') |
|---|
| 3347 | studylevel.level = self.context.current_level |
|---|
| 3348 | studylevel.level_session = self.context.current_session |
|---|
| 3349 | try: |
|---|
| 3350 | self.context.addStudentStudyLevel( |
|---|
| 3351 | self.context.certificate,studylevel) |
|---|
| 3352 | except KeyError: |
|---|
| 3353 | self.flash(_('This level exists.'), type="warning") |
|---|
| 3354 | self.redirect(self.url(self.context)) |
|---|
| 3355 | return |
|---|
| 3356 | except RequiredMissing: |
|---|
| 3357 | self.flash(_('Your data are incomplete.'), type="danger") |
|---|
| 3358 | self.redirect(self.url(self.context)) |
|---|
| 3359 | return |
|---|
| 3360 | self.flash(_('You successfully created a new course list.')) |
|---|
| 3361 | self.redirect(self.url(self.context, str(studylevel.level))) |
|---|
| 3362 | return |
|---|
| 3363 | |
|---|
| 3364 | class StudyLevelEditFormPage(KofaEditFormPage): |
|---|
| 3365 | """ Page to edit the student study level data by students |
|---|
| 3366 | """ |
|---|
| 3367 | grok.context(IStudentStudyLevel) |
|---|
| 3368 | grok.name('edit') |
|---|
| 3369 | grok.require('waeup.editStudyLevel') |
|---|
| 3370 | grok.template('studyleveleditpage') |
|---|
| 3371 | pnav = 4 |
|---|
| 3372 | placeholder = _('Enter valid course code') |
|---|
| 3373 | |
|---|
| 3374 | def update(self, ADD=None, course=None): |
|---|
| 3375 | if not self.context.__parent__.is_current: |
|---|
| 3376 | emit_lock_message(self) |
|---|
| 3377 | return |
|---|
| 3378 | if self.context.student.state != PAID or \ |
|---|
| 3379 | not self.context.is_current_level: |
|---|
| 3380 | emit_lock_message(self) |
|---|
| 3381 | return |
|---|
| 3382 | super(StudyLevelEditFormPage, self).update() |
|---|
| 3383 | if ADD is not None: |
|---|
| 3384 | if not course: |
|---|
| 3385 | self.flash(_('No valid course code entered.'), type="warning") |
|---|
| 3386 | return |
|---|
| 3387 | cat = queryUtility(ICatalog, name='courses_catalog') |
|---|
| 3388 | result = cat.searchResults(code=(course, course)) |
|---|
| 3389 | if len(result) != 1: |
|---|
| 3390 | self.flash(_('Course not found.'), type="warning") |
|---|
| 3391 | return |
|---|
| 3392 | course = list(result)[0] |
|---|
| 3393 | if course.former_course: |
|---|
| 3394 | self.flash(_('Former courses can\'t be added.'), type="warning") |
|---|
| 3395 | return |
|---|
| 3396 | addCourseTicket(self, course) |
|---|
| 3397 | return |
|---|
| 3398 | |
|---|
| 3399 | @property |
|---|
| 3400 | def label(self): |
|---|
| 3401 | # Here we know that the cookie has been set |
|---|
| 3402 | lang = self.request.cookies.get('kofa.language') |
|---|
| 3403 | level_title = translate(self.context.level_title, 'waeup.kofa', |
|---|
| 3404 | target_language=lang) |
|---|
| 3405 | return _('Edit course list of ${a}', |
|---|
| 3406 | mapping = {'a':level_title}) |
|---|
| 3407 | |
|---|
| 3408 | @property |
|---|
| 3409 | def translated_values(self): |
|---|
| 3410 | return translated_values(self) |
|---|
| 3411 | |
|---|
| 3412 | def _delCourseTicket(self, **data): |
|---|
| 3413 | form = self.request.form |
|---|
| 3414 | if 'val_id' in form: |
|---|
| 3415 | child_id = form['val_id'] |
|---|
| 3416 | else: |
|---|
| 3417 | self.flash(_('No ticket selected.'), type="warning") |
|---|
| 3418 | self.redirect(self.url(self.context, '@@edit')) |
|---|
| 3419 | return |
|---|
| 3420 | if not isinstance(child_id, list): |
|---|
| 3421 | child_id = [child_id] |
|---|
| 3422 | deleted = [] |
|---|
| 3423 | for id in child_id: |
|---|
| 3424 | # Students are not allowed to remove core tickets |
|---|
| 3425 | if id in self.context and \ |
|---|
| 3426 | self.context[id].removable_by_student: |
|---|
| 3427 | del self.context[id] |
|---|
| 3428 | deleted.append(id) |
|---|
| 3429 | if len(deleted): |
|---|
| 3430 | self.flash(_('Successfully removed: ${a}', |
|---|
| 3431 | mapping = {'a':', '.join(deleted)})) |
|---|
| 3432 | self.context.writeLogMessage( |
|---|
| 3433 | self,'removed: %s at %s' % |
|---|
| 3434 | (', '.join(deleted), self.context.level)) |
|---|
| 3435 | self.redirect(self.url(self.context, u'@@edit')) |
|---|
| 3436 | return |
|---|
| 3437 | |
|---|
| 3438 | @jsaction(_('Remove selected tickets')) |
|---|
| 3439 | def delCourseTicket(self, **data): |
|---|
| 3440 | self._delCourseTicket(**data) |
|---|
| 3441 | return |
|---|
| 3442 | |
|---|
| 3443 | def _updateTickets(self, **data): |
|---|
| 3444 | cat = queryUtility(ICatalog, name='courses_catalog') |
|---|
| 3445 | invalidated = list() |
|---|
| 3446 | for value in self.context.values(): |
|---|
| 3447 | result = cat.searchResults(code=(value.code, value.code)) |
|---|
| 3448 | if len(result) != 1: |
|---|
| 3449 | course = None |
|---|
| 3450 | else: |
|---|
| 3451 | course = list(result)[0] |
|---|
| 3452 | invalid = self.context.updateCourseTicket(value, course) |
|---|
| 3453 | if invalid: |
|---|
| 3454 | invalidated.append(invalid) |
|---|
| 3455 | if invalidated: |
|---|
| 3456 | invalidated_string = ', '.join(invalidated) |
|---|
| 3457 | self.context.writeLogMessage( |
|---|
| 3458 | self, 'course tickets invalidated: %s' % invalidated_string) |
|---|
| 3459 | self.flash(_('All course tickets updated.')) |
|---|
| 3460 | return |
|---|
| 3461 | |
|---|
| 3462 | @action(_('Update all tickets'), |
|---|
| 3463 | tooltip=_('Update all course parameters including course titles.')) |
|---|
| 3464 | def updateTickets(self, **data): |
|---|
| 3465 | self._updateTickets(**data) |
|---|
| 3466 | return |
|---|
| 3467 | |
|---|
| 3468 | def _registerCourses(self, **data): |
|---|
| 3469 | if self.context.student.is_postgrad and \ |
|---|
| 3470 | not self.context.student.is_special_postgrad: |
|---|
| 3471 | self.flash(_( |
|---|
| 3472 | "You are a postgraduate student, " |
|---|
| 3473 | "your course list can't bee registered."), type="warning") |
|---|
| 3474 | self.redirect(self.url(self.context)) |
|---|
| 3475 | return |
|---|
| 3476 | students_utils = getUtility(IStudentsUtils) |
|---|
| 3477 | warning = students_utils.warnCreditsOOR(self.context) |
|---|
| 3478 | if warning: |
|---|
| 3479 | self.flash(warning, type="warning") |
|---|
| 3480 | return |
|---|
| 3481 | msg = self.context.course_registration_forbidden |
|---|
| 3482 | if msg: |
|---|
| 3483 | self.flash(msg, type="warning") |
|---|
| 3484 | return |
|---|
| 3485 | IWorkflowInfo(self.context.student).fireTransition( |
|---|
| 3486 | 'register_courses') |
|---|
| 3487 | self.flash(_('Course list has been registered.')) |
|---|
| 3488 | self.redirect(self.url(self.context)) |
|---|
| 3489 | return |
|---|
| 3490 | |
|---|
| 3491 | @action(_('Register course list'), style='primary', |
|---|
| 3492 | warning=_('You can not edit your course list after registration.' |
|---|
| 3493 | ' You really want to register?')) |
|---|
| 3494 | def registerCourses(self, **data): |
|---|
| 3495 | self._registerCourses(**data) |
|---|
| 3496 | return |
|---|
| 3497 | |
|---|
| 3498 | class CourseTicketAddFormPage2(CourseTicketAddFormPage): |
|---|
| 3499 | """Add a course ticket by student. |
|---|
| 3500 | """ |
|---|
| 3501 | grok.name('ctadd') |
|---|
| 3502 | grok.require('waeup.handleStudent') |
|---|
| 3503 | form_fields = grok.AutoFields(ICourseTicketAdd) |
|---|
| 3504 | |
|---|
| 3505 | def update(self): |
|---|
| 3506 | if self.context.student.state != PAID or \ |
|---|
| 3507 | not self.context.is_current_level: |
|---|
| 3508 | emit_lock_message(self) |
|---|
| 3509 | return |
|---|
| 3510 | super(CourseTicketAddFormPage2, self).update() |
|---|
| 3511 | return |
|---|
| 3512 | |
|---|
| 3513 | @action(_('Add course ticket')) |
|---|
| 3514 | def addCourseTicket(self, **data): |
|---|
| 3515 | # Safety belt |
|---|
| 3516 | if self.context.student.state != PAID: |
|---|
| 3517 | return |
|---|
| 3518 | course = data['course'] |
|---|
| 3519 | if course.former_course: |
|---|
| 3520 | self.flash(_('Former courses can\'t be added.'), type="warning") |
|---|
| 3521 | return |
|---|
| 3522 | success = addCourseTicket(self, course) |
|---|
| 3523 | if success: |
|---|
| 3524 | self.redirect(self.url(self.context, u'@@edit')) |
|---|
| 3525 | return |
|---|
| 3526 | |
|---|
| 3527 | class SetPasswordPage(KofaPage): |
|---|
| 3528 | grok.context(IKofaObject) |
|---|
| 3529 | grok.name('setpassword') |
|---|
| 3530 | grok.require('waeup.Anonymous') |
|---|
| 3531 | grok.template('setpassword') |
|---|
| 3532 | label = _('Set password for first-time login') |
|---|
| 3533 | ac_prefix = 'PWD' |
|---|
| 3534 | pnav = 0 |
|---|
| 3535 | set_button = _('Set') |
|---|
| 3536 | |
|---|
| 3537 | def update(self, SUBMIT=None): |
|---|
| 3538 | self.reg_number = self.request.form.get('reg_number', None) |
|---|
| 3539 | self.ac_series = self.request.form.get('ac_series', None) |
|---|
| 3540 | self.ac_number = self.request.form.get('ac_number', None) |
|---|
| 3541 | |
|---|
| 3542 | if SUBMIT is None: |
|---|
| 3543 | return |
|---|
| 3544 | hitlist = search(query=self.reg_number, |
|---|
| 3545 | searchtype='reg_number', view=self) |
|---|
| 3546 | if not hitlist: |
|---|
| 3547 | self.flash(_('No student found.'), type="warning") |
|---|
| 3548 | return |
|---|
| 3549 | if len(hitlist) != 1: # Cannot happen but anyway |
|---|
| 3550 | self.flash(_('More than one student found.'), type="warning") |
|---|
| 3551 | return |
|---|
| 3552 | student = hitlist[0].context |
|---|
| 3553 | self.student_id = student.student_id |
|---|
| 3554 | student_pw = student.password |
|---|
| 3555 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
|---|
| 3556 | code = get_access_code(pin) |
|---|
| 3557 | if not code: |
|---|
| 3558 | self.flash(_('Access code is invalid.'), type="warning") |
|---|
| 3559 | return |
|---|
| 3560 | if student_pw and pin == student.adm_code: |
|---|
| 3561 | self.flash(_( |
|---|
| 3562 | 'Password has already been set. Your Student Id is ${a}', |
|---|
| 3563 | mapping = {'a':self.student_id})) |
|---|
| 3564 | return |
|---|
| 3565 | elif student_pw: |
|---|
| 3566 | self.flash( |
|---|
| 3567 | _('Password has already been set. You are using the ' + |
|---|
| 3568 | 'wrong Access Code.'), type="warning") |
|---|
| 3569 | return |
|---|
| 3570 | # Mark pin as used (this also fires a pin related transition) |
|---|
| 3571 | # and set student password |
|---|
| 3572 | if code.state == USED: |
|---|
| 3573 | self.flash(_('Access code has already been used.'), type="warning") |
|---|
| 3574 | return |
|---|
| 3575 | else: |
|---|
| 3576 | comment = _(u"invalidated") |
|---|
| 3577 | # Here we know that the ac is in state initialized so we do not |
|---|
| 3578 | # expect an exception |
|---|
| 3579 | invalidate_accesscode(pin,comment) |
|---|
| 3580 | IUserAccount(student).setPassword(self.ac_number) |
|---|
| 3581 | student.adm_code = pin |
|---|
| 3582 | self.flash(_('Password has been set. Your Student Id is ${a}', |
|---|
| 3583 | mapping = {'a':self.student_id})) |
|---|
| 3584 | return |
|---|
| 3585 | |
|---|
| 3586 | class StudentRequestPasswordPage(KofaAddFormPage): |
|---|
| 3587 | """Captcha'd request password page for students. |
|---|
| 3588 | """ |
|---|
| 3589 | grok.name('requestpw') |
|---|
| 3590 | grok.require('waeup.Anonymous') |
|---|
| 3591 | grok.template('requestpw') |
|---|
| 3592 | form_fields = grok.AutoFields(IStudentRequestPW).select( |
|---|
| 3593 | 'lastname','number','email') |
|---|
| 3594 | label = _('Request password for first-time login') |
|---|
| 3595 | |
|---|
| 3596 | def update(self): |
|---|
| 3597 | blocker = grok.getSite()['configuration'].maintmode_enabled_by |
|---|
| 3598 | if blocker: |
|---|
| 3599 | self.flash(_('The portal is in maintenance mode. ' |
|---|
| 3600 | 'Password request forms are temporarily disabled.'), |
|---|
| 3601 | type='warning') |
|---|
| 3602 | self.redirect(self.url(self.context)) |
|---|
| 3603 | return |
|---|
| 3604 | # Handle captcha |
|---|
| 3605 | self.captcha = getUtility(ICaptchaManager).getCaptcha() |
|---|
| 3606 | self.captcha_result = self.captcha.verify(self.request) |
|---|
| 3607 | self.captcha_code = self.captcha.display(self.captcha_result.error_code) |
|---|
| 3608 | return |
|---|
| 3609 | |
|---|
| 3610 | def _redirect(self, email, password, student_id): |
|---|
| 3611 | # Forward only email to landing page in base package. |
|---|
| 3612 | self.redirect(self.url(self.context, 'requestpw_complete', |
|---|
| 3613 | data = dict(email=email))) |
|---|
| 3614 | return |
|---|
| 3615 | |
|---|
| 3616 | def _redirect_no_student(self): |
|---|
| 3617 | # No record found, this is the truth. We do not redirect here. |
|---|
| 3618 | # We are using this method in custom packages |
|---|
| 3619 | # for redirecting alumni to the application section. |
|---|
| 3620 | self.flash(_('No student record found.'), type="warning") |
|---|
| 3621 | return |
|---|
| 3622 | |
|---|
| 3623 | def _pw_used(self): |
|---|
| 3624 | # XXX: False if password has not been used. We need an extra |
|---|
| 3625 | # attribute which remembers if student logged in. |
|---|
| 3626 | return True |
|---|
| 3627 | |
|---|
| 3628 | @action(_('Send login credentials to email address'), style='primary') |
|---|
| 3629 | def get_credentials(self, **data): |
|---|
| 3630 | if not self.captcha_result.is_valid: |
|---|
| 3631 | # Captcha will display error messages automatically. |
|---|
| 3632 | # No need to flash something. |
|---|
| 3633 | return |
|---|
| 3634 | number = data.get('number','') |
|---|
| 3635 | lastname = data.get('lastname','') |
|---|
| 3636 | cat = getUtility(ICatalog, name='students_catalog') |
|---|
| 3637 | results = list( |
|---|
| 3638 | cat.searchResults(reg_number=(number, number))) |
|---|
| 3639 | if not results: |
|---|
| 3640 | results = list( |
|---|
| 3641 | cat.searchResults(matric_number=(number, number))) |
|---|
| 3642 | if results: |
|---|
| 3643 | student = results[0] |
|---|
| 3644 | if getattr(student,'lastname',None) is None: |
|---|
| 3645 | self.flash(_('An error occurred.'), type="danger") |
|---|
| 3646 | return |
|---|
| 3647 | elif student.lastname.lower() != lastname.lower(): |
|---|
| 3648 | # Don't tell the truth here. Anonymous must not |
|---|
| 3649 | # know that a record was found and only the lastname |
|---|
| 3650 | # verification failed. |
|---|
| 3651 | self.flash(_('No student record found.'), type="warning") |
|---|
| 3652 | return |
|---|
| 3653 | elif student.password is not None and self._pw_used: |
|---|
| 3654 | self.flash(_('Your password has already been set and used. ' |
|---|
| 3655 | 'Please proceed to the login page.'), |
|---|
| 3656 | type="warning") |
|---|
| 3657 | return |
|---|
| 3658 | # Store email address but nothing else. |
|---|
| 3659 | student.email = data['email'] |
|---|
| 3660 | notify(grok.ObjectModifiedEvent(student)) |
|---|
| 3661 | else: |
|---|
| 3662 | self._redirect_no_student() |
|---|
| 3663 | return |
|---|
| 3664 | |
|---|
| 3665 | kofa_utils = getUtility(IKofaUtils) |
|---|
| 3666 | password = kofa_utils.genPassword() |
|---|
| 3667 | mandate = PasswordMandate() |
|---|
| 3668 | mandate.params['password'] = password |
|---|
| 3669 | mandate.params['user'] = student |
|---|
| 3670 | site = grok.getSite() |
|---|
| 3671 | site['mandates'].addMandate(mandate) |
|---|
| 3672 | # Send email with credentials |
|---|
| 3673 | args = {'mandate_id':mandate.mandate_id} |
|---|
| 3674 | mandate_url = self.url(site) + '/mandate?%s' % urlencode(args) |
|---|
| 3675 | url_info = u'Confirmation link: %s' % mandate_url |
|---|
| 3676 | msg = _('You have successfully requested a password for the') |
|---|
| 3677 | if kofa_utils.sendCredentials(IUserAccount(student), |
|---|
| 3678 | password, url_info, msg): |
|---|
| 3679 | email_sent = student.email |
|---|
| 3680 | else: |
|---|
| 3681 | email_sent = None |
|---|
| 3682 | self._redirect(email=email_sent, password=password, |
|---|
| 3683 | student_id=student.student_id) |
|---|
| 3684 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
|---|
| 3685 | self.context.logger.info( |
|---|
| 3686 | '%s - %s (%s) - %s' % (ob_class, number, student.student_id, email_sent)) |
|---|
| 3687 | return |
|---|
| 3688 | |
|---|
| 3689 | class ParentsUser: |
|---|
| 3690 | pass |
|---|
| 3691 | |
|---|
| 3692 | class RequestParentsPasswordPage(StudentRequestPasswordPage): |
|---|
| 3693 | """Captcha'd request password page for parents. |
|---|
| 3694 | """ |
|---|
| 3695 | grok.name('requestppw') |
|---|
| 3696 | grok.template('requestppw') |
|---|
| 3697 | label = _('Request password for parents access') |
|---|
| 3698 | |
|---|
| 3699 | def update(self): |
|---|
| 3700 | super(RequestParentsPasswordPage, self).update() |
|---|
| 3701 | kofa_utils = getUtility(IKofaUtils) |
|---|
| 3702 | self.temp_password_minutes = kofa_utils.TEMP_PASSWORD_MINUTES |
|---|
| 3703 | return |
|---|
| 3704 | |
|---|
| 3705 | @action(_('Send temporary login credentials to email address'), style='primary') |
|---|
| 3706 | def get_credentials(self, **data): |
|---|
| 3707 | if not self.captcha_result.is_valid: |
|---|
| 3708 | # Captcha will display error messages automatically. |
|---|
| 3709 | # No need to flash something. |
|---|
| 3710 | return |
|---|
| 3711 | number = data.get('number','') |
|---|
| 3712 | lastname = data.get('lastname','') |
|---|
| 3713 | email = data['email'] |
|---|
| 3714 | cat = getUtility(ICatalog, name='students_catalog') |
|---|
| 3715 | results = list( |
|---|
| 3716 | cat.searchResults(reg_number=(number, number))) |
|---|
| 3717 | if not results: |
|---|
| 3718 | results = list( |
|---|
| 3719 | cat.searchResults(matric_number=(number, number))) |
|---|
| 3720 | if results: |
|---|
| 3721 | student = results[0] |
|---|
| 3722 | if getattr(student,'lastname',None) is None: |
|---|
| 3723 | self.flash(_('An error occurred.'), type="danger") |
|---|
| 3724 | return |
|---|
| 3725 | elif student.lastname.lower() != lastname.lower(): |
|---|
| 3726 | # Don't tell the truth here. Anonymous must not |
|---|
| 3727 | # know that a record was found and only the lastname |
|---|
| 3728 | # verification failed. |
|---|
| 3729 | self.flash(_('No student record found.'), type="warning") |
|---|
| 3730 | return |
|---|
| 3731 | elif email != student.parents_email: |
|---|
| 3732 | self.flash(_('Wrong email address.'), type="warning") |
|---|
| 3733 | return |
|---|
| 3734 | else: |
|---|
| 3735 | self._redirect_no_student() |
|---|
| 3736 | return |
|---|
| 3737 | kofa_utils = getUtility(IKofaUtils) |
|---|
| 3738 | password = kofa_utils.genPassword() |
|---|
| 3739 | mandate = ParentsPasswordMandate() |
|---|
| 3740 | mandate.params['password'] = password |
|---|
| 3741 | mandate.params['student'] = student |
|---|
| 3742 | site = grok.getSite() |
|---|
| 3743 | site['mandates'].addMandate(mandate) |
|---|
| 3744 | # Send email with credentials |
|---|
| 3745 | args = {'mandate_id':mandate.mandate_id} |
|---|
| 3746 | mandate_url = self.url(site) + '/mandate?%s' % urlencode(args) |
|---|
| 3747 | url_info = u'Confirmation link: %s' % mandate_url |
|---|
| 3748 | msg = _('You have successfully requested a parents password for the') |
|---|
| 3749 | # Create a fake user |
|---|
| 3750 | user = ParentsUser() |
|---|
| 3751 | user.name = student.student_id |
|---|
| 3752 | user.title = "Parents of %s" % student.display_fullname |
|---|
| 3753 | user.email = student.parents_email |
|---|
| 3754 | if kofa_utils.sendCredentials(user, password, url_info, msg): |
|---|
| 3755 | email_sent = user.email |
|---|
| 3756 | else: |
|---|
| 3757 | email_sent = None |
|---|
| 3758 | self._redirect(email=email_sent, password=password, |
|---|
| 3759 | student_id=student.student_id) |
|---|
| 3760 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
|---|
| 3761 | self.context.logger.info( |
|---|
| 3762 | '%s - %s (%s) - %s' % (ob_class, number, student.student_id, email_sent)) |
|---|
| 3763 | return |
|---|
| 3764 | |
|---|
| 3765 | class StudentRequestPasswordEmailSent(KofaPage): |
|---|
| 3766 | """Landing page after successful password request. |
|---|
| 3767 | |
|---|
| 3768 | """ |
|---|
| 3769 | grok.name('requestpw_complete') |
|---|
| 3770 | grok.require('waeup.Public') |
|---|
| 3771 | grok.template('requestpwmailsent') |
|---|
| 3772 | label = _('Your password request was successful.') |
|---|
| 3773 | |
|---|
| 3774 | def update(self, email=None, student_id=None, password=None): |
|---|
| 3775 | self.email = email |
|---|
| 3776 | self.password = password |
|---|
| 3777 | self.student_id = student_id |
|---|
| 3778 | return |
|---|
| 3779 | |
|---|
| 3780 | class FilterStudentsInDepartmentPage(KofaPage): |
|---|
| 3781 | """Page that filters and lists students. |
|---|
| 3782 | """ |
|---|
| 3783 | grok.context(IDepartment) |
|---|
| 3784 | grok.require('waeup.showStudents') |
|---|
| 3785 | grok.name('students') |
|---|
| 3786 | grok.template('filterstudentspage') |
|---|
| 3787 | pnav = 1 |
|---|
| 3788 | session_label = _('Current Session') |
|---|
| 3789 | level_label = _('Current Level') |
|---|
| 3790 | |
|---|
| 3791 | def label(self): |
|---|
| 3792 | return 'Students in %s' % self.context.longtitle |
|---|
| 3793 | |
|---|
| 3794 | def _set_session_values(self): |
|---|
| 3795 | vocab_terms = academic_sessions_vocab.by_value.values() |
|---|
| 3796 | self.sessions = sorted( |
|---|
| 3797 | [(x.title, x.token) for x in vocab_terms], reverse=True) |
|---|
| 3798 | self.sessions += [('All Sessions', 'all')] |
|---|
| 3799 | return |
|---|
| 3800 | |
|---|
| 3801 | def _set_level_values(self): |
|---|
| 3802 | vocab_terms = course_levels.by_value.values() |
|---|
| 3803 | self.levels = sorted( |
|---|
| 3804 | [(x.title, x.token) for x in vocab_terms]) |
|---|
| 3805 | self.levels += [('All Levels', 'all')] |
|---|
| 3806 | return |
|---|
| 3807 | |
|---|
| 3808 | def _searchCatalog(self, session, level): |
|---|
| 3809 | if level not in (10, 999, 1000, None): |
|---|
| 3810 | start_level = 100 * (level // 100) |
|---|
| 3811 | end_level = start_level + 90 |
|---|
| 3812 | else: |
|---|
| 3813 | start_level = end_level = level |
|---|
| 3814 | cat = queryUtility(ICatalog, name='students_catalog') |
|---|
| 3815 | students = cat.searchResults( |
|---|
| 3816 | current_session=(session, session), |
|---|
| 3817 | current_level=(start_level, end_level), |
|---|
| 3818 | depcode=(self.context.code, self.context.code) |
|---|
| 3819 | ) |
|---|
| 3820 | hitlist = [] |
|---|
| 3821 | for student in students: |
|---|
| 3822 | hitlist.append(StudentQueryResultItem(student, view=self)) |
|---|
| 3823 | return hitlist |
|---|
| 3824 | |
|---|
| 3825 | def update(self, SHOW=None, session=None, level=None): |
|---|
| 3826 | self.parent_url = self.url(self.context.__parent__) |
|---|
| 3827 | self._set_session_values() |
|---|
| 3828 | self._set_level_values() |
|---|
| 3829 | self.hitlist = [] |
|---|
| 3830 | self.session_default = session |
|---|
| 3831 | self.level_default = level |
|---|
| 3832 | if SHOW is not None: |
|---|
| 3833 | if session != 'all': |
|---|
| 3834 | self.session = int(session) |
|---|
| 3835 | self.session_string = '%s %s/%s' % ( |
|---|
| 3836 | self.session_label, self.session, self.session+1) |
|---|
| 3837 | else: |
|---|
| 3838 | self.session = None |
|---|
| 3839 | self.session_string = _('in any session') |
|---|
| 3840 | if level != 'all': |
|---|
| 3841 | self.level = int(level) |
|---|
| 3842 | self.level_string = '%s %s' % (self.level_label, self.level) |
|---|
| 3843 | else: |
|---|
| 3844 | self.level = None |
|---|
| 3845 | self.level_string = _('at any level') |
|---|
| 3846 | self.hitlist = self._searchCatalog(self.session, self.level) |
|---|
| 3847 | if not self.hitlist: |
|---|
| 3848 | self.flash(_('No student found.'), type="warning") |
|---|
| 3849 | return |
|---|
| 3850 | |
|---|
| 3851 | class FilterStudentsInCertificatePage(FilterStudentsInDepartmentPage): |
|---|
| 3852 | """Page that filters and lists students. |
|---|
| 3853 | """ |
|---|
| 3854 | grok.context(ICertificate) |
|---|
| 3855 | |
|---|
| 3856 | def label(self): |
|---|
| 3857 | return 'Students studying %s' % self.context.longtitle |
|---|
| 3858 | |
|---|
| 3859 | def _searchCatalog(self, session, level): |
|---|
| 3860 | if level not in (10, 999, 1000, None): |
|---|
| 3861 | start_level = 100 * (level // 100) |
|---|
| 3862 | end_level = start_level + 90 |
|---|
| 3863 | else: |
|---|
| 3864 | start_level = end_level = level |
|---|
| 3865 | cat = queryUtility(ICatalog, name='students_catalog') |
|---|
| 3866 | students = cat.searchResults( |
|---|
| 3867 | current_session=(session, session), |
|---|
| 3868 | current_level=(start_level, end_level), |
|---|
| 3869 | certcode=(self.context.code, self.context.code) |
|---|
| 3870 | ) |
|---|
| 3871 | hitlist = [] |
|---|
| 3872 | for student in students: |
|---|
| 3873 | hitlist.append(StudentQueryResultItem(student, view=self)) |
|---|
| 3874 | return hitlist |
|---|
| 3875 | |
|---|
| 3876 | class FilterStudentsInCoursePage(FilterStudentsInDepartmentPage): |
|---|
| 3877 | """Page that filters and lists students. |
|---|
| 3878 | """ |
|---|
| 3879 | grok.context(ICourse) |
|---|
| 3880 | grok.require('waeup.viewStudent') |
|---|
| 3881 | |
|---|
| 3882 | session_label = _('Session') |
|---|
| 3883 | level_label = _('Level') |
|---|
| 3884 | |
|---|
| 3885 | def label(self): |
|---|
| 3886 | return 'Students registered for %s' % self.context.longtitle |
|---|
| 3887 | |
|---|
| 3888 | def _searchCatalog(self, session, level): |
|---|
| 3889 | if level not in (10, 999, 1000, None): |
|---|
| 3890 | start_level = 100 * (level // 100) |
|---|
| 3891 | end_level = start_level + 90 |
|---|
| 3892 | else: |
|---|
| 3893 | start_level = end_level = level |
|---|
| 3894 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
|---|
| 3895 | coursetickets = cat.searchResults( |
|---|
| 3896 | session=(session, session), |
|---|
| 3897 | level=(start_level, end_level), |
|---|
| 3898 | code=(self.context.code, self.context.code) |
|---|
| 3899 | ) |
|---|
| 3900 | hitlist = [] |
|---|
| 3901 | for ticket in coursetickets: |
|---|
| 3902 | hitlist.append(StudentQueryResultItem(ticket.student, view=self)) |
|---|
| 3903 | return list(set(hitlist)) |
|---|
| 3904 | |
|---|
| 3905 | class ClearAllStudentsInDepartmentView(UtilityView, grok.View): |
|---|
| 3906 | """ Clear all students of a department in state 'clearance requested'. |
|---|
| 3907 | """ |
|---|
| 3908 | grok.context(IDepartment) |
|---|
| 3909 | grok.name('clearallstudents') |
|---|
| 3910 | grok.require('waeup.clearAllStudents') |
|---|
| 3911 | |
|---|
| 3912 | def update(self): |
|---|
| 3913 | cat = queryUtility(ICatalog, name='students_catalog') |
|---|
| 3914 | students = cat.searchResults( |
|---|
| 3915 | depcode=(self.context.code, self.context.code), |
|---|
| 3916 | state=(REQUESTED, REQUESTED) |
|---|
| 3917 | ) |
|---|
| 3918 | num = 0 |
|---|
| 3919 | for student in students: |
|---|
| 3920 | if getUtility(IStudentsUtils).clearance_disabled_message(student): |
|---|
| 3921 | continue |
|---|
| 3922 | IWorkflowInfo(student).fireTransition('clear') |
|---|
| 3923 | num += 1 |
|---|
| 3924 | self.flash(_('%d students have been cleared.' % num)) |
|---|
| 3925 | self.redirect(self.url(self.context)) |
|---|
| 3926 | return |
|---|
| 3927 | |
|---|
| 3928 | def render(self): |
|---|
| 3929 | return |
|---|
| 3930 | |
|---|
| 3931 | #class RemoveFlashNoticeAllStudentsInDepartmentView(UtilityView, grok.View): |
|---|
| 3932 | # """ Remove flash notices of all students in a department. |
|---|
| 3933 | # """ |
|---|
| 3934 | # grok.context(IDepartment) |
|---|
| 3935 | # grok.name('removeflash') |
|---|
| 3936 | # grok.require('waeup.manageStudent') |
|---|
| 3937 | |
|---|
| 3938 | # def update(self): |
|---|
| 3939 | # cat = queryUtility(ICatalog, name='students_catalog') |
|---|
| 3940 | # students = cat.searchResults( |
|---|
| 3941 | # depcode=(self.context.code, self.context.code), |
|---|
| 3942 | # ) |
|---|
| 3943 | # num = 0 |
|---|
| 3944 | # for student in students: |
|---|
| 3945 | # student.flash_notice = u'' |
|---|
| 3946 | # num += 1 |
|---|
| 3947 | # self.flash(_('%d flash notices have been removed.' % num)) |
|---|
| 3948 | # self.redirect(self.url(self.context)) |
|---|
| 3949 | # return |
|---|
| 3950 | |
|---|
| 3951 | # def render(self): |
|---|
| 3952 | # return |
|---|
| 3953 | |
|---|
| 3954 | class EditFlashNoticesFormPage(KofaFormPage): |
|---|
| 3955 | """Edit all flash notices of students in a department. |
|---|
| 3956 | """ |
|---|
| 3957 | grok.context(IDepartment) |
|---|
| 3958 | grok.name('edit_flash_notices') |
|---|
| 3959 | grok.template('editflashnotices') |
|---|
| 3960 | grok.require('waeup.manageStudent') |
|---|
| 3961 | form_fields = grok.AutoFields(IFlashNotice) |
|---|
| 3962 | pnav = 0 |
|---|
| 3963 | |
|---|
| 3964 | def label(self): |
|---|
| 3965 | return _(u'Set flash notices for all students in ${a}', |
|---|
| 3966 | mapping = {'a':self.context.longtitle}) |
|---|
| 3967 | |
|---|
| 3968 | @action('Save flash notices', style='primary') |
|---|
| 3969 | def save(self, *args, **data): |
|---|
| 3970 | cat = queryUtility(ICatalog, name='students_catalog') |
|---|
| 3971 | students = cat.searchResults( |
|---|
| 3972 | depcode=(self.context.code, self.context.code), |
|---|
| 3973 | ) |
|---|
| 3974 | num = 0 |
|---|
| 3975 | for student in students: |
|---|
| 3976 | student.flash_notice = data['flash_notice'] |
|---|
| 3977 | num += 1 |
|---|
| 3978 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
|---|
| 3979 | grok.getSite().logger.info( |
|---|
| 3980 | '%s - %s - saved flash notice: %s' |
|---|
| 3981 | % (ob_class, self.context.__name__, data['flash_notice'])) |
|---|
| 3982 | self.flash(_('%d flash notices have been edited.' % num)) |
|---|
| 3983 | self.redirect(self.url(self.context)) |
|---|
| 3984 | return |
|---|
| 3985 | |
|---|
| 3986 | @action(_('Cancel'), validator=NullValidator) |
|---|
| 3987 | def cancel(self, **data): |
|---|
| 3988 | self.redirect(self.url(self.context)) |
|---|
| 3989 | |
|---|
| 3990 | class EditScoresPage(KofaPage): |
|---|
| 3991 | """Page that allows to edit batches of scores. |
|---|
| 3992 | """ |
|---|
| 3993 | grok.context(ICourse) |
|---|
| 3994 | grok.require('waeup.editScores') |
|---|
| 3995 | grok.name('edit_scores') |
|---|
| 3996 | grok.template('editscorespage') |
|---|
| 3997 | pnav = 1 |
|---|
| 3998 | doclink = DOCLINK + '/students/browser.html#batch-editing-scores-by-lecturers' |
|---|
| 3999 | |
|---|
| 4000 | def label(self): |
|---|
| 4001 | return '%s tickets in academic session %s' % ( |
|---|
| 4002 | self.context.code, self.session_title) |
|---|
| 4003 | |
|---|
| 4004 | def _searchCatalog(self, session): |
|---|
| 4005 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
|---|
| 4006 | # Attention: Also tickets of previous studycourses are found |
|---|
| 4007 | coursetickets = cat.searchResults( |
|---|
| 4008 | session=(session, session), |
|---|
| 4009 | code=(self.context.code, self.context.code) |
|---|
| 4010 | ) |
|---|
| 4011 | return list(coursetickets) |
|---|
| 4012 | |
|---|
| 4013 | def _extract_uploadfile(self, uploadfile): |
|---|
| 4014 | """Get a mapping of student-ids to scores. |
|---|
| 4015 | |
|---|
| 4016 | The mapping is constructed by reading contents from `uploadfile`. |
|---|
| 4017 | |
|---|
| 4018 | We expect uploadfile to be a regular CSV file with columns |
|---|
| 4019 | ``student_id`` and ``score`` (other cols are ignored). |
|---|
| 4020 | """ |
|---|
| 4021 | result = dict() |
|---|
| 4022 | data = StringIO(uploadfile.read()) # ensure we have something seekable |
|---|
| 4023 | reader = csv.DictReader(data) |
|---|
| 4024 | for row in reader: |
|---|
| 4025 | if not 'student_id' in row or not 'score' in row: |
|---|
| 4026 | continue |
|---|
| 4027 | result[row['student_id']] = row['score'] |
|---|
| 4028 | return result |
|---|
| 4029 | |
|---|
| 4030 | def _update_scores(self, form): |
|---|
| 4031 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.', '') |
|---|
| 4032 | error = '' |
|---|
| 4033 | if 'UPDATE_FILE' in form: |
|---|
| 4034 | if form['uploadfile']: |
|---|
| 4035 | try: |
|---|
| 4036 | formvals = self._extract_uploadfile(form['uploadfile']) |
|---|
| 4037 | except: |
|---|
| 4038 | self.flash( |
|---|
| 4039 | _('Uploaded file contains illegal data. Ignored'), |
|---|
| 4040 | type="danger") |
|---|
| 4041 | return False |
|---|
| 4042 | else: |
|---|
| 4043 | self.flash( |
|---|
| 4044 | _('No file provided.'), type="danger") |
|---|
| 4045 | return False |
|---|
| 4046 | else: |
|---|
| 4047 | formvals = dict(zip(form['sids'], form['scores'])) |
|---|
| 4048 | for ticket in self.editable_tickets: |
|---|
| 4049 | score = ticket.score |
|---|
| 4050 | sid = ticket.student.student_id |
|---|
| 4051 | if sid not in formvals: |
|---|
| 4052 | continue |
|---|
| 4053 | if formvals[sid] == '': |
|---|
| 4054 | score = None |
|---|
| 4055 | else: |
|---|
| 4056 | try: |
|---|
| 4057 | score = int(formvals[sid]) |
|---|
| 4058 | except ValueError: |
|---|
| 4059 | error += '%s, ' % ticket.student.display_fullname |
|---|
| 4060 | if ticket.score != score: |
|---|
| 4061 | ticket.score = score |
|---|
| 4062 | ticket.student.__parent__.logger.info( |
|---|
| 4063 | '%s - %s %s/%s score updated (%s)' % ( |
|---|
| 4064 | ob_class, ticket.student.student_id, |
|---|
| 4065 | ticket.level, ticket.code, score) |
|---|
| 4066 | ) |
|---|
| 4067 | if error: |
|---|
| 4068 | self.flash( |
|---|
| 4069 | _('Error: Score(s) of following students have not been ' |
|---|
| 4070 | 'updated (only integers are allowed): %s.' % error.strip(', ')), |
|---|
| 4071 | type="danger") |
|---|
| 4072 | return True |
|---|
| 4073 | |
|---|
| 4074 | def _validate_results(self, form): |
|---|
| 4075 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.', '') |
|---|
| 4076 | user = get_current_principal() |
|---|
| 4077 | if user is None: |
|---|
| 4078 | usertitle = 'system' |
|---|
| 4079 | else: |
|---|
| 4080 | usertitle = getattr(user, 'public_name', None) |
|---|
| 4081 | if not usertitle: |
|---|
| 4082 | usertitle = user.title |
|---|
| 4083 | self.context.results_validated_by = usertitle |
|---|
| 4084 | self.context.results_validation_date = datetime.utcnow() |
|---|
| 4085 | self.context.results_validation_session = self.current_academic_session |
|---|
| 4086 | return |
|---|
| 4087 | |
|---|
| 4088 | def _results_editable(self, results_validation_session, |
|---|
| 4089 | current_academic_session): |
|---|
| 4090 | user = get_current_principal() |
|---|
| 4091 | prm = IPrincipalRoleManager(self.context) |
|---|
| 4092 | roles = [x[0] for x in prm.getRolesForPrincipal(user.id)] |
|---|
| 4093 | if 'waeup.local.LocalStudentsManager' in roles: |
|---|
| 4094 | return True |
|---|
| 4095 | if results_validation_session \ |
|---|
| 4096 | and results_validation_session >= current_academic_session: |
|---|
| 4097 | return False |
|---|
| 4098 | return True |
|---|
| 4099 | |
|---|
| 4100 | def update(self, *args, **kw): |
|---|
| 4101 | form = self.request.form |
|---|
| 4102 | self.current_academic_session = grok.getSite()[ |
|---|
| 4103 | 'configuration'].current_academic_session |
|---|
| 4104 | if self.context.__parent__.__parent__.score_editing_disabled \ |
|---|
| 4105 | or self.context.score_editing_disabled: |
|---|
| 4106 | self.flash(_('Score editing disabled.'), type="warning") |
|---|
| 4107 | self.redirect(self.url(self.context)) |
|---|
| 4108 | return |
|---|
| 4109 | if not self.current_academic_session: |
|---|
| 4110 | self.flash(_('Current academic session not set.'), type="warning") |
|---|
| 4111 | self.redirect(self.url(self.context)) |
|---|
| 4112 | return |
|---|
| 4113 | vs = self.context.results_validation_session |
|---|
| 4114 | if not self._results_editable(vs, self.current_academic_session): |
|---|
| 4115 | self.flash( |
|---|
| 4116 | _('Course results have already been ' |
|---|
| 4117 | 'validated and can no longer be changed.'), |
|---|
| 4118 | type="danger") |
|---|
| 4119 | self.redirect(self.url(self.context)) |
|---|
| 4120 | return |
|---|
| 4121 | self.session_title = academic_sessions_vocab.getTerm( |
|---|
| 4122 | self.current_academic_session).title |
|---|
| 4123 | self.tickets = self._searchCatalog(self.current_academic_session) |
|---|
| 4124 | if not self.tickets: |
|---|
| 4125 | self.flash(_('No student found.'), type="warning") |
|---|
| 4126 | self.redirect(self.url(self.context)) |
|---|
| 4127 | return |
|---|
| 4128 | self.editable_tickets = [ |
|---|
| 4129 | ticket for ticket in self.tickets if ticket.editable_by_lecturer] |
|---|
| 4130 | if not 'UPDATE_TABLE' in form and not 'UPDATE_FILE' in form\ |
|---|
| 4131 | and not 'VALIDATE_RESULTS' in form: |
|---|
| 4132 | return |
|---|
| 4133 | if 'VALIDATE_RESULTS' in form: |
|---|
| 4134 | if vs and vs >= self.current_academic_session: |
|---|
| 4135 | self.flash( |
|---|
| 4136 | _('Course results have already been validated.'), |
|---|
| 4137 | type="danger") |
|---|
| 4138 | for ticket in self.tickets: |
|---|
| 4139 | if ticket.total_score is not None: |
|---|
| 4140 | break |
|---|
| 4141 | self.flash( |
|---|
| 4142 | _('No score has been entered.'), |
|---|
| 4143 | type="danger") |
|---|
| 4144 | return |
|---|
| 4145 | self._validate_results(form) |
|---|
| 4146 | self.flash(_('You successfully validated the course results.')) |
|---|
| 4147 | self.redirect(self.url(self.context)) |
|---|
| 4148 | return |
|---|
| 4149 | if not self.editable_tickets: |
|---|
| 4150 | return |
|---|
| 4151 | success = self._update_scores(form) |
|---|
| 4152 | if success: |
|---|
| 4153 | self.flash(_('You successfully updated course results.')) |
|---|
| 4154 | return |
|---|
| 4155 | |
|---|
| 4156 | class DownloadScoresView(UtilityView, grok.View): |
|---|
| 4157 | """View that exports scores. |
|---|
| 4158 | """ |
|---|
| 4159 | grok.context(ICourse) |
|---|
| 4160 | grok.require('waeup.editScores') |
|---|
| 4161 | grok.name('download_scores') |
|---|
| 4162 | |
|---|
| 4163 | def _results_editable(self, results_validation_session, |
|---|
| 4164 | current_academic_session): |
|---|
| 4165 | user = get_current_principal() |
|---|
| 4166 | prm = IPrincipalRoleManager(self.context) |
|---|
| 4167 | roles = [x[0] for x in prm.getRolesForPrincipal(user.id)] |
|---|
| 4168 | if 'waeup.local.LocalStudentsManager' in roles: |
|---|
| 4169 | return True |
|---|
| 4170 | if results_validation_session \ |
|---|
| 4171 | and results_validation_session >= current_academic_session: |
|---|
| 4172 | return False |
|---|
| 4173 | return True |
|---|
| 4174 | |
|---|
| 4175 | def update(self): |
|---|
| 4176 | self.current_academic_session = grok.getSite()[ |
|---|
| 4177 | 'configuration'].current_academic_session |
|---|
| 4178 | if self.context.__parent__.__parent__.score_editing_disabled \ |
|---|
| 4179 | or self.context.score_editing_disabled: |
|---|
| 4180 | self.flash(_('Score editing disabled.'), type="warning") |
|---|
| 4181 | self.redirect(self.url(self.context)) |
|---|
| 4182 | return |
|---|
| 4183 | if not self.current_academic_session: |
|---|
| 4184 | self.flash(_('Current academic session not set.'), type="warning") |
|---|
| 4185 | self.redirect(self.url(self.context)) |
|---|
| 4186 | return |
|---|
| 4187 | vs = self.context.results_validation_session |
|---|
| 4188 | if not self._results_editable(vs, self.current_academic_session): |
|---|
| 4189 | self.flash( |
|---|
| 4190 | _('Course results have already been ' |
|---|
| 4191 | 'validated and can no longer be changed.'), |
|---|
| 4192 | type="danger") |
|---|
| 4193 | self.redirect(self.url(self.context)) |
|---|
| 4194 | return |
|---|
| 4195 | site = grok.getSite() |
|---|
| 4196 | exporter = getUtility(ICSVExporter, name='lecturer') |
|---|
| 4197 | self.csv = exporter.export_filtered(site, filepath=None, |
|---|
| 4198 | catalog='coursetickets', |
|---|
| 4199 | session=self.current_academic_session, |
|---|
| 4200 | level=None, |
|---|
| 4201 | code=self.context.code) |
|---|
| 4202 | return |
|---|
| 4203 | |
|---|
| 4204 | def render(self): |
|---|
| 4205 | filename = 'results_%s_%s.csv' % ( |
|---|
| 4206 | self.context.code, self.current_academic_session) |
|---|
| 4207 | self.response.setHeader( |
|---|
| 4208 | 'Content-Type', 'text/csv; charset=UTF-8') |
|---|
| 4209 | self.response.setHeader( |
|---|
| 4210 | 'Content-Disposition:', 'attachment; filename="%s' % filename) |
|---|
| 4211 | return self.csv |
|---|
| 4212 | |
|---|
| 4213 | class ExportPDFScoresSlip(UtilityView, grok.View, |
|---|
| 4214 | LocalRoleAssignmentUtilityView): |
|---|
| 4215 | """Deliver a PDF slip of course tickets for a lecturer. |
|---|
| 4216 | """ |
|---|
| 4217 | grok.context(ICourse) |
|---|
| 4218 | grok.name('coursetickets.pdf') |
|---|
| 4219 | grok.require('waeup.showStudents') |
|---|
| 4220 | |
|---|
| 4221 | def update(self): |
|---|
| 4222 | self.current_academic_session = grok.getSite()[ |
|---|
| 4223 | 'configuration'].current_academic_session |
|---|
| 4224 | if not self.current_academic_session: |
|---|
| 4225 | self.flash(_('Current academic session not set.'), type="danger") |
|---|
| 4226 | self.redirect(self.url(self.context)) |
|---|
| 4227 | return |
|---|
| 4228 | |
|---|
| 4229 | @property |
|---|
| 4230 | def note(self): |
|---|
| 4231 | return |
|---|
| 4232 | |
|---|
| 4233 | def data(self, session): |
|---|
| 4234 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
|---|
| 4235 | # Attention: Also tickets of previous studycourses are found |
|---|
| 4236 | coursetickets = cat.searchResults( |
|---|
| 4237 | session=(session, session), |
|---|
| 4238 | code=(self.context.code, self.context.code) |
|---|
| 4239 | ) |
|---|
| 4240 | header = [[_('S/N'), |
|---|
| 4241 | _('Matric No.'), |
|---|
| 4242 | _('Reg. No.'), |
|---|
| 4243 | _('Fullname'), |
|---|
| 4244 | _('Status'), |
|---|
| 4245 | _('Course of Studies'), |
|---|
| 4246 | _('Level'), |
|---|
| 4247 | _('Score') ],] |
|---|
| 4248 | tickets = [] |
|---|
| 4249 | for ticket in list(coursetickets): |
|---|
| 4250 | row = [ticket.student.matric_number, |
|---|
| 4251 | ticket.student.reg_number, |
|---|
| 4252 | ticket.student.display_fullname, |
|---|
| 4253 | ticket.student.translated_state, |
|---|
| 4254 | ticket.student.certcode, |
|---|
| 4255 | ticket.level, |
|---|
| 4256 | ticket.score, |
|---|
| 4257 | ticket.student.lastname # for sorting only |
|---|
| 4258 | ] |
|---|
| 4259 | tickets.append(row) |
|---|
| 4260 | data = sorted(tickets, key=lambda value: value[7]) |
|---|
| 4261 | sn = 1 |
|---|
| 4262 | for d in data: |
|---|
| 4263 | d.pop(7) |
|---|
| 4264 | d.insert(0, sn) |
|---|
| 4265 | sn += 1 |
|---|
| 4266 | return header + data, None |
|---|
| 4267 | |
|---|
| 4268 | def render(self): |
|---|
| 4269 | lecturers = [i['user_title'] for i in self.getUsersWithLocalRoles() |
|---|
| 4270 | if i['local_role'] == 'waeup.local.Lecturer'] |
|---|
| 4271 | lecturers = sorted(lecturers) |
|---|
| 4272 | lecturers = ', '.join(lecturers) |
|---|
| 4273 | students_utils = getUtility(IStudentsUtils) |
|---|
| 4274 | return students_utils.renderPDFCourseticketsOverview( |
|---|
| 4275 | self, 'coursetickets', self.current_academic_session, |
|---|
| 4276 | self.data(self.current_academic_session), lecturers, |
|---|
| 4277 | 'landscape', 90, self.note) |
|---|
| 4278 | |
|---|
| 4279 | class ExportAttendanceSlip(UtilityView, grok.View, |
|---|
| 4280 | LocalRoleAssignmentUtilityView): |
|---|
| 4281 | """Deliver a PDF slip of course tickets in attendance sheet format. |
|---|
| 4282 | """ |
|---|
| 4283 | grok.context(ICourse) |
|---|
| 4284 | grok.name('attendance.pdf') |
|---|
| 4285 | grok.require('waeup.showStudents') |
|---|
| 4286 | |
|---|
| 4287 | def update(self): |
|---|
| 4288 | self.current_academic_session = grok.getSite()[ |
|---|
| 4289 | 'configuration'].current_academic_session |
|---|
| 4290 | if not self.current_academic_session: |
|---|
| 4291 | self.flash(_('Current academic session not set.'), type="danger") |
|---|
| 4292 | self.redirect(self.url(self.context)) |
|---|
| 4293 | return |
|---|
| 4294 | |
|---|
| 4295 | @property |
|---|
| 4296 | def note(self): |
|---|
| 4297 | return |
|---|
| 4298 | |
|---|
| 4299 | def data(self, session): |
|---|
| 4300 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
|---|
| 4301 | # Attention: Also tickets of previous studycourses are found |
|---|
| 4302 | coursetickets = cat.searchResults( |
|---|
| 4303 | session=(session, session), |
|---|
| 4304 | code=(self.context.code, self.context.code) |
|---|
| 4305 | ) |
|---|
| 4306 | header = [[_('S/N'), |
|---|
| 4307 | _('Matric No.'), |
|---|
| 4308 | _('Name'), |
|---|
| 4309 | _('Level'), |
|---|
| 4310 | _('Course of\nStudies'), |
|---|
| 4311 | _('Booklet\nNo.'), |
|---|
| 4312 | _('Venue'), |
|---|
| 4313 | _('Time'), |
|---|
| 4314 | _('Signature'), |
|---|
| 4315 | ],] |
|---|
| 4316 | tickets = [] |
|---|
| 4317 | sn = 1 |
|---|
| 4318 | ctlist = sorted(list(coursetickets), |
|---|
| 4319 | key=lambda value: str(value.student.faccode) + |
|---|
| 4320 | str(value.student.depcode) + |
|---|
| 4321 | str(value.student.certcode) + |
|---|
| 4322 | str(value.student.matric_number)) |
|---|
| 4323 | # In AAUE only editable appear on the attendance sheet. Hopefully |
|---|
| 4324 | # this holds for other universities too. |
|---|
| 4325 | editable_tickets = [ticket for ticket in ctlist |
|---|
| 4326 | if ticket.editable_by_lecturer] |
|---|
| 4327 | for ticket in editable_tickets: |
|---|
| 4328 | name = textwrap.fill(ticket.student.display_fullname, 20) |
|---|
| 4329 | row = [sn, |
|---|
| 4330 | ticket.student.matric_number, |
|---|
| 4331 | name, |
|---|
| 4332 | ticket.level, |
|---|
| 4333 | ticket.student.certcode, |
|---|
| 4334 | 10 * ' ', |
|---|
| 4335 | 10 * ' ', |
|---|
| 4336 | 10 * ' ', |
|---|
| 4337 | 27 * ' ', |
|---|
| 4338 | ] |
|---|
| 4339 | tickets.append(row) |
|---|
| 4340 | sn += 1 |
|---|
| 4341 | return header + tickets, None |
|---|
| 4342 | |
|---|
| 4343 | def _signatures(self): |
|---|
| 4344 | return ([_('Lecturer Signature')], |
|---|
| 4345 | [_('Lecturer Signature')],) |
|---|
| 4346 | |
|---|
| 4347 | |
|---|
| 4348 | def render(self): |
|---|
| 4349 | lecturers = [i['user_title'] for i in self.getUsersWithLocalRoles() |
|---|
| 4350 | if i['local_role'] == 'waeup.local.Lecturer'] |
|---|
| 4351 | lecturers = ', '.join(lecturers) |
|---|
| 4352 | students_utils = getUtility(IStudentsUtils) |
|---|
| 4353 | return students_utils.renderPDFCourseticketsOverview( |
|---|
| 4354 | self, 'attendance', self.current_academic_session, |
|---|
| 4355 | self.data(self.current_academic_session), |
|---|
| 4356 | lecturers, '', 65, self.note, |
|---|
| 4357 | signatures=self._signatures(),) |
|---|
| 4358 | |
|---|
| 4359 | class ExportJobContainerOverview(KofaPage): |
|---|
| 4360 | """Page that lists active student data export jobs and provides links |
|---|
| 4361 | to discard or download CSV files. |
|---|
| 4362 | |
|---|
| 4363 | """ |
|---|
| 4364 | grok.context(VirtualExportJobContainer) |
|---|
| 4365 | grok.require('waeup.showStudents') |
|---|
| 4366 | grok.name('index.html') |
|---|
| 4367 | grok.template('exportjobsindex') |
|---|
| 4368 | label = _('Student Data Exports') |
|---|
| 4369 | pnav = 1 |
|---|
| 4370 | doclink = DOCLINK + '/datacenter/export.html#student-data-exporters' |
|---|
| 4371 | |
|---|
| 4372 | def update(self, CREATE1=None, CREATE2=None, DISCARD=None, job_id=None): |
|---|
| 4373 | if CREATE1: |
|---|
| 4374 | self.redirect(self.url('@@exportconfig')) |
|---|
| 4375 | return |
|---|
| 4376 | if CREATE2: |
|---|
| 4377 | self.redirect(self.url('@@exportselected')) |
|---|
| 4378 | return |
|---|
| 4379 | if DISCARD and job_id: |
|---|
| 4380 | entry = self.context.entry_from_job_id(job_id) |
|---|
| 4381 | self.context.delete_export_entry(entry) |
|---|
| 4382 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
|---|
| 4383 | self.context.logger.info( |
|---|
| 4384 | '%s - discarded: job_id=%s' % (ob_class, job_id)) |
|---|
| 4385 | self.flash(_('Discarded export') + ' %s' % job_id) |
|---|
| 4386 | self.entries = doll_up(self, user=self.request.principal.id) |
|---|
| 4387 | return |
|---|
| 4388 | |
|---|
| 4389 | class ExportJobContainerJobConfig(KofaPage): |
|---|
| 4390 | """Page that configures a students export job. |
|---|
| 4391 | |
|---|
| 4392 | This is a baseclass. |
|---|
| 4393 | """ |
|---|
| 4394 | grok.baseclass() |
|---|
| 4395 | grok.require('waeup.showStudents') |
|---|
| 4396 | grok.template('exportconfig') |
|---|
| 4397 | label = _('Configure student data export') |
|---|
| 4398 | pnav = 1 |
|---|
| 4399 | redirect_target = '' |
|---|
| 4400 | doclink = DOCLINK + '/datacenter/export.html#student-data-exporters' |
|---|
| 4401 | |
|---|
| 4402 | def _set_session_values(self): |
|---|
| 4403 | vocab_terms = academic_sessions_vocab.by_value.values() |
|---|
| 4404 | self.sessions = [(_('All Sessions'), 'all')] |
|---|
| 4405 | self.sessions += sorted( |
|---|
| 4406 | [(x.title, x.token) for x in vocab_terms], reverse=True) |
|---|
| 4407 | return |
|---|
| 4408 | |
|---|
| 4409 | def _set_level_values(self): |
|---|
| 4410 | vocab_terms = course_levels.by_value.values() |
|---|
| 4411 | self.levels = [(_('All Levels'), 'all')] |
|---|
| 4412 | self.levels += sorted( |
|---|
| 4413 | [(x.title, x.token) for x in vocab_terms]) |
|---|
| 4414 | return |
|---|
| 4415 | |
|---|
| 4416 | def _set_semesters_values(self): |
|---|
| 4417 | utils = getUtility(IKofaUtils) |
|---|
| 4418 | self.semesters =[(_('All Semesters'), 'all')] |
|---|
| 4419 | self.semesters += sorted([(value, key) for key, value in |
|---|
| 4420 | utils.SEMESTER_DICT.items()]) |
|---|
| 4421 | return |
|---|
| 4422 | |
|---|
| 4423 | def _set_mode_values(self): |
|---|
| 4424 | utils = getUtility(IKofaUtils) |
|---|
| 4425 | self.modes =[(_('All Modes'), 'all')] |
|---|
| 4426 | self.modes += sorted([(value, key) for key, value in |
|---|
| 4427 | utils.STUDY_MODES_DICT.items()]) |
|---|
| 4428 | return |
|---|
| 4429 | |
|---|
| 4430 | def _set_paycat_values(self): |
|---|
| 4431 | utils = getUtility(IKofaUtils) |
|---|
| 4432 | self.paycats =[(_('All Payment Categories'), 'all')] |
|---|
| 4433 | self.paycats += sorted([(value, key) for key, value in |
|---|
| 4434 | utils.PAYMENT_CATEGORIES.items()]) |
|---|
| 4435 | return |
|---|
| 4436 | |
|---|
| 4437 | def _set_exporter_values(self): |
|---|
| 4438 | kofa_utils = getUtility(IKofaUtils) |
|---|
| 4439 | exporters = kofa_utils.collect_exporters(self.context) |
|---|
| 4440 | if exporters: |
|---|
| 4441 | self.exporters = exporters |
|---|
| 4442 | return |
|---|
| 4443 | exporters = [] |
|---|
| 4444 | STUDENT_EXPORTER_NAMES = getUtility( |
|---|
| 4445 | IStudentsUtils).STUDENT_EXPORTER_NAMES |
|---|
| 4446 | for name in STUDENT_EXPORTER_NAMES: |
|---|
| 4447 | util = getUtility(ICSVExporter, name=name) |
|---|
| 4448 | exporters.append((util.title, name),) |
|---|
| 4449 | self.exporters = sorted(exporters) |
|---|
| 4450 | return |
|---|
| 4451 | |
|---|
| 4452 | @property |
|---|
| 4453 | def faccode(self): |
|---|
| 4454 | return None |
|---|
| 4455 | |
|---|
| 4456 | @property |
|---|
| 4457 | def depcode(self): |
|---|
| 4458 | return None |
|---|
| 4459 | |
|---|
| 4460 | @property |
|---|
| 4461 | def certcode(self): |
|---|
| 4462 | return None |
|---|
| 4463 | |
|---|
| 4464 | def update(self, START=None, session=None, level=None, mode=None, |
|---|
| 4465 | payments_start=None, payments_end=None, ct_level=None, |
|---|
| 4466 | ct_session=None, ct_semester=None, paycat=None, |
|---|
| 4467 | paysession=None, level_session=None, exporter=None): |
|---|
| 4468 | self._set_session_values() |
|---|
| 4469 | self._set_level_values() |
|---|
| 4470 | self._set_mode_values() |
|---|
| 4471 | self._set_paycat_values() |
|---|
| 4472 | self._set_exporter_values() |
|---|
| 4473 | self._set_semesters_values() |
|---|
| 4474 | if START is None: |
|---|
| 4475 | return |
|---|
| 4476 | ena = exports_not_allowed(self) |
|---|
| 4477 | if ena: |
|---|
| 4478 | self.flash(ena, type='danger') |
|---|
| 4479 | return |
|---|
| 4480 | if payments_start or payments_end: |
|---|
| 4481 | date_format = '%d/%m/%Y' |
|---|
| 4482 | try: |
|---|
| 4483 | datetime.strptime(payments_start, date_format) |
|---|
| 4484 | datetime.strptime(payments_end, date_format) |
|---|
| 4485 | except ValueError: |
|---|
| 4486 | self.flash(_('Payment dates do not match format d/m/Y.'), |
|---|
| 4487 | type="danger") |
|---|
| 4488 | return |
|---|
| 4489 | if session == 'all': |
|---|
| 4490 | session=None |
|---|
| 4491 | if level == 'all': |
|---|
| 4492 | level = None |
|---|
| 4493 | if mode == 'all': |
|---|
| 4494 | mode = None |
|---|
| 4495 | if (mode, |
|---|
| 4496 | level, |
|---|
| 4497 | session, |
|---|
| 4498 | self.faccode, |
|---|
| 4499 | self.depcode, |
|---|
| 4500 | self.certcode) == (None, None, None, None, None, None): |
|---|
| 4501 | # Export all students including those without certificate |
|---|
| 4502 | job_id = self.context.start_export_job(exporter, |
|---|
| 4503 | self.request.principal.id, |
|---|
| 4504 | payments_start = payments_start, |
|---|
| 4505 | payments_end = payments_end, |
|---|
| 4506 | paycat=paycat, |
|---|
| 4507 | paysession=paysession, |
|---|
| 4508 | ct_level = ct_level, |
|---|
| 4509 | ct_session = ct_session, |
|---|
| 4510 | ct_semester = ct_semester, |
|---|
| 4511 | level_session=level_session, |
|---|
| 4512 | ) |
|---|
| 4513 | else: |
|---|
| 4514 | job_id = self.context.start_export_job(exporter, |
|---|
| 4515 | self.request.principal.id, |
|---|
| 4516 | current_session=session, |
|---|
| 4517 | current_level=level, |
|---|
| 4518 | current_mode=mode, |
|---|
| 4519 | faccode=self.faccode, |
|---|
| 4520 | depcode=self.depcode, |
|---|
| 4521 | certcode=self.certcode, |
|---|
| 4522 | payments_start = payments_start, |
|---|
| 4523 | payments_end = payments_end, |
|---|
| 4524 | paycat=paycat, |
|---|
| 4525 | paysession=paysession, |
|---|
| 4526 | ct_level = ct_level, |
|---|
| 4527 | ct_session = ct_session, |
|---|
| 4528 | ct_semester = ct_semester, |
|---|
| 4529 | level_session=level_session,) |
|---|
| 4530 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
|---|
| 4531 | self.context.logger.info( |
|---|
| 4532 | '%s - exported: %s (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s), job_id=%s' |
|---|
| 4533 | % (ob_class, exporter, session, level, mode, self.faccode, |
|---|
| 4534 | self.depcode, self.certcode, payments_start, payments_end, |
|---|
| 4535 | ct_level, ct_session, paycat, paysession, level_session, job_id)) |
|---|
| 4536 | self.flash(_('Export started for students with') + |
|---|
| 4537 | ' current_session=%s, current_level=%s, study_mode=%s' % ( |
|---|
| 4538 | session, level, mode)) |
|---|
| 4539 | self.redirect(self.url(self.redirect_target)) |
|---|
| 4540 | return |
|---|
| 4541 | |
|---|
| 4542 | class ExportJobContainerDownload(ExportCSVView): |
|---|
| 4543 | """Page that downloads a students export csv file. |
|---|
| 4544 | |
|---|
| 4545 | """ |
|---|
| 4546 | grok.context(VirtualExportJobContainer) |
|---|
| 4547 | grok.require('waeup.showStudents') |
|---|
| 4548 | |
|---|
| 4549 | class DatacenterExportJobContainerJobConfig(ExportJobContainerJobConfig): |
|---|
| 4550 | """Page that configures a students export job in datacenter. |
|---|
| 4551 | |
|---|
| 4552 | """ |
|---|
| 4553 | grok.name('exportconfig') |
|---|
| 4554 | grok.context(IDataCenter) |
|---|
| 4555 | redirect_target = '@@export' |
|---|
| 4556 | |
|---|
| 4557 | class DatacenterExportJobContainerSelectStudents(ExportJobContainerJobConfig): |
|---|
| 4558 | """Page that configures a students export job in datacenter. |
|---|
| 4559 | |
|---|
| 4560 | """ |
|---|
| 4561 | grok.name('exportselected') |
|---|
| 4562 | grok.context(IDataCenter) |
|---|
| 4563 | redirect_target = '@@export' |
|---|
| 4564 | grok.template('exportselected') |
|---|
| 4565 | |
|---|
| 4566 | def update(self, START=None, students=None, exporter=None): |
|---|
| 4567 | self._set_exporter_values() |
|---|
| 4568 | if START is None: |
|---|
| 4569 | return |
|---|
| 4570 | ena = exports_not_allowed(self) |
|---|
| 4571 | if ena: |
|---|
| 4572 | self.flash(ena, type='danger') |
|---|
| 4573 | return |
|---|
| 4574 | try: |
|---|
| 4575 | ids = students.replace(',', ' ').split() |
|---|
| 4576 | except: |
|---|
| 4577 | self.flash(sys.exc_info()[1]) |
|---|
| 4578 | self.redirect(self.url(self.redirect_target)) |
|---|
| 4579 | return |
|---|
| 4580 | job_id = self.context.start_export_job( |
|---|
| 4581 | exporter, self.request.principal.id, selected=ids) |
|---|
| 4582 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
|---|
| 4583 | self.context.logger.info( |
|---|
| 4584 | '%s - selected students exported: %s, job_id=%s' % |
|---|
| 4585 | (ob_class, exporter, job_id)) |
|---|
| 4586 | self.flash(_('Export of selected students started.')) |
|---|
| 4587 | self.redirect(self.url(self.redirect_target)) |
|---|
| 4588 | return |
|---|
| 4589 | |
|---|
| 4590 | class FacultiesExportJobContainerJobConfig( |
|---|
| 4591 | DatacenterExportJobContainerJobConfig): |
|---|
| 4592 | """Page that configures a students export job in facultiescontainer. |
|---|
| 4593 | |
|---|
| 4594 | """ |
|---|
| 4595 | grok.context(VirtualFacultiesExportJobContainer) |
|---|
| 4596 | redirect_target = '' |
|---|
| 4597 | |
|---|
| 4598 | class FacultiesExportJobContainerSelectStudents( |
|---|
| 4599 | DatacenterExportJobContainerSelectStudents): |
|---|
| 4600 | """Page that configures a students export job in facultiescontainer. |
|---|
| 4601 | |
|---|
| 4602 | """ |
|---|
| 4603 | grok.context(VirtualFacultiesExportJobContainer) |
|---|
| 4604 | redirect_target = '' |
|---|
| 4605 | |
|---|
| 4606 | class FacultyExportJobContainerJobConfig(DatacenterExportJobContainerJobConfig): |
|---|
| 4607 | """Page that configures a students export job in faculties. |
|---|
| 4608 | |
|---|
| 4609 | """ |
|---|
| 4610 | grok.context(VirtualFacultyExportJobContainer) |
|---|
| 4611 | redirect_target = '' |
|---|
| 4612 | |
|---|
| 4613 | @property |
|---|
| 4614 | def faccode(self): |
|---|
| 4615 | return self.context.__parent__.code |
|---|
| 4616 | |
|---|
| 4617 | class DepartmentExportJobContainerJobConfig( |
|---|
| 4618 | DatacenterExportJobContainerJobConfig): |
|---|
| 4619 | """Page that configures a students export job in departments. |
|---|
| 4620 | |
|---|
| 4621 | """ |
|---|
| 4622 | grok.context(VirtualDepartmentExportJobContainer) |
|---|
| 4623 | redirect_target = '' |
|---|
| 4624 | |
|---|
| 4625 | @property |
|---|
| 4626 | def depcode(self): |
|---|
| 4627 | return self.context.__parent__.code |
|---|
| 4628 | |
|---|
| 4629 | class CertificateExportJobContainerJobConfig( |
|---|
| 4630 | DatacenterExportJobContainerJobConfig): |
|---|
| 4631 | """Page that configures a students export job for certificates. |
|---|
| 4632 | |
|---|
| 4633 | """ |
|---|
| 4634 | grok.context(VirtualCertificateExportJobContainer) |
|---|
| 4635 | grok.template('exportconfig_certificate') |
|---|
| 4636 | redirect_target = '' |
|---|
| 4637 | |
|---|
| 4638 | @property |
|---|
| 4639 | def certcode(self): |
|---|
| 4640 | return self.context.__parent__.code |
|---|
| 4641 | |
|---|
| 4642 | class CourseExportJobContainerJobConfig( |
|---|
| 4643 | DatacenterExportJobContainerJobConfig): |
|---|
| 4644 | """Page that configures a students export job for courses. |
|---|
| 4645 | |
|---|
| 4646 | In contrast to department or certificate student data exports the |
|---|
| 4647 | coursetickets_catalog is searched here. Therefore the update |
|---|
| 4648 | method from the base class is customized. |
|---|
| 4649 | """ |
|---|
| 4650 | grok.context(VirtualCourseExportJobContainer) |
|---|
| 4651 | grok.template('exportconfig_course') |
|---|
| 4652 | redirect_target = '' |
|---|
| 4653 | |
|---|
| 4654 | def _set_exporter_values(self): |
|---|
| 4655 | # We provide only the 'coursetickets' and 'lecturer' exporter |
|---|
| 4656 | # but can add more. |
|---|
| 4657 | exporters = [] |
|---|
| 4658 | for name in ('coursetickets', 'lecturer'): |
|---|
| 4659 | util = getUtility(ICSVExporter, name=name) |
|---|
| 4660 | exporters.append((util.title, name),) |
|---|
| 4661 | self.exporters = exporters |
|---|
| 4662 | return |
|---|
| 4663 | |
|---|
| 4664 | # Disabled on 10/03/21 |
|---|
| 4665 | #def _set_session_values(self): |
|---|
| 4666 | # # We allow only current academic session |
|---|
| 4667 | # academic_session = grok.getSite()['configuration'].current_academic_session |
|---|
| 4668 | # if not academic_session: |
|---|
| 4669 | # self.sessions = [] |
|---|
| 4670 | # return |
|---|
| 4671 | # x = academic_sessions_vocab.getTerm(academic_session) |
|---|
| 4672 | # self.sessions = [(x.title, x.token)] |
|---|
| 4673 | # return |
|---|
| 4674 | |
|---|
| 4675 | def _set_session_values(self): |
|---|
| 4676 | vocab_terms = academic_sessions_vocab.by_value.values() |
|---|
| 4677 | self.sessions = sorted( |
|---|
| 4678 | [(x.title, x.token) for x in vocab_terms], reverse=True) |
|---|
| 4679 | self.sessions += [('All Sessions', 'all')] |
|---|
| 4680 | return |
|---|
| 4681 | |
|---|
| 4682 | def update(self, START=None, session=None, level=None, mode=None, |
|---|
| 4683 | exporter=None): |
|---|
| 4684 | if not checkPermission('waeup.exportData', self.context): |
|---|
| 4685 | self.flash(_('Not permitted.'), type='danger') |
|---|
| 4686 | self.redirect(self.url(self.context)) |
|---|
| 4687 | return |
|---|
| 4688 | self._set_session_values() |
|---|
| 4689 | self._set_level_values() |
|---|
| 4690 | self._set_mode_values() |
|---|
| 4691 | self._set_exporter_values() |
|---|
| 4692 | # Disabled on 10/03/21 |
|---|
| 4693 | #if not self.sessions: |
|---|
| 4694 | # self.flash( |
|---|
| 4695 | # _('Academic session not set. ' |
|---|
| 4696 | # 'Please contact the administrator.'), |
|---|
| 4697 | # type='danger') |
|---|
| 4698 | # self.redirect(self.url(self.context)) |
|---|
| 4699 | # return |
|---|
| 4700 | if START is None: |
|---|
| 4701 | return |
|---|
| 4702 | ena = exports_not_allowed(self) |
|---|
| 4703 | if ena: |
|---|
| 4704 | self.flash(ena, type='danger') |
|---|
| 4705 | return |
|---|
| 4706 | if session == 'all': |
|---|
| 4707 | session = None |
|---|
| 4708 | if level == 'all': |
|---|
| 4709 | level = None |
|---|
| 4710 | job_id = self.context.start_export_job(exporter, |
|---|
| 4711 | self.request.principal.id, |
|---|
| 4712 | # Use a different catalog and |
|---|
| 4713 | # pass different keywords than |
|---|
| 4714 | # for the (default) students_catalog |
|---|
| 4715 | catalog='coursetickets', |
|---|
| 4716 | session=session, |
|---|
| 4717 | level=level, |
|---|
| 4718 | code=self.context.__parent__.code) |
|---|
| 4719 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
|---|
| 4720 | self.context.logger.info( |
|---|
| 4721 | '%s - exported: %s (%s, %s, %s), job_id=%s' |
|---|
| 4722 | % (ob_class, exporter, session, level, |
|---|
| 4723 | self.context.__parent__.code, job_id)) |
|---|
| 4724 | self.flash(_('Export started for course tickets with') + |
|---|
| 4725 | ' level_session=%s, level=%s' % ( |
|---|
| 4726 | session, level)) |
|---|
| 4727 | self.redirect(self.url(self.redirect_target)) |
|---|
| 4728 | return |
|---|