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