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