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