[7191] | 1 | ## $Id: browser.py 9845 2013-01-08 14:24:05Z 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 | """ |
---|
[7006] | 20 | import sys |
---|
[6621] | 21 | import grok |
---|
[7275] | 22 | from urllib import urlencode |
---|
[7256] | 23 | from datetime import datetime |
---|
[8143] | 24 | from copy import deepcopy |
---|
[7015] | 25 | from zope.event import notify |
---|
[7723] | 26 | from zope.i18n import translate |
---|
[6996] | 27 | from zope.catalog.interfaces import ICatalog |
---|
[7386] | 28 | from zope.component import queryUtility, getUtility, createObject |
---|
[9467] | 29 | from zope.schema.interfaces import ConstraintNotSatisfied, RequiredMissing |
---|
[7386] | 30 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[6621] | 31 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
[7811] | 32 | from waeup.kofa.accesscodes import ( |
---|
[8420] | 33 | invalidate_accesscode, get_access_code) |
---|
[7811] | 34 | from waeup.kofa.accesscodes.workflow import USED |
---|
[9217] | 35 | from waeup.kofa.browser.layout import ( |
---|
[7819] | 36 | KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage, |
---|
[9217] | 37 | KofaForm, NullValidator) |
---|
[9797] | 38 | from waeup.kofa.browser.breadcrumbs import Breadcrumb |
---|
[9822] | 39 | from waeup.kofa.browser.pages import ContactAdminForm, ExportCSVView, doll_up |
---|
[9797] | 40 | from waeup.kofa.browser.resources import ( |
---|
| 41 | datepicker, datatable, tabs, warning, toggleall) |
---|
[7811] | 42 | from waeup.kofa.browser.layout import jsaction, action, UtilityView |
---|
[8779] | 43 | from waeup.kofa.browser.interfaces import ICaptchaManager |
---|
[9797] | 44 | from waeup.kofa.hostels.hostel import NOT_OCCUPIED |
---|
[7811] | 45 | from waeup.kofa.interfaces import ( |
---|
[7819] | 46 | IKofaObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm, |
---|
[9797] | 47 | IKofaUtils, IUniversity, IObjectHistory, academic_sessions, ICSVExporter, |
---|
[9833] | 48 | academic_sessions_vocab, IJobManager, IDataCenter) |
---|
[7811] | 49 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[8170] | 50 | from waeup.kofa.widgets.datewidget import ( |
---|
| 51 | FriendlyDateWidget, FriendlyDateDisplayWidget, |
---|
| 52 | FriendlyDatetimeDisplayWidget) |
---|
[9797] | 53 | from waeup.kofa.mandates.mandate import PasswordMandate |
---|
[9806] | 54 | from waeup.kofa.university.interfaces import ( |
---|
| 55 | IDepartment, ICertificate, ICourse) |
---|
[9797] | 56 | from waeup.kofa.university.department import ( |
---|
| 57 | VirtualDepartmentExportJobContainer,) |
---|
[9842] | 58 | from waeup.kofa.university.certificate import ( |
---|
| 59 | VirtualCertificateExportJobContainer,) |
---|
[9843] | 60 | from waeup.kofa.university.course import ( |
---|
| 61 | VirtualCourseExportJobContainer,) |
---|
[9797] | 62 | from waeup.kofa.university.vocabularies import course_levels |
---|
[9813] | 63 | from waeup.kofa.utils.batching import VirtualExportJobContainer |
---|
[9797] | 64 | from waeup.kofa.utils.helpers import get_current_principal, to_timezone |
---|
[7868] | 65 | from waeup.kofa.widgets.restwidget import ReSTDisplayWidget |
---|
[7811] | 66 | from waeup.kofa.students.interfaces import ( |
---|
[7993] | 67 | IStudentsContainer, IStudent, |
---|
| 68 | IUGStudentClearance,IPGStudentClearance, |
---|
[9563] | 69 | IStudentPersonal, IStudentPersonalEdit, IStudentBase, IStudentStudyCourse, |
---|
[9138] | 70 | IStudentStudyCourseTransfer, |
---|
[7538] | 71 | IStudentAccommodation, IStudentStudyLevel, |
---|
[6877] | 72 | ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer, |
---|
[9148] | 73 | IStudentOnlinePayment, IStudentPreviousPayment, |
---|
| 74 | IBedTicket, IStudentsUtils, IStudentRequestPW |
---|
[6621] | 75 | ) |
---|
[9806] | 76 | from waeup.kofa.students.catalog import search, StudentQueryResultItem |
---|
[9804] | 77 | from waeup.kofa.students.export import EXPORTER_NAMES |
---|
[9797] | 78 | from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket |
---|
| 79 | from waeup.kofa.students.vocabularies import StudyLevelSource |
---|
[8779] | 80 | from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID, |
---|
[9028] | 81 | CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED, |
---|
| 82 | FORBIDDEN_POSTGRAD_TRANS) |
---|
[6621] | 83 | |
---|
[9797] | 84 | |
---|
[8779] | 85 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
| 86 | |
---|
[8737] | 87 | # Save function used for save methods in pages |
---|
| 88 | def msave(view, **data): |
---|
| 89 | changed_fields = view.applyData(view.context, **data) |
---|
| 90 | # Turn list of lists into single list |
---|
| 91 | if changed_fields: |
---|
| 92 | changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) |
---|
| 93 | # Inform catalog if certificate has changed |
---|
| 94 | # (applyData does this only for the context) |
---|
| 95 | if 'certificate' in changed_fields: |
---|
| 96 | notify(grok.ObjectModifiedEvent(view.context.student)) |
---|
| 97 | fields_string = ' + '.join(changed_fields) |
---|
| 98 | view.flash(_('Form has been saved.')) |
---|
| 99 | if fields_string: |
---|
| 100 | view.context.writeLogMessage(view, 'saved: %s' % fields_string) |
---|
| 101 | return |
---|
| 102 | |
---|
[7145] | 103 | def emit_lock_message(view): |
---|
[7642] | 104 | """Flash a lock message. |
---|
| 105 | """ |
---|
[7723] | 106 | view.flash(_('The requested form is locked (read-only).')) |
---|
[7133] | 107 | view.redirect(view.url(view.context)) |
---|
| 108 | return |
---|
| 109 | |
---|
[8921] | 110 | def translated_values(view): |
---|
[9685] | 111 | """Translate course ticket attribute values to be displayed on |
---|
| 112 | studylevel pages. |
---|
| 113 | """ |
---|
[8921] | 114 | lang = view.request.cookies.get('kofa.language') |
---|
| 115 | for value in view.context.values(): |
---|
[9328] | 116 | # We have to unghostify (according to Tres Seaver) the __dict__ |
---|
| 117 | # by activating the object, otherwise value_dict will be empty |
---|
| 118 | # when calling the first time. |
---|
[9330] | 119 | value._p_activate() |
---|
[8921] | 120 | value_dict = dict([i for i in value.__dict__.items()]) |
---|
[9698] | 121 | value_dict['removable_by_student'] = value.removable_by_student |
---|
[8921] | 122 | value_dict['mandatory'] = translate(str(value.mandatory), 'zope', |
---|
| 123 | target_language=lang) |
---|
| 124 | value_dict['carry_over'] = translate(str(value.carry_over), 'zope', |
---|
| 125 | target_language=lang) |
---|
| 126 | value_dict['automatic'] = translate(str(value.automatic), 'zope', |
---|
| 127 | target_language=lang) |
---|
[9685] | 128 | value_dict['grade'] = value.grade |
---|
| 129 | value_dict['weight'] = value.weight |
---|
[8921] | 130 | yield value_dict |
---|
| 131 | |
---|
[9814] | 132 | def clearance_disabled_message(student): |
---|
| 133 | try: |
---|
| 134 | session_config = grok.getSite()[ |
---|
| 135 | 'configuration'][str(student.current_session)] |
---|
| 136 | except KeyError: |
---|
| 137 | return _('Session configuration object is not available.') |
---|
| 138 | if not session_config.clearance_enabled: |
---|
| 139 | return _('Clearance is disabled for this session.') |
---|
| 140 | return None |
---|
| 141 | |
---|
[6629] | 142 | class StudentsBreadcrumb(Breadcrumb): |
---|
| 143 | """A breadcrumb for the students container. |
---|
| 144 | """ |
---|
| 145 | grok.context(IStudentsContainer) |
---|
[7723] | 146 | title = _('Students') |
---|
[6629] | 147 | |
---|
[7459] | 148 | @property |
---|
| 149 | def target(self): |
---|
| 150 | user = get_current_principal() |
---|
| 151 | if getattr(user, 'user_type', None) == 'student': |
---|
| 152 | return None |
---|
| 153 | return self.viewname |
---|
| 154 | |
---|
[6818] | 155 | class StudentBreadcrumb(Breadcrumb): |
---|
| 156 | """A breadcrumb for the student container. |
---|
| 157 | """ |
---|
| 158 | grok.context(IStudent) |
---|
| 159 | |
---|
| 160 | def title(self): |
---|
[7364] | 161 | return self.context.display_fullname |
---|
[6818] | 162 | |
---|
[6635] | 163 | class SudyCourseBreadcrumb(Breadcrumb): |
---|
| 164 | """A breadcrumb for the student study course. |
---|
| 165 | """ |
---|
| 166 | grok.context(IStudentStudyCourse) |
---|
| 167 | |
---|
[9140] | 168 | def title(self): |
---|
| 169 | if self.context.is_current: |
---|
| 170 | return _('Study Course') |
---|
| 171 | else: |
---|
| 172 | return _('Previous Study Course') |
---|
| 173 | |
---|
[6635] | 174 | class PaymentsBreadcrumb(Breadcrumb): |
---|
| 175 | """A breadcrumb for the student payments folder. |
---|
| 176 | """ |
---|
[6859] | 177 | grok.context(IStudentPaymentsContainer) |
---|
[7723] | 178 | title = _('Payments') |
---|
[6635] | 179 | |
---|
[6870] | 180 | class OnlinePaymentBreadcrumb(Breadcrumb): |
---|
[7251] | 181 | """A breadcrumb for payments. |
---|
[6870] | 182 | """ |
---|
[6877] | 183 | grok.context(IStudentOnlinePayment) |
---|
[6870] | 184 | |
---|
| 185 | @property |
---|
| 186 | def title(self): |
---|
| 187 | return self.context.p_id |
---|
| 188 | |
---|
[6635] | 189 | class AccommodationBreadcrumb(Breadcrumb): |
---|
| 190 | """A breadcrumb for the student accommodation folder. |
---|
| 191 | """ |
---|
| 192 | grok.context(IStudentAccommodation) |
---|
[7723] | 193 | title = _('Accommodation') |
---|
[6635] | 194 | |
---|
[6994] | 195 | class BedTicketBreadcrumb(Breadcrumb): |
---|
| 196 | """A breadcrumb for bed tickets. |
---|
| 197 | """ |
---|
| 198 | grok.context(IBedTicket) |
---|
[7009] | 199 | |
---|
[6994] | 200 | @property |
---|
| 201 | def title(self): |
---|
[7723] | 202 | return _('Bed Ticket ${a}', |
---|
| 203 | mapping = {'a':self.context.getSessionString()}) |
---|
[6994] | 204 | |
---|
[6776] | 205 | class StudyLevelBreadcrumb(Breadcrumb): |
---|
| 206 | """A breadcrumb for course lists. |
---|
| 207 | """ |
---|
| 208 | grok.context(IStudentStudyLevel) |
---|
| 209 | |
---|
| 210 | @property |
---|
| 211 | def title(self): |
---|
[7834] | 212 | return self.context.level_title |
---|
[6776] | 213 | |
---|
[7819] | 214 | class StudentsContainerPage(KofaPage): |
---|
[6626] | 215 | """The standard view for student containers. |
---|
[6621] | 216 | """ |
---|
| 217 | grok.context(IStudentsContainer) |
---|
| 218 | grok.name('index') |
---|
[7240] | 219 | grok.require('waeup.viewStudentsContainer') |
---|
[6695] | 220 | grok.template('containerpage') |
---|
[7723] | 221 | label = _('Student Section') |
---|
[7735] | 222 | search_button = _('Search') |
---|
[6642] | 223 | pnav = 4 |
---|
[6621] | 224 | |
---|
[6626] | 225 | def update(self, *args, **kw): |
---|
| 226 | datatable.need() |
---|
| 227 | form = self.request.form |
---|
| 228 | self.hitlist = [] |
---|
[9795] | 229 | if form.get('searchtype', None) == 'suspended': |
---|
| 230 | self.searchtype = form['searchtype'] |
---|
| 231 | self.searchterm = None |
---|
| 232 | elif 'searchterm' in form and form['searchterm']: |
---|
[6626] | 233 | self.searchterm = form['searchterm'] |
---|
| 234 | self.searchtype = form['searchtype'] |
---|
| 235 | elif 'old_searchterm' in form: |
---|
| 236 | self.searchterm = form['old_searchterm'] |
---|
| 237 | self.searchtype = form['old_searchtype'] |
---|
| 238 | else: |
---|
| 239 | if 'search' in form: |
---|
[7745] | 240 | self.flash(_('Empty search string')) |
---|
[6626] | 241 | return |
---|
[7068] | 242 | if self.searchtype == 'current_session': |
---|
[8081] | 243 | try: |
---|
| 244 | self.searchterm = int(self.searchterm) |
---|
| 245 | except ValueError: |
---|
[8404] | 246 | self.flash(_('Only year dates allowed (e.g. 2011).')) |
---|
[8081] | 247 | return |
---|
[6626] | 248 | self.hitlist = search(query=self.searchterm, |
---|
| 249 | searchtype=self.searchtype, view=self) |
---|
| 250 | if not self.hitlist: |
---|
[8404] | 251 | self.flash(_('No student found.')) |
---|
[6626] | 252 | return |
---|
| 253 | |
---|
[7819] | 254 | class StudentsContainerManagePage(KofaPage): |
---|
[6626] | 255 | """The manage page for student containers. |
---|
[6622] | 256 | """ |
---|
| 257 | grok.context(IStudentsContainer) |
---|
| 258 | grok.name('manage') |
---|
[7136] | 259 | grok.require('waeup.manageStudent') |
---|
[6695] | 260 | grok.template('containermanagepage') |
---|
[6642] | 261 | pnav = 4 |
---|
[7723] | 262 | label = _('Manage student section') |
---|
[7735] | 263 | search_button = _('Search') |
---|
| 264 | remove_button = _('Remove selected') |
---|
[6622] | 265 | |
---|
[6626] | 266 | def update(self, *args, **kw): |
---|
| 267 | datatable.need() |
---|
[6820] | 268 | toggleall.need() |
---|
[7329] | 269 | warning.need() |
---|
[6626] | 270 | form = self.request.form |
---|
| 271 | self.hitlist = [] |
---|
[9795] | 272 | if form.get('searchtype', None) == 'suspended': |
---|
| 273 | self.searchtype = form['searchtype'] |
---|
| 274 | self.searchterm = None |
---|
| 275 | elif 'searchterm' in form and form['searchterm']: |
---|
[6626] | 276 | self.searchterm = form['searchterm'] |
---|
| 277 | self.searchtype = form['searchtype'] |
---|
| 278 | elif 'old_searchterm' in form: |
---|
| 279 | self.searchterm = form['old_searchterm'] |
---|
| 280 | self.searchtype = form['old_searchtype'] |
---|
| 281 | else: |
---|
| 282 | if 'search' in form: |
---|
[7745] | 283 | self.flash(_('Empty search string')) |
---|
[6626] | 284 | return |
---|
[8082] | 285 | if self.searchtype == 'current_session': |
---|
| 286 | try: |
---|
| 287 | self.searchterm = int(self.searchterm) |
---|
| 288 | except ValueError: |
---|
| 289 | self.flash('Only year dates allowed (e.g. 2011).') |
---|
| 290 | return |
---|
[6626] | 291 | if not 'entries' in form: |
---|
| 292 | self.hitlist = search(query=self.searchterm, |
---|
| 293 | searchtype=self.searchtype, view=self) |
---|
| 294 | if not self.hitlist: |
---|
[7723] | 295 | self.flash(_('No student found.')) |
---|
[7459] | 296 | if 'remove' in form: |
---|
[7723] | 297 | self.flash(_('No item selected.')) |
---|
[6626] | 298 | return |
---|
| 299 | entries = form['entries'] |
---|
| 300 | if isinstance(entries, basestring): |
---|
| 301 | entries = [entries] |
---|
| 302 | deleted = [] |
---|
| 303 | for entry in entries: |
---|
| 304 | if 'remove' in form: |
---|
| 305 | del self.context[entry] |
---|
| 306 | deleted.append(entry) |
---|
| 307 | self.hitlist = search(query=self.searchterm, |
---|
| 308 | searchtype=self.searchtype, view=self) |
---|
| 309 | if len(deleted): |
---|
[7723] | 310 | self.flash(_('Successfully removed: ${a}', |
---|
| 311 | mapping = {'a':', '.join(deleted)})) |
---|
[6622] | 312 | return |
---|
| 313 | |
---|
[7819] | 314 | class StudentAddFormPage(KofaAddFormPage): |
---|
[6622] | 315 | """Add-form to add a student. |
---|
| 316 | """ |
---|
| 317 | grok.context(IStudentsContainer) |
---|
[7136] | 318 | grok.require('waeup.manageStudent') |
---|
[6622] | 319 | grok.name('addstudent') |
---|
[7357] | 320 | form_fields = grok.AutoFields(IStudent).select( |
---|
[7520] | 321 | 'firstname', 'middlename', 'lastname', 'reg_number') |
---|
[7723] | 322 | label = _('Add student') |
---|
[6642] | 323 | pnav = 4 |
---|
[6622] | 324 | |
---|
[7723] | 325 | @action(_('Create student record'), style='primary') |
---|
[6622] | 326 | def addStudent(self, **data): |
---|
| 327 | student = createObject(u'waeup.Student') |
---|
| 328 | self.applyData(student, **data) |
---|
[6652] | 329 | self.context.addStudent(student) |
---|
[7723] | 330 | self.flash(_('Student record created.')) |
---|
[6651] | 331 | self.redirect(self.url(self.context[student.student_id], 'index')) |
---|
[6622] | 332 | return |
---|
| 333 | |
---|
[9338] | 334 | class LoginAsStudentStep1(KofaEditFormPage): |
---|
| 335 | """ View to temporarily set a student password. |
---|
| 336 | """ |
---|
| 337 | grok.context(IStudent) |
---|
| 338 | grok.name('loginasstep1') |
---|
| 339 | grok.require('waeup.loginAsStudent') |
---|
| 340 | grok.template('loginasstep1') |
---|
| 341 | pnav = 4 |
---|
| 342 | |
---|
| 343 | def label(self): |
---|
| 344 | return _(u'Set temporary password for ${a}', |
---|
| 345 | mapping = {'a':self.context.display_fullname}) |
---|
| 346 | |
---|
| 347 | @action('Set password now', style='primary') |
---|
| 348 | def setPassword(self, *args, **data): |
---|
| 349 | kofa_utils = getUtility(IKofaUtils) |
---|
| 350 | password = kofa_utils.genPassword() |
---|
| 351 | self.context.setTempPassword(self.request.principal.id, password) |
---|
| 352 | self.context.writeLogMessage( |
---|
| 353 | self, 'temp_password generated: %s' % password) |
---|
| 354 | args = {'password':password} |
---|
| 355 | self.redirect(self.url(self.context) + |
---|
| 356 | '/loginasstep2?%s' % urlencode(args)) |
---|
| 357 | return |
---|
| 358 | |
---|
| 359 | class LoginAsStudentStep2(KofaPage): |
---|
| 360 | """ View to temporarily login as student with a temporary password. |
---|
| 361 | """ |
---|
| 362 | grok.context(IStudent) |
---|
| 363 | grok.name('loginasstep2') |
---|
| 364 | grok.require('waeup.Public') |
---|
| 365 | grok.template('loginasstep2') |
---|
| 366 | login_button = _('Login now') |
---|
| 367 | pnav = 4 |
---|
| 368 | |
---|
| 369 | def label(self): |
---|
| 370 | return _(u'Login as ${a}', |
---|
| 371 | mapping = {'a':self.context.student_id}) |
---|
| 372 | |
---|
| 373 | def update(self, SUBMIT=None, password=None): |
---|
| 374 | self.password = password |
---|
| 375 | if SUBMIT is not None: |
---|
| 376 | self.flash(_('You successfully logged in as student.')) |
---|
| 377 | self.redirect(self.url(self.context)) |
---|
| 378 | return |
---|
| 379 | |
---|
[7819] | 380 | class StudentBaseDisplayFormPage(KofaDisplayFormPage): |
---|
[6631] | 381 | """ Page to display student base data |
---|
| 382 | """ |
---|
[6622] | 383 | grok.context(IStudent) |
---|
| 384 | grok.name('index') |
---|
[6660] | 385 | grok.require('waeup.viewStudent') |
---|
[6695] | 386 | grok.template('basepage') |
---|
[9702] | 387 | form_fields = grok.AutoFields(IStudentBase).omit( |
---|
| 388 | 'password', 'suspended', 'suspended_comment') |
---|
[6642] | 389 | pnav = 4 |
---|
[6622] | 390 | |
---|
| 391 | @property |
---|
| 392 | def label(self): |
---|
[8983] | 393 | if self.context.suspended: |
---|
[9124] | 394 | return _('${a}: Base Data (account deactivated)', |
---|
[8983] | 395 | mapping = {'a':self.context.display_fullname}) |
---|
| 396 | return _('${a}: Base Data', |
---|
[7723] | 397 | mapping = {'a':self.context.display_fullname}) |
---|
[6631] | 398 | |
---|
[6699] | 399 | @property |
---|
| 400 | def hasPassword(self): |
---|
| 401 | if self.context.password: |
---|
[7723] | 402 | return _('set') |
---|
| 403 | return _('unset') |
---|
[6699] | 404 | |
---|
[9141] | 405 | class StudentBasePDFFormPage(KofaDisplayFormPage): |
---|
| 406 | """ Page to display student base data in pdf files. |
---|
| 407 | """ |
---|
| 408 | |
---|
[9374] | 409 | def __init__(self, context, request, omit_fields): |
---|
| 410 | self.omit_fields = omit_fields |
---|
| 411 | super(StudentBasePDFFormPage, self).__init__(context, request) |
---|
| 412 | |
---|
| 413 | @property |
---|
| 414 | def form_fields(self): |
---|
| 415 | form_fields = grok.AutoFields(IStudentBase) |
---|
| 416 | for field in self.omit_fields: |
---|
| 417 | form_fields = form_fields.omit(field) |
---|
| 418 | return form_fields |
---|
| 419 | |
---|
[7229] | 420 | class ContactStudentForm(ContactAdminForm): |
---|
| 421 | grok.context(IStudent) |
---|
[7230] | 422 | grok.name('contactstudent') |
---|
[7275] | 423 | grok.require('waeup.viewStudent') |
---|
[7229] | 424 | pnav = 4 |
---|
| 425 | form_fields = grok.AutoFields(IContactForm).select('subject', 'body') |
---|
| 426 | |
---|
[9484] | 427 | def update(self, subject=u'', body=u''): |
---|
[7275] | 428 | self.form_fields.get('subject').field.default = subject |
---|
[9484] | 429 | self.form_fields.get('body').field.default = body |
---|
[9758] | 430 | return super(ContactStudentForm, self).update() |
---|
[7275] | 431 | |
---|
[7229] | 432 | def label(self): |
---|
[7723] | 433 | return _(u'Send message to ${a}', |
---|
| 434 | mapping = {'a':self.context.display_fullname}) |
---|
[7229] | 435 | |
---|
[7459] | 436 | @action('Send message now', style='primary') |
---|
[7229] | 437 | def send(self, *args, **data): |
---|
[7234] | 438 | try: |
---|
[7403] | 439 | email = self.request.principal.email |
---|
[7234] | 440 | except AttributeError: |
---|
[7403] | 441 | email = self.config.email_admin |
---|
| 442 | usertype = getattr(self.request.principal, |
---|
| 443 | 'user_type', 'system').title() |
---|
[7819] | 444 | kofa_utils = getUtility(IKofaUtils) |
---|
[7811] | 445 | success = kofa_utils.sendContactForm( |
---|
[7403] | 446 | self.request.principal.title,email, |
---|
| 447 | self.context.display_fullname,self.context.email, |
---|
| 448 | self.request.principal.id,usertype, |
---|
| 449 | self.config.name, |
---|
| 450 | data['body'],data['subject']) |
---|
[7229] | 451 | if success: |
---|
[7723] | 452 | self.flash(_('Your message has been sent.')) |
---|
[7229] | 453 | else: |
---|
[7723] | 454 | self.flash(_('An smtp server error occurred.')) |
---|
[7229] | 455 | return |
---|
| 456 | |
---|
[9191] | 457 | class ExportPDFAdmissionSlipPage(UtilityView, grok.View): |
---|
| 458 | """Deliver a PDF Admission slip. |
---|
| 459 | """ |
---|
| 460 | grok.context(IStudent) |
---|
| 461 | grok.name('admission_slip.pdf') |
---|
| 462 | grok.require('waeup.viewStudent') |
---|
| 463 | prefix = 'form' |
---|
| 464 | |
---|
| 465 | form_fields = grok.AutoFields(IStudentBase).select('student_id', 'reg_number') |
---|
| 466 | |
---|
| 467 | @property |
---|
| 468 | def label(self): |
---|
| 469 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 470 | return translate(_('Admission Letter of'), |
---|
| 471 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 472 | + ' %s' % self.context.display_fullname |
---|
| 473 | |
---|
| 474 | def render(self): |
---|
| 475 | students_utils = getUtility(IStudentsUtils) |
---|
| 476 | return students_utils.renderPDFAdmissionLetter(self, |
---|
| 477 | self.context.student) |
---|
| 478 | |
---|
[7819] | 479 | class StudentBaseManageFormPage(KofaEditFormPage): |
---|
[7133] | 480 | """ View to manage student base data |
---|
[6631] | 481 | """ |
---|
| 482 | grok.context(IStudent) |
---|
[7133] | 483 | grok.name('manage_base') |
---|
[7136] | 484 | grok.require('waeup.manageStudent') |
---|
[9124] | 485 | form_fields = grok.AutoFields(IStudentBase).omit( |
---|
| 486 | 'student_id', 'adm_code', 'suspended') |
---|
[6695] | 487 | grok.template('basemanagepage') |
---|
[7723] | 488 | label = _('Manage base data') |
---|
[6642] | 489 | pnav = 4 |
---|
[6631] | 490 | |
---|
[6638] | 491 | def update(self): |
---|
| 492 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
[7134] | 493 | tabs.need() |
---|
[7490] | 494 | self.tab1 = self.tab2 = '' |
---|
| 495 | qs = self.request.get('QUERY_STRING', '') |
---|
| 496 | if not qs: |
---|
| 497 | qs = 'tab1' |
---|
| 498 | setattr(self, qs, 'active') |
---|
[6638] | 499 | super(StudentBaseManageFormPage, self).update() |
---|
| 500 | self.wf_info = IWorkflowInfo(self.context) |
---|
| 501 | return |
---|
| 502 | |
---|
[7723] | 503 | @action(_('Save'), style='primary') |
---|
[6638] | 504 | def save(self, **data): |
---|
[6701] | 505 | form = self.request.form |
---|
[6790] | 506 | password = form.get('password', None) |
---|
| 507 | password_ctl = form.get('control_password', None) |
---|
| 508 | if password: |
---|
[7147] | 509 | validator = getUtility(IPasswordValidator) |
---|
| 510 | errors = validator.validate_password(password, password_ctl) |
---|
| 511 | if errors: |
---|
| 512 | self.flash( ' '.join(errors)) |
---|
| 513 | return |
---|
| 514 | changed_fields = self.applyData(self.context, **data) |
---|
[6771] | 515 | # Turn list of lists into single list |
---|
| 516 | if changed_fields: |
---|
| 517 | changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) |
---|
[7147] | 518 | else: |
---|
| 519 | changed_fields = [] |
---|
| 520 | if password: |
---|
[9273] | 521 | # Now we know that the form has no errors and can set password |
---|
[7147] | 522 | IUserAccount(self.context).setPassword(password) |
---|
| 523 | changed_fields.append('password') |
---|
| 524 | fields_string = ' + '.join(changed_fields) |
---|
[7723] | 525 | self.flash(_('Form has been saved.')) |
---|
[6644] | 526 | if fields_string: |
---|
[8735] | 527 | self.context.writeLogMessage(self, 'saved: % s' % fields_string) |
---|
[6638] | 528 | return |
---|
| 529 | |
---|
[9273] | 530 | class StudentTriggerTransitionFormPage(KofaEditFormPage): |
---|
| 531 | """ View to manage student base data |
---|
| 532 | """ |
---|
| 533 | grok.context(IStudent) |
---|
| 534 | grok.name('trigtrans') |
---|
| 535 | grok.require('waeup.triggerTransition') |
---|
| 536 | grok.template('trigtrans') |
---|
| 537 | label = _('Trigger registration transition') |
---|
| 538 | pnav = 4 |
---|
| 539 | |
---|
| 540 | def getTransitions(self): |
---|
| 541 | """Return a list of dicts of allowed transition ids and titles. |
---|
| 542 | |
---|
| 543 | Each list entry provides keys ``name`` and ``title`` for |
---|
| 544 | internal name and (human readable) title of a single |
---|
| 545 | transition. |
---|
| 546 | """ |
---|
| 547 | wf_info = IWorkflowInfo(self.context) |
---|
| 548 | allowed_transitions = [t for t in wf_info.getManualTransitions() |
---|
| 549 | if not t[0].startswith('pay')] |
---|
| 550 | if self.context.is_postgrad: |
---|
| 551 | allowed_transitions = [t for t in allowed_transitions |
---|
| 552 | if not t[0] in FORBIDDEN_POSTGRAD_TRANS] |
---|
| 553 | return [dict(name='', title=_('No transition'))] +[ |
---|
| 554 | dict(name=x, title=y) for x, y in allowed_transitions] |
---|
| 555 | |
---|
| 556 | @action(_('Save'), style='primary') |
---|
| 557 | def save(self, **data): |
---|
| 558 | form = self.request.form |
---|
[9701] | 559 | if 'transition' in form and form['transition']: |
---|
[9273] | 560 | transition_id = form['transition'] |
---|
| 561 | wf_info = IWorkflowInfo(self.context) |
---|
| 562 | wf_info.fireTransition(transition_id) |
---|
| 563 | return |
---|
| 564 | |
---|
[9124] | 565 | class StudentActivatePage(UtilityView, grok.View): |
---|
| 566 | """ Activate student account |
---|
| 567 | """ |
---|
| 568 | grok.context(IStudent) |
---|
| 569 | grok.name('activate') |
---|
| 570 | grok.require('waeup.manageStudent') |
---|
| 571 | |
---|
| 572 | def update(self): |
---|
| 573 | self.context.suspended = False |
---|
| 574 | self.context.writeLogMessage(self, 'account activated') |
---|
| 575 | history = IObjectHistory(self.context) |
---|
| 576 | history.addMessage('Student account activated') |
---|
| 577 | self.flash(_('Student account has been activated.')) |
---|
| 578 | self.redirect(self.url(self.context)) |
---|
| 579 | return |
---|
| 580 | |
---|
| 581 | def render(self): |
---|
| 582 | return |
---|
| 583 | |
---|
| 584 | class StudentDeactivatePage(UtilityView, grok.View): |
---|
| 585 | """ Deactivate student account |
---|
| 586 | """ |
---|
| 587 | grok.context(IStudent) |
---|
| 588 | grok.name('deactivate') |
---|
| 589 | grok.require('waeup.manageStudent') |
---|
| 590 | |
---|
| 591 | def update(self): |
---|
| 592 | self.context.suspended = True |
---|
| 593 | self.context.writeLogMessage(self, 'account deactivated') |
---|
| 594 | history = IObjectHistory(self.context) |
---|
| 595 | history.addMessage('Student account deactivated') |
---|
| 596 | self.flash(_('Student account has been deactivated.')) |
---|
| 597 | self.redirect(self.url(self.context)) |
---|
| 598 | return |
---|
| 599 | |
---|
| 600 | def render(self): |
---|
| 601 | return |
---|
| 602 | |
---|
[7819] | 603 | class StudentClearanceDisplayFormPage(KofaDisplayFormPage): |
---|
[6631] | 604 | """ Page to display student clearance data |
---|
| 605 | """ |
---|
| 606 | grok.context(IStudent) |
---|
| 607 | grok.name('view_clearance') |
---|
[6660] | 608 | grok.require('waeup.viewStudent') |
---|
[6642] | 609 | pnav = 4 |
---|
[6631] | 610 | |
---|
| 611 | @property |
---|
[8099] | 612 | def separators(self): |
---|
| 613 | return getUtility(IStudentsUtils).SEPARATORS_DICT |
---|
| 614 | |
---|
| 615 | @property |
---|
[7993] | 616 | def form_fields(self): |
---|
[8472] | 617 | if self.context.is_postgrad: |
---|
[8977] | 618 | form_fields = grok.AutoFields( |
---|
| 619 | IPGStudentClearance).omit('clearance_locked') |
---|
[7993] | 620 | else: |
---|
[8977] | 621 | form_fields = grok.AutoFields( |
---|
| 622 | IUGStudentClearance).omit('clearance_locked') |
---|
[9486] | 623 | if not getattr(self.context, 'officer_comment'): |
---|
| 624 | form_fields = form_fields.omit('officer_comment') |
---|
[9484] | 625 | else: |
---|
[9486] | 626 | form_fields['officer_comment'].custom_widget = BytesDisplayWidget |
---|
[7993] | 627 | return form_fields |
---|
| 628 | |
---|
| 629 | @property |
---|
[6631] | 630 | def label(self): |
---|
[7723] | 631 | return _('${a}: Clearance Data', |
---|
| 632 | mapping = {'a':self.context.display_fullname}) |
---|
[6631] | 633 | |
---|
[7277] | 634 | class ExportPDFClearanceSlipPage(grok.View): |
---|
| 635 | """Deliver a PDF slip of the context. |
---|
| 636 | """ |
---|
| 637 | grok.context(IStudent) |
---|
[9452] | 638 | grok.name('clearance_slip.pdf') |
---|
[7277] | 639 | grok.require('waeup.viewStudent') |
---|
| 640 | prefix = 'form' |
---|
[9702] | 641 | omit_fields = ( |
---|
| 642 | 'password', 'suspended', 'phone', |
---|
| 643 | 'adm_code', 'suspended_comment') |
---|
[7277] | 644 | |
---|
| 645 | @property |
---|
[7993] | 646 | def form_fields(self): |
---|
[8472] | 647 | if self.context.is_postgrad: |
---|
[8977] | 648 | form_fields = grok.AutoFields( |
---|
| 649 | IPGStudentClearance).omit('clearance_locked') |
---|
[7993] | 650 | else: |
---|
[8977] | 651 | form_fields = grok.AutoFields( |
---|
| 652 | IUGStudentClearance).omit('clearance_locked') |
---|
[9486] | 653 | if not getattr(self.context, 'officer_comment'): |
---|
| 654 | form_fields = form_fields.omit('officer_comment') |
---|
[7993] | 655 | return form_fields |
---|
| 656 | |
---|
| 657 | @property |
---|
[7723] | 658 | def title(self): |
---|
[7819] | 659 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 660 | return translate(_('Clearance Data'), 'waeup.kofa', |
---|
[7723] | 661 | target_language=portal_language) |
---|
| 662 | |
---|
| 663 | @property |
---|
[7277] | 664 | def label(self): |
---|
[7819] | 665 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9026] | 666 | return translate(_('Clearance Slip of'), |
---|
[7811] | 667 | 'waeup.kofa', target_language=portal_language) \ |
---|
[7723] | 668 | + ' %s' % self.context.display_fullname |
---|
[7277] | 669 | |
---|
[9010] | 670 | def _signatures(self): |
---|
[9548] | 671 | isStudent = getattr( |
---|
| 672 | self.request.principal, 'user_type', None) == 'student' |
---|
| 673 | if not isStudent and self.context.state in (CLEARED, ): |
---|
[9010] | 674 | return (_('Student Signature'), _('Clearance Officer Signature')) |
---|
| 675 | return |
---|
| 676 | |
---|
[9555] | 677 | def _sigsInFooter(self): |
---|
[9548] | 678 | isStudent = getattr( |
---|
| 679 | self.request.principal, 'user_type', None) == 'student' |
---|
| 680 | if not isStudent and self.context.state in (CLEARED, ): |
---|
[9555] | 681 | return (_('Date, Student Signature'), |
---|
| 682 | _('Date, Clearance Officer Signature'), |
---|
| 683 | ) |
---|
[9557] | 684 | return () |
---|
[9548] | 685 | |
---|
[7277] | 686 | def render(self): |
---|
[9141] | 687 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[9375] | 688 | self.request, self.omit_fields) |
---|
[7277] | 689 | students_utils = getUtility(IStudentsUtils) |
---|
| 690 | return students_utils.renderPDF( |
---|
[9452] | 691 | self, 'clearance_slip.pdf', |
---|
[9548] | 692 | self.context.student, studentview, signatures=self._signatures(), |
---|
[9555] | 693 | sigs_in_footer=self._sigsInFooter()) |
---|
[7277] | 694 | |
---|
[7819] | 695 | class StudentClearanceManageFormPage(KofaEditFormPage): |
---|
[8120] | 696 | """ Page to manage student clearance data |
---|
[6631] | 697 | """ |
---|
| 698 | grok.context(IStudent) |
---|
[8119] | 699 | grok.name('manage_clearance') |
---|
[7136] | 700 | grok.require('waeup.manageStudent') |
---|
[7134] | 701 | grok.template('clearanceeditpage') |
---|
[7723] | 702 | label = _('Manage clearance data') |
---|
[6642] | 703 | pnav = 4 |
---|
[6650] | 704 | |
---|
[7993] | 705 | @property |
---|
[8099] | 706 | def separators(self): |
---|
| 707 | return getUtility(IStudentsUtils).SEPARATORS_DICT |
---|
| 708 | |
---|
| 709 | @property |
---|
[7993] | 710 | def form_fields(self): |
---|
[8472] | 711 | if self.context.is_postgrad: |
---|
[8977] | 712 | form_fields = grok.AutoFields(IPGStudentClearance).omit('clr_code') |
---|
[7993] | 713 | else: |
---|
[8977] | 714 | form_fields = grok.AutoFields(IUGStudentClearance).omit('clr_code') |
---|
[7993] | 715 | return form_fields |
---|
| 716 | |
---|
[6650] | 717 | def update(self): |
---|
| 718 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
[7134] | 719 | tabs.need() |
---|
[7490] | 720 | self.tab1 = self.tab2 = '' |
---|
| 721 | qs = self.request.get('QUERY_STRING', '') |
---|
| 722 | if not qs: |
---|
| 723 | qs = 'tab1' |
---|
| 724 | setattr(self, qs, 'active') |
---|
[6650] | 725 | return super(StudentClearanceManageFormPage, self).update() |
---|
| 726 | |
---|
[7723] | 727 | @action(_('Save'), style='primary') |
---|
[6695] | 728 | def save(self, **data): |
---|
[6762] | 729 | msave(self, **data) |
---|
[6695] | 730 | return |
---|
| 731 | |
---|
[7459] | 732 | class StudentClearPage(UtilityView, grok.View): |
---|
[7158] | 733 | """ Clear student by clearance officer |
---|
| 734 | """ |
---|
| 735 | grok.context(IStudent) |
---|
| 736 | grok.name('clear') |
---|
| 737 | grok.require('waeup.clearStudent') |
---|
| 738 | |
---|
| 739 | def update(self): |
---|
[9814] | 740 | if clearance_disabled_message(self.context): |
---|
| 741 | self.flash(clearance_disabled_message(self.context)) |
---|
| 742 | self.redirect(self.url(self.context,'view_clearance')) |
---|
| 743 | return |
---|
[7158] | 744 | if self.context.state == REQUESTED: |
---|
| 745 | IWorkflowInfo(self.context).fireTransition('clear') |
---|
[7723] | 746 | self.flash(_('Student has been cleared.')) |
---|
[7158] | 747 | else: |
---|
[7723] | 748 | self.flash(_('Student is in wrong state.')) |
---|
[7158] | 749 | self.redirect(self.url(self.context,'view_clearance')) |
---|
| 750 | return |
---|
| 751 | |
---|
| 752 | def render(self): |
---|
| 753 | return |
---|
| 754 | |
---|
[9484] | 755 | class StudentRejectClearancePage(KofaEditFormPage): |
---|
[7158] | 756 | """ Reject clearance by clearance officers |
---|
| 757 | """ |
---|
| 758 | grok.context(IStudent) |
---|
| 759 | grok.name('reject_clearance') |
---|
[9484] | 760 | label = _('Reject clearance') |
---|
[7158] | 761 | grok.require('waeup.clearStudent') |
---|
[9484] | 762 | form_fields = grok.AutoFields( |
---|
[9486] | 763 | IUGStudentClearance).select('officer_comment') |
---|
[7158] | 764 | |
---|
[9814] | 765 | def update(self): |
---|
| 766 | if clearance_disabled_message(self.context): |
---|
| 767 | self.flash(clearance_disabled_message(self.context)) |
---|
| 768 | self.redirect(self.url(self.context,'view_clearance')) |
---|
| 769 | return |
---|
| 770 | return super(StudentRejectClearancePage, self).update() |
---|
| 771 | |
---|
[9484] | 772 | @action(_('Save comment and reject clearance now'), style='primary') |
---|
| 773 | def reject(self, **data): |
---|
[7158] | 774 | if self.context.state == CLEARED: |
---|
| 775 | IWorkflowInfo(self.context).fireTransition('reset4') |
---|
[7723] | 776 | message = _('Clearance has been annulled.') |
---|
[7275] | 777 | self.flash(message) |
---|
[7158] | 778 | elif self.context.state == REQUESTED: |
---|
| 779 | IWorkflowInfo(self.context).fireTransition('reset3') |
---|
[7723] | 780 | message = _('Clearance request has been rejected.') |
---|
[7275] | 781 | self.flash(message) |
---|
[7158] | 782 | else: |
---|
[7723] | 783 | self.flash(_('Student is in wrong state.')) |
---|
[7334] | 784 | self.redirect(self.url(self.context,'view_clearance')) |
---|
[7275] | 785 | return |
---|
[9484] | 786 | self.applyData(self.context, **data) |
---|
[9486] | 787 | comment = data['officer_comment'] |
---|
[9556] | 788 | if comment: |
---|
| 789 | self.context.writeLogMessage( |
---|
| 790 | self, 'comment: %s' % comment.replace('\n', '<br>')) |
---|
| 791 | args = {'subject':message, 'body':comment} |
---|
| 792 | else: |
---|
| 793 | args = {'subject':message,} |
---|
[7275] | 794 | self.redirect(self.url(self.context) + |
---|
| 795 | '/contactstudent?%s' % urlencode(args)) |
---|
[7158] | 796 | return |
---|
| 797 | |
---|
| 798 | |
---|
[7819] | 799 | class StudentPersonalDisplayFormPage(KofaDisplayFormPage): |
---|
[6631] | 800 | """ Page to display student personal data |
---|
| 801 | """ |
---|
| 802 | grok.context(IStudent) |
---|
| 803 | grok.name('view_personal') |
---|
[6660] | 804 | grok.require('waeup.viewStudent') |
---|
[6631] | 805 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
[7386] | 806 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
[9543] | 807 | form_fields[ |
---|
| 808 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[6642] | 809 | pnav = 4 |
---|
[6631] | 810 | |
---|
| 811 | @property |
---|
| 812 | def label(self): |
---|
[7723] | 813 | return _('${a}: Personal Data', |
---|
| 814 | mapping = {'a':self.context.display_fullname}) |
---|
[6631] | 815 | |
---|
[8903] | 816 | class StudentPersonalManageFormPage(KofaEditFormPage): |
---|
| 817 | """ Page to manage personal data |
---|
[6631] | 818 | """ |
---|
| 819 | grok.context(IStudent) |
---|
[8903] | 820 | grok.name('manage_personal') |
---|
| 821 | grok.require('waeup.manageStudent') |
---|
[9553] | 822 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
| 823 | form_fields['personal_updated'].for_display = True |
---|
[9571] | 824 | form_fields[ |
---|
| 825 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[8903] | 826 | label = _('Manage personal data') |
---|
[6642] | 827 | pnav = 4 |
---|
[6631] | 828 | |
---|
[7723] | 829 | @action(_('Save'), style='primary') |
---|
[6762] | 830 | def save(self, **data): |
---|
| 831 | msave(self, **data) |
---|
| 832 | return |
---|
| 833 | |
---|
[9543] | 834 | class StudentPersonalEditFormPage(KofaEditFormPage): |
---|
[8903] | 835 | """ Page to edit personal data |
---|
| 836 | """ |
---|
[9543] | 837 | grok.context(IStudent) |
---|
[8903] | 838 | grok.name('edit_personal') |
---|
| 839 | grok.require('waeup.handleStudent') |
---|
[9563] | 840 | form_fields = grok.AutoFields(IStudentPersonalEdit).omit('personal_updated') |
---|
[8903] | 841 | label = _('Edit personal data') |
---|
| 842 | pnav = 4 |
---|
| 843 | |
---|
[9543] | 844 | @action(_('Save/Confirm'), style='primary') |
---|
| 845 | def save(self, **data): |
---|
| 846 | msave(self, **data) |
---|
[9569] | 847 | self.context.personal_updated = datetime.utcnow() |
---|
[9543] | 848 | return |
---|
| 849 | |
---|
[7819] | 850 | class StudyCourseDisplayFormPage(KofaDisplayFormPage): |
---|
[6635] | 851 | """ Page to display the student study course data |
---|
| 852 | """ |
---|
| 853 | grok.context(IStudentStudyCourse) |
---|
| 854 | grok.name('index') |
---|
[6660] | 855 | grok.require('waeup.viewStudent') |
---|
[6775] | 856 | grok.template('studycoursepage') |
---|
[6642] | 857 | pnav = 4 |
---|
[6635] | 858 | |
---|
| 859 | @property |
---|
[8972] | 860 | def form_fields(self): |
---|
| 861 | if self.context.is_postgrad: |
---|
| 862 | form_fields = grok.AutoFields(IStudentStudyCourse).omit( |
---|
[9723] | 863 | 'previous_verdict') |
---|
[8972] | 864 | else: |
---|
| 865 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 866 | return form_fields |
---|
| 867 | |
---|
| 868 | @property |
---|
[6635] | 869 | def label(self): |
---|
[9140] | 870 | if self.context.is_current: |
---|
| 871 | return _('${a}: Study Course', |
---|
| 872 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
| 873 | else: |
---|
| 874 | return _('${a}: Previous Study Course', |
---|
| 875 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
[6635] | 876 | |
---|
[6912] | 877 | @property |
---|
| 878 | def current_mode(self): |
---|
[7641] | 879 | if self.context.certificate is not None: |
---|
[7841] | 880 | studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
---|
[7681] | 881 | return studymodes_dict[self.context.certificate.study_mode] |
---|
[7171] | 882 | return |
---|
[7642] | 883 | |
---|
[7171] | 884 | @property |
---|
| 885 | def department(self): |
---|
[7205] | 886 | if self.context.certificate is not None: |
---|
[7171] | 887 | return self.context.certificate.__parent__.__parent__ |
---|
| 888 | return |
---|
[6912] | 889 | |
---|
[7171] | 890 | @property |
---|
| 891 | def faculty(self): |
---|
[7205] | 892 | if self.context.certificate is not None: |
---|
[7171] | 893 | return self.context.certificate.__parent__.__parent__.__parent__ |
---|
| 894 | return |
---|
| 895 | |
---|
[9140] | 896 | @property |
---|
| 897 | def prev_studycourses(self): |
---|
| 898 | if self.context.is_current: |
---|
| 899 | if self.context.__parent__.get('studycourse_2', None) is not None: |
---|
| 900 | return ( |
---|
| 901 | {'href':self.url(self.context.student) + '/studycourse_1', |
---|
| 902 | 'title':_('First Study Course, ')}, |
---|
| 903 | {'href':self.url(self.context.student) + '/studycourse_2', |
---|
| 904 | 'title':_('Second Study Course')} |
---|
| 905 | ) |
---|
| 906 | if self.context.__parent__.get('studycourse_1', None) is not None: |
---|
| 907 | return ( |
---|
| 908 | {'href':self.url(self.context.student) + '/studycourse_1', |
---|
| 909 | 'title':_('First Study Course')}, |
---|
| 910 | ) |
---|
| 911 | return |
---|
| 912 | |
---|
[7819] | 913 | class StudyCourseManageFormPage(KofaEditFormPage): |
---|
[6649] | 914 | """ Page to edit the student study course data |
---|
| 915 | """ |
---|
| 916 | grok.context(IStudentStudyCourse) |
---|
[6775] | 917 | grok.name('manage') |
---|
[7136] | 918 | grok.require('waeup.manageStudent') |
---|
[6775] | 919 | grok.template('studycoursemanagepage') |
---|
[7723] | 920 | label = _('Manage study course') |
---|
[6649] | 921 | pnav = 4 |
---|
[7723] | 922 | taboneactions = [_('Save'),_('Cancel')] |
---|
| 923 | tabtwoactions = [_('Remove selected levels'),_('Cancel')] |
---|
| 924 | tabthreeactions = [_('Add study level')] |
---|
[6649] | 925 | |
---|
[8972] | 926 | @property |
---|
| 927 | def form_fields(self): |
---|
| 928 | if self.context.is_postgrad: |
---|
| 929 | form_fields = grok.AutoFields(IStudentStudyCourse).omit( |
---|
[9723] | 930 | 'previous_verdict') |
---|
[8972] | 931 | else: |
---|
| 932 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 933 | return form_fields |
---|
| 934 | |
---|
[6775] | 935 | def update(self): |
---|
[9139] | 936 | if not self.context.is_current: |
---|
| 937 | emit_lock_message(self) |
---|
| 938 | return |
---|
[6775] | 939 | super(StudyCourseManageFormPage, self).update() |
---|
| 940 | tabs.need() |
---|
[7484] | 941 | self.tab1 = self.tab2 = '' |
---|
| 942 | qs = self.request.get('QUERY_STRING', '') |
---|
| 943 | if not qs: |
---|
| 944 | qs = 'tab1' |
---|
| 945 | setattr(self, qs, 'active') |
---|
[7490] | 946 | warning.need() |
---|
| 947 | datatable.need() |
---|
| 948 | return |
---|
[6775] | 949 | |
---|
[7723] | 950 | @action(_('Save'), style='primary') |
---|
[6761] | 951 | def save(self, **data): |
---|
[8099] | 952 | try: |
---|
| 953 | msave(self, **data) |
---|
| 954 | except ConstraintNotSatisfied: |
---|
| 955 | # The selected level might not exist in certificate |
---|
| 956 | self.flash(_('Current level not available for certificate.')) |
---|
| 957 | return |
---|
[8081] | 958 | notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
---|
[6761] | 959 | return |
---|
| 960 | |
---|
[6775] | 961 | @property |
---|
| 962 | def level_dict(self): |
---|
| 963 | studylevelsource = StudyLevelSource().factory |
---|
| 964 | for code in studylevelsource.getValues(self.context): |
---|
| 965 | title = studylevelsource.getTitle(self.context, code) |
---|
| 966 | yield(dict(code=code, title=title)) |
---|
| 967 | |
---|
[9437] | 968 | @property |
---|
| 969 | def session_dict(self): |
---|
| 970 | yield(dict(code='', title='--')) |
---|
| 971 | for item in academic_sessions(): |
---|
| 972 | code = item[1] |
---|
| 973 | title = item[0] |
---|
| 974 | yield(dict(code=code, title=title)) |
---|
| 975 | |
---|
[7723] | 976 | @action(_('Add study level')) |
---|
[6774] | 977 | def addStudyLevel(self, **data): |
---|
[6775] | 978 | level_code = self.request.form.get('addlevel', None) |
---|
[9437] | 979 | level_session = self.request.form.get('level_session', None) |
---|
| 980 | if not level_session: |
---|
| 981 | self.flash(_('You must select a session for the level.')) |
---|
| 982 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
| 983 | return |
---|
[8323] | 984 | studylevel = createObject(u'waeup.StudentStudyLevel') |
---|
[6775] | 985 | studylevel.level = int(level_code) |
---|
[9437] | 986 | studylevel.level_session = int(level_session) |
---|
[6775] | 987 | try: |
---|
[6782] | 988 | self.context.addStudentStudyLevel( |
---|
| 989 | self.context.certificate,studylevel) |
---|
[7723] | 990 | self.flash(_('Study level has been added.')) |
---|
[6775] | 991 | except KeyError: |
---|
[7723] | 992 | self.flash(_('This level exists.')) |
---|
[7484] | 993 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6774] | 994 | return |
---|
| 995 | |
---|
[7723] | 996 | @jsaction(_('Remove selected levels')) |
---|
[6775] | 997 | def delStudyLevels(self, **data): |
---|
| 998 | form = self.request.form |
---|
[9701] | 999 | if 'val_id' in form: |
---|
[6775] | 1000 | child_id = form['val_id'] |
---|
| 1001 | else: |
---|
[7723] | 1002 | self.flash(_('No study level selected.')) |
---|
[7484] | 1003 | self.redirect(self.url(self.context, '@@manage')+'?tab2') |
---|
[6775] | 1004 | return |
---|
| 1005 | if not isinstance(child_id, list): |
---|
| 1006 | child_id = [child_id] |
---|
| 1007 | deleted = [] |
---|
| 1008 | for id in child_id: |
---|
[7723] | 1009 | del self.context[id] |
---|
| 1010 | deleted.append(id) |
---|
[6775] | 1011 | if len(deleted): |
---|
[7723] | 1012 | self.flash(_('Successfully removed: ${a}', |
---|
| 1013 | mapping = {'a':', '.join(deleted)})) |
---|
[9332] | 1014 | self.context.writeLogMessage( |
---|
| 1015 | self,'removed: %s' % ', '.join(deleted)) |
---|
[7484] | 1016 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6775] | 1017 | return |
---|
[6774] | 1018 | |
---|
[9138] | 1019 | class StudentTransferFormPage(KofaAddFormPage): |
---|
| 1020 | """Page to transfer the student. |
---|
| 1021 | """ |
---|
| 1022 | grok.context(IStudent) |
---|
| 1023 | grok.name('transfer') |
---|
| 1024 | grok.require('waeup.manageStudent') |
---|
| 1025 | label = _('Transfer student') |
---|
| 1026 | form_fields = grok.AutoFields(IStudentStudyCourseTransfer).omit( |
---|
| 1027 | 'entry_mode', 'entry_session') |
---|
| 1028 | pnav = 4 |
---|
| 1029 | |
---|
| 1030 | def update(self): |
---|
| 1031 | super(StudentTransferFormPage, self).update() |
---|
| 1032 | warning.need() |
---|
| 1033 | return |
---|
| 1034 | |
---|
| 1035 | @jsaction(_('Transfer')) |
---|
| 1036 | def transferStudent(self, **data): |
---|
| 1037 | error = self.context.transfer(**data) |
---|
| 1038 | if error == -1: |
---|
| 1039 | self.flash(_('Current level does not match certificate levels.')) |
---|
| 1040 | elif error == -2: |
---|
| 1041 | self.flash(_('Former study course record incomplete.')) |
---|
| 1042 | elif error == -3: |
---|
| 1043 | self.flash(_('Maximum number of transfers exceeded.')) |
---|
| 1044 | else: |
---|
| 1045 | self.flash(_('Successfully transferred.')) |
---|
| 1046 | return |
---|
| 1047 | |
---|
[7819] | 1048 | class StudyLevelDisplayFormPage(KofaDisplayFormPage): |
---|
[6774] | 1049 | """ Page to display student study levels |
---|
| 1050 | """ |
---|
| 1051 | grok.context(IStudentStudyLevel) |
---|
| 1052 | grok.name('index') |
---|
| 1053 | grok.require('waeup.viewStudent') |
---|
[6775] | 1054 | form_fields = grok.AutoFields(IStudentStudyLevel) |
---|
[9161] | 1055 | form_fields[ |
---|
| 1056 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[6783] | 1057 | grok.template('studylevelpage') |
---|
[6774] | 1058 | pnav = 4 |
---|
| 1059 | |
---|
[7310] | 1060 | def update(self): |
---|
| 1061 | super(StudyLevelDisplayFormPage, self).update() |
---|
| 1062 | datatable.need() |
---|
| 1063 | return |
---|
| 1064 | |
---|
[6774] | 1065 | @property |
---|
[8141] | 1066 | def translated_values(self): |
---|
[8921] | 1067 | return translated_values(self) |
---|
[8141] | 1068 | |
---|
| 1069 | @property |
---|
[6774] | 1070 | def label(self): |
---|
[7833] | 1071 | # Here we know that the cookie has been set |
---|
| 1072 | lang = self.request.cookies.get('kofa.language') |
---|
[7811] | 1073 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 1074 | target_language=lang) |
---|
| 1075 | return _('${a}: Study Level ${b}', mapping = { |
---|
[8736] | 1076 | 'a':self.context.student.display_fullname, |
---|
[7723] | 1077 | 'b':level_title}) |
---|
[6774] | 1078 | |
---|
[7459] | 1079 | class ExportPDFCourseRegistrationSlipPage(UtilityView, grok.View): |
---|
[7028] | 1080 | """Deliver a PDF slip of the context. |
---|
| 1081 | """ |
---|
| 1082 | grok.context(IStudentStudyLevel) |
---|
[9452] | 1083 | grok.name('course_registration_slip.pdf') |
---|
[7028] | 1084 | grok.require('waeup.viewStudent') |
---|
| 1085 | form_fields = grok.AutoFields(IStudentStudyLevel) |
---|
[9683] | 1086 | form_fields[ |
---|
| 1087 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[7028] | 1088 | prefix = 'form' |
---|
[9702] | 1089 | omit_fields = ( |
---|
| 1090 | 'password', 'suspended', 'phone', |
---|
| 1091 | 'adm_code', 'sex', 'suspended_comment') |
---|
[7028] | 1092 | |
---|
| 1093 | @property |
---|
[7723] | 1094 | def title(self): |
---|
[7819] | 1095 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 1096 | return translate(_('Level Data'), 'waeup.kofa', |
---|
[7723] | 1097 | target_language=portal_language) |
---|
| 1098 | |
---|
| 1099 | @property |
---|
| 1100 | def content_title(self): |
---|
[7819] | 1101 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 1102 | return translate(_('Course List'), 'waeup.kofa', |
---|
[7723] | 1103 | target_language=portal_language) |
---|
| 1104 | |
---|
| 1105 | @property |
---|
[7028] | 1106 | def label(self): |
---|
[7819] | 1107 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 1108 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
| 1109 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 1110 | target_language=lang) |
---|
[8141] | 1111 | return translate(_('Course Registration Slip'), |
---|
[7811] | 1112 | 'waeup.kofa', target_language=portal_language) \ |
---|
[7723] | 1113 | + ' %s' % level_title |
---|
[7028] | 1114 | |
---|
| 1115 | def render(self): |
---|
[7819] | 1116 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 1117 | Sem = translate(_('Sem.'), 'waeup.kofa', target_language=portal_language) |
---|
| 1118 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
| 1119 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
| 1120 | Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language) |
---|
| 1121 | Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language) |
---|
| 1122 | Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language) |
---|
[9320] | 1123 | Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language) |
---|
[7811] | 1124 | Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
[9810] | 1125 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
---|
[9141] | 1126 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[9375] | 1127 | self.request, self.omit_fields) |
---|
[7150] | 1128 | students_utils = getUtility(IStudentsUtils) |
---|
[7318] | 1129 | tabledata = sorted(self.context.values(), |
---|
| 1130 | key=lambda value: str(value.semester) + value.code) |
---|
[7186] | 1131 | return students_utils.renderPDF( |
---|
[9452] | 1132 | self, 'course_registration_slip.pdf', |
---|
[8736] | 1133 | self.context.student, studentview, |
---|
[7723] | 1134 | tableheader=[(Sem,'semester', 1.5),(Code,'code', 2.5), |
---|
| 1135 | (Title,'title', 5), |
---|
| 1136 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
| 1137 | (Cred, 'credits', 1.5), |
---|
| 1138 | (Mand, 'mandatory', 1.5), |
---|
[8141] | 1139 | (Score, 'score', 1.5), |
---|
[9810] | 1140 | (Grade, 'grade', 1.5), |
---|
[8141] | 1141 | #('Auto', 'automatic', 1.5) |
---|
[7304] | 1142 | ], |
---|
[7318] | 1143 | tabledata=tabledata) |
---|
[7028] | 1144 | |
---|
[7819] | 1145 | class StudyLevelManageFormPage(KofaEditFormPage): |
---|
[6792] | 1146 | """ Page to edit the student study level data |
---|
| 1147 | """ |
---|
| 1148 | grok.context(IStudentStudyLevel) |
---|
| 1149 | grok.name('manage') |
---|
[7136] | 1150 | grok.require('waeup.manageStudent') |
---|
[6792] | 1151 | grok.template('studylevelmanagepage') |
---|
[9161] | 1152 | form_fields = grok.AutoFields(IStudentStudyLevel).omit( |
---|
[9690] | 1153 | 'validation_date', 'validated_by', 'total_credits', 'gpa') |
---|
[6792] | 1154 | pnav = 4 |
---|
[7723] | 1155 | taboneactions = [_('Save'),_('Cancel')] |
---|
| 1156 | tabtwoactions = [_('Add course ticket'), |
---|
| 1157 | _('Remove selected tickets'),_('Cancel')] |
---|
[6792] | 1158 | |
---|
| 1159 | def update(self): |
---|
[9139] | 1160 | if not self.context.__parent__.is_current: |
---|
| 1161 | emit_lock_message(self) |
---|
| 1162 | return |
---|
[6792] | 1163 | super(StudyLevelManageFormPage, self).update() |
---|
| 1164 | tabs.need() |
---|
[7484] | 1165 | self.tab1 = self.tab2 = '' |
---|
| 1166 | qs = self.request.get('QUERY_STRING', '') |
---|
| 1167 | if not qs: |
---|
| 1168 | qs = 'tab1' |
---|
| 1169 | setattr(self, qs, 'active') |
---|
[7490] | 1170 | warning.need() |
---|
| 1171 | datatable.need() |
---|
[6792] | 1172 | return |
---|
| 1173 | |
---|
| 1174 | @property |
---|
[8921] | 1175 | def translated_values(self): |
---|
| 1176 | return translated_values(self) |
---|
| 1177 | |
---|
| 1178 | @property |
---|
[6792] | 1179 | def label(self): |
---|
[7833] | 1180 | # Here we know that the cookie has been set |
---|
| 1181 | lang = self.request.cookies.get('kofa.language') |
---|
[7811] | 1182 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 1183 | target_language=lang) |
---|
| 1184 | return _('Manage study level ${a}', |
---|
| 1185 | mapping = {'a':level_title}) |
---|
[6792] | 1186 | |
---|
[7723] | 1187 | @action(_('Save'), style='primary') |
---|
[6792] | 1188 | def save(self, **data): |
---|
| 1189 | msave(self, **data) |
---|
| 1190 | return |
---|
| 1191 | |
---|
[7723] | 1192 | @action(_('Add course ticket')) |
---|
[6795] | 1193 | def addCourseTicket(self, **data): |
---|
| 1194 | self.redirect(self.url(self.context, '@@add')) |
---|
[6792] | 1195 | |
---|
[7723] | 1196 | @jsaction(_('Remove selected tickets')) |
---|
[6792] | 1197 | def delCourseTicket(self, **data): |
---|
| 1198 | form = self.request.form |
---|
[9701] | 1199 | if 'val_id' in form: |
---|
[6792] | 1200 | child_id = form['val_id'] |
---|
| 1201 | else: |
---|
[7723] | 1202 | self.flash(_('No ticket selected.')) |
---|
[7484] | 1203 | self.redirect(self.url(self.context, '@@manage')+'?tab2') |
---|
[6792] | 1204 | return |
---|
| 1205 | if not isinstance(child_id, list): |
---|
| 1206 | child_id = [child_id] |
---|
| 1207 | deleted = [] |
---|
| 1208 | for id in child_id: |
---|
[7723] | 1209 | del self.context[id] |
---|
| 1210 | deleted.append(id) |
---|
[6792] | 1211 | if len(deleted): |
---|
[7723] | 1212 | self.flash(_('Successfully removed: ${a}', |
---|
| 1213 | mapping = {'a':', '.join(deleted)})) |
---|
[9332] | 1214 | self.context.writeLogMessage( |
---|
| 1215 | self,'removed: %s' % ', '.join(deleted)) |
---|
[7484] | 1216 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6792] | 1217 | return |
---|
| 1218 | |
---|
[7459] | 1219 | class ValidateCoursesPage(UtilityView, grok.View): |
---|
[7334] | 1220 | """ Validate course list by course adviser |
---|
| 1221 | """ |
---|
| 1222 | grok.context(IStudentStudyLevel) |
---|
| 1223 | grok.name('validate_courses') |
---|
| 1224 | grok.require('waeup.validateStudent') |
---|
| 1225 | |
---|
| 1226 | def update(self): |
---|
[9139] | 1227 | if not self.context.__parent__.is_current: |
---|
| 1228 | emit_lock_message(self) |
---|
| 1229 | return |
---|
[7334] | 1230 | if str(self.context.__parent__.current_level) != self.context.__name__: |
---|
[7723] | 1231 | self.flash(_('This level does not correspond current level.')) |
---|
[8736] | 1232 | elif self.context.student.state == REGISTERED: |
---|
| 1233 | IWorkflowInfo(self.context.student).fireTransition( |
---|
[7642] | 1234 | 'validate_courses') |
---|
[7723] | 1235 | self.flash(_('Course list has been validated.')) |
---|
[7334] | 1236 | else: |
---|
[7723] | 1237 | self.flash(_('Student is in the wrong state.')) |
---|
[7334] | 1238 | self.redirect(self.url(self.context)) |
---|
| 1239 | return |
---|
| 1240 | |
---|
| 1241 | def render(self): |
---|
| 1242 | return |
---|
| 1243 | |
---|
[7459] | 1244 | class RejectCoursesPage(UtilityView, grok.View): |
---|
[7334] | 1245 | """ Reject course list by course adviser |
---|
| 1246 | """ |
---|
| 1247 | grok.context(IStudentStudyLevel) |
---|
| 1248 | grok.name('reject_courses') |
---|
| 1249 | grok.require('waeup.validateStudent') |
---|
| 1250 | |
---|
| 1251 | def update(self): |
---|
[9139] | 1252 | if not self.context.__parent__.is_current: |
---|
| 1253 | emit_lock_message(self) |
---|
| 1254 | return |
---|
[7334] | 1255 | if str(self.context.__parent__.current_level) != self.context.__name__: |
---|
[7723] | 1256 | self.flash(_('This level does not correspond current level.')) |
---|
[7334] | 1257 | self.redirect(self.url(self.context)) |
---|
| 1258 | return |
---|
[8736] | 1259 | elif self.context.student.state == VALIDATED: |
---|
| 1260 | IWorkflowInfo(self.context.student).fireTransition('reset8') |
---|
[7723] | 1261 | message = _('Course list request has been annulled.') |
---|
[7334] | 1262 | self.flash(message) |
---|
[8736] | 1263 | elif self.context.student.state == REGISTERED: |
---|
| 1264 | IWorkflowInfo(self.context.student).fireTransition('reset7') |
---|
[7723] | 1265 | message = _('Course list request has been rejected:') |
---|
[7334] | 1266 | self.flash(message) |
---|
| 1267 | else: |
---|
[7723] | 1268 | self.flash(_('Student is in the wrong state.')) |
---|
[7334] | 1269 | self.redirect(self.url(self.context)) |
---|
| 1270 | return |
---|
| 1271 | args = {'subject':message} |
---|
[8736] | 1272 | self.redirect(self.url(self.context.student) + |
---|
[7334] | 1273 | '/contactstudent?%s' % urlencode(args)) |
---|
| 1274 | return |
---|
| 1275 | |
---|
| 1276 | def render(self): |
---|
| 1277 | return |
---|
| 1278 | |
---|
[7819] | 1279 | class CourseTicketAddFormPage(KofaAddFormPage): |
---|
[6808] | 1280 | """Add a course ticket. |
---|
[6795] | 1281 | """ |
---|
| 1282 | grok.context(IStudentStudyLevel) |
---|
| 1283 | grok.name('add') |
---|
[7136] | 1284 | grok.require('waeup.manageStudent') |
---|
[7723] | 1285 | label = _('Add course ticket') |
---|
[9420] | 1286 | form_fields = grok.AutoFields(ICourseTicketAdd) |
---|
[6795] | 1287 | pnav = 4 |
---|
| 1288 | |
---|
[9139] | 1289 | def update(self): |
---|
| 1290 | if not self.context.__parent__.is_current: |
---|
| 1291 | emit_lock_message(self) |
---|
| 1292 | return |
---|
| 1293 | super(CourseTicketAddFormPage, self).update() |
---|
| 1294 | return |
---|
| 1295 | |
---|
[7723] | 1296 | @action(_('Add course ticket')) |
---|
[6795] | 1297 | def addCourseTicket(self, **data): |
---|
[9532] | 1298 | students_utils = getUtility(IStudentsUtils) |
---|
[8325] | 1299 | ticket = createObject(u'waeup.CourseTicket') |
---|
[6795] | 1300 | course = data['course'] |
---|
[6802] | 1301 | ticket.automatic = False |
---|
[8141] | 1302 | ticket.carry_over = False |
---|
[9532] | 1303 | max_credits = students_utils.maxCreditsExceeded(self.context, course) |
---|
| 1304 | if max_credits: |
---|
| 1305 | self.flash(_( |
---|
| 1306 | 'Total credits exceed ${a}.', |
---|
| 1307 | mapping = {'a': max_credits})) |
---|
| 1308 | return |
---|
[6795] | 1309 | try: |
---|
[8920] | 1310 | self.context.addCourseTicket(ticket, course) |
---|
[6795] | 1311 | except KeyError: |
---|
[7723] | 1312 | self.flash(_('The ticket exists.')) |
---|
[6795] | 1313 | return |
---|
[7723] | 1314 | self.flash(_('Successfully added ${a}.', |
---|
| 1315 | mapping = {'a':ticket.code})) |
---|
[7484] | 1316 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6795] | 1317 | return |
---|
| 1318 | |
---|
[7834] | 1319 | @action(_('Cancel'), validator=NullValidator) |
---|
[6795] | 1320 | def cancel(self, **data): |
---|
| 1321 | self.redirect(self.url(self.context)) |
---|
| 1322 | |
---|
[7819] | 1323 | class CourseTicketDisplayFormPage(KofaDisplayFormPage): |
---|
[6796] | 1324 | """ Page to display course tickets |
---|
| 1325 | """ |
---|
| 1326 | grok.context(ICourseTicket) |
---|
| 1327 | grok.name('index') |
---|
| 1328 | grok.require('waeup.viewStudent') |
---|
| 1329 | form_fields = grok.AutoFields(ICourseTicket) |
---|
[9684] | 1330 | grok.template('courseticketpage') |
---|
[6796] | 1331 | pnav = 4 |
---|
| 1332 | |
---|
| 1333 | @property |
---|
| 1334 | def label(self): |
---|
[7723] | 1335 | return _('${a}: Course Ticket ${b}', mapping = { |
---|
[8736] | 1336 | 'a':self.context.student.display_fullname, |
---|
[7723] | 1337 | 'b':self.context.code}) |
---|
[6796] | 1338 | |
---|
[7819] | 1339 | class CourseTicketManageFormPage(KofaEditFormPage): |
---|
[6796] | 1340 | """ Page to manage course tickets |
---|
| 1341 | """ |
---|
| 1342 | grok.context(ICourseTicket) |
---|
| 1343 | grok.name('manage') |
---|
[7136] | 1344 | grok.require('waeup.manageStudent') |
---|
[9420] | 1345 | form_fields = grok.AutoFields(ICourseTicket) |
---|
| 1346 | form_fields['title'].for_display = True |
---|
| 1347 | form_fields['fcode'].for_display = True |
---|
| 1348 | form_fields['dcode'].for_display = True |
---|
| 1349 | form_fields['semester'].for_display = True |
---|
| 1350 | form_fields['passmark'].for_display = True |
---|
| 1351 | form_fields['credits'].for_display = True |
---|
[9698] | 1352 | form_fields['mandatory'].for_display = False |
---|
[9420] | 1353 | form_fields['automatic'].for_display = True |
---|
[9422] | 1354 | form_fields['carry_over'].for_display = True |
---|
[6796] | 1355 | pnav = 4 |
---|
[9697] | 1356 | grok.template('courseticketmanagepage') |
---|
[6796] | 1357 | |
---|
| 1358 | @property |
---|
| 1359 | def label(self): |
---|
[7723] | 1360 | return _('Manage course ticket ${a}', mapping = {'a':self.context.code}) |
---|
[6796] | 1361 | |
---|
[7459] | 1362 | @action('Save', style='primary') |
---|
[6796] | 1363 | def save(self, **data): |
---|
| 1364 | msave(self, **data) |
---|
| 1365 | return |
---|
| 1366 | |
---|
[7819] | 1367 | class PaymentsManageFormPage(KofaEditFormPage): |
---|
[6869] | 1368 | """ Page to manage the student payments |
---|
[7642] | 1369 | |
---|
| 1370 | This manage form page is for both students and students officers. |
---|
[6869] | 1371 | """ |
---|
| 1372 | grok.context(IStudentPaymentsContainer) |
---|
[6940] | 1373 | grok.name('index') |
---|
[7181] | 1374 | grok.require('waeup.payStudent') |
---|
[6869] | 1375 | form_fields = grok.AutoFields(IStudentPaymentsContainer) |
---|
| 1376 | grok.template('paymentsmanagepage') |
---|
| 1377 | pnav = 4 |
---|
| 1378 | |
---|
[6940] | 1379 | def unremovable(self, ticket): |
---|
[7251] | 1380 | usertype = getattr(self.request.principal, 'user_type', None) |
---|
| 1381 | if not usertype: |
---|
| 1382 | return False |
---|
| 1383 | return (self.request.principal.user_type == 'student' and ticket.r_code) |
---|
[6940] | 1384 | |
---|
[6869] | 1385 | @property |
---|
| 1386 | def label(self): |
---|
[7723] | 1387 | return _('${a}: Payments', |
---|
| 1388 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
[6869] | 1389 | |
---|
| 1390 | def update(self): |
---|
| 1391 | super(PaymentsManageFormPage, self).update() |
---|
| 1392 | datatable.need() |
---|
[7329] | 1393 | warning.need() |
---|
[6869] | 1394 | return |
---|
| 1395 | |
---|
[7723] | 1396 | @jsaction(_('Remove selected tickets')) |
---|
[6869] | 1397 | def delPaymentTicket(self, **data): |
---|
| 1398 | form = self.request.form |
---|
[9701] | 1399 | if 'val_id' in form: |
---|
[6869] | 1400 | child_id = form['val_id'] |
---|
| 1401 | else: |
---|
[7723] | 1402 | self.flash(_('No payment selected.')) |
---|
[6940] | 1403 | self.redirect(self.url(self.context)) |
---|
[6869] | 1404 | return |
---|
| 1405 | if not isinstance(child_id, list): |
---|
| 1406 | child_id = [child_id] |
---|
| 1407 | deleted = [] |
---|
| 1408 | for id in child_id: |
---|
[6992] | 1409 | # Students are not allowed to remove used payment tickets |
---|
[6940] | 1410 | if not self.unremovable(self.context[id]): |
---|
[7723] | 1411 | del self.context[id] |
---|
| 1412 | deleted.append(id) |
---|
[6869] | 1413 | if len(deleted): |
---|
[7723] | 1414 | self.flash(_('Successfully removed: ${a}', |
---|
| 1415 | mapping = {'a': ', '.join(deleted)})) |
---|
[8735] | 1416 | self.context.writeLogMessage( |
---|
[8885] | 1417 | self,'removed: %s' % ', '.join(deleted)) |
---|
[6940] | 1418 | self.redirect(self.url(self.context)) |
---|
[6869] | 1419 | return |
---|
| 1420 | |
---|
[9517] | 1421 | #@action(_('Add online payment ticket')) |
---|
| 1422 | #def addPaymentTicket(self, **data): |
---|
| 1423 | # self.redirect(self.url(self.context, '@@addop')) |
---|
[6869] | 1424 | |
---|
[7819] | 1425 | class OnlinePaymentAddFormPage(KofaAddFormPage): |
---|
[6869] | 1426 | """ Page to add an online payment ticket |
---|
| 1427 | """ |
---|
| 1428 | grok.context(IStudentPaymentsContainer) |
---|
| 1429 | grok.name('addop') |
---|
[9729] | 1430 | grok.template('onlinepaymentaddform') |
---|
[7181] | 1431 | grok.require('waeup.payStudent') |
---|
[6877] | 1432 | form_fields = grok.AutoFields(IStudentOnlinePayment).select( |
---|
[6869] | 1433 | 'p_category') |
---|
[7723] | 1434 | label = _('Add online payment') |
---|
[6869] | 1435 | pnav = 4 |
---|
[7642] | 1436 | |
---|
[9729] | 1437 | @property |
---|
| 1438 | def selectable_categories(self): |
---|
| 1439 | categories = getUtility(IKofaUtils).SELECTABLE_PAYMENT_CATEGORIES |
---|
| 1440 | return sorted(categories.items()) |
---|
| 1441 | |
---|
[7723] | 1442 | @action(_('Create ticket'), style='primary') |
---|
[6869] | 1443 | def createTicket(self, **data): |
---|
[7024] | 1444 | p_category = data['p_category'] |
---|
[9148] | 1445 | previous_session = data.get('p_session', None) |
---|
| 1446 | previous_level = data.get('p_level', None) |
---|
[7024] | 1447 | student = self.context.__parent__ |
---|
| 1448 | if p_category == 'bed_allocation' and student[ |
---|
| 1449 | 'studycourse'].current_session != grok.getSite()[ |
---|
[8685] | 1450 | 'hostels'].accommodation_session: |
---|
[7024] | 1451 | self.flash( |
---|
[7723] | 1452 | _('Your current session does not match ' + \ |
---|
| 1453 | 'accommodation session.')) |
---|
[7024] | 1454 | return |
---|
[9423] | 1455 | if 'maintenance' in p_category: |
---|
| 1456 | current_session = str(student['studycourse'].current_session) |
---|
[9701] | 1457 | if not current_session in student['accommodation']: |
---|
[9424] | 1458 | self.flash(_('You have not yet booked accommodation.')) |
---|
[9423] | 1459 | return |
---|
[7150] | 1460 | students_utils = getUtility(IStudentsUtils) |
---|
[9148] | 1461 | error, payment = students_utils.setPaymentDetails( |
---|
| 1462 | p_category, student, previous_session, previous_level) |
---|
[8595] | 1463 | if error is not None: |
---|
| 1464 | self.flash(error) |
---|
[8081] | 1465 | return |
---|
[6869] | 1466 | self.context[payment.p_id] = payment |
---|
[7723] | 1467 | self.flash(_('Payment ticket created.')) |
---|
[6940] | 1468 | self.redirect(self.url(self.context)) |
---|
[6869] | 1469 | return |
---|
| 1470 | |
---|
[9383] | 1471 | @action(_('Cancel'), validator=NullValidator) |
---|
| 1472 | def cancel(self, **data): |
---|
| 1473 | self.redirect(self.url(self.context)) |
---|
| 1474 | |
---|
[9148] | 1475 | class PreviousPaymentAddFormPage(OnlinePaymentAddFormPage): |
---|
| 1476 | """ Page to add an online payment ticket for previous sessions |
---|
| 1477 | """ |
---|
| 1478 | grok.context(IStudentPaymentsContainer) |
---|
| 1479 | grok.name('addpp') |
---|
[9729] | 1480 | grok.template('previouspaymentaddform') |
---|
[9148] | 1481 | grok.require('waeup.payStudent') |
---|
| 1482 | form_fields = grok.AutoFields(IStudentPreviousPayment).select( |
---|
| 1483 | 'p_category', 'p_session', 'p_level') |
---|
| 1484 | label = _('Add previous session online payment') |
---|
| 1485 | pnav = 4 |
---|
| 1486 | |
---|
[9517] | 1487 | def update(self): |
---|
[9521] | 1488 | if self.context.student.before_payment: |
---|
| 1489 | self.flash(_("No previous payment to be made.")) |
---|
[9517] | 1490 | self.redirect(self.url(self.context)) |
---|
| 1491 | super(PreviousPaymentAddFormPage, self).update() |
---|
| 1492 | return |
---|
| 1493 | |
---|
[7819] | 1494 | class OnlinePaymentDisplayFormPage(KofaDisplayFormPage): |
---|
[6869] | 1495 | """ Page to view an online payment ticket |
---|
| 1496 | """ |
---|
[6877] | 1497 | grok.context(IStudentOnlinePayment) |
---|
[6869] | 1498 | grok.name('index') |
---|
| 1499 | grok.require('waeup.viewStudent') |
---|
[6877] | 1500 | form_fields = grok.AutoFields(IStudentOnlinePayment) |
---|
[8170] | 1501 | form_fields[ |
---|
| 1502 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 1503 | form_fields[ |
---|
| 1504 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[6869] | 1505 | pnav = 4 |
---|
| 1506 | |
---|
| 1507 | @property |
---|
| 1508 | def label(self): |
---|
[7723] | 1509 | return _('${a}: Online Payment Ticket ${b}', mapping = { |
---|
[8736] | 1510 | 'a':self.context.student.display_fullname, |
---|
[7723] | 1511 | 'b':self.context.p_id}) |
---|
[6869] | 1512 | |
---|
[8420] | 1513 | class OnlinePaymentApprovePage(UtilityView, grok.View): |
---|
[6930] | 1514 | """ Callback view |
---|
| 1515 | """ |
---|
| 1516 | grok.context(IStudentOnlinePayment) |
---|
[8420] | 1517 | grok.name('approve') |
---|
| 1518 | grok.require('waeup.managePortal') |
---|
[6930] | 1519 | |
---|
| 1520 | def update(self): |
---|
[8428] | 1521 | success, msg, log = self.context.approveStudentPayment() |
---|
| 1522 | if log is not None: |
---|
[9770] | 1523 | # Add log message to students.log |
---|
[8735] | 1524 | self.context.writeLogMessage(self,log) |
---|
[9770] | 1525 | # Add log message to payments.log |
---|
| 1526 | self.context.logger.info( |
---|
[9779] | 1527 | '%s,%s,%s,%s,%s,,,,,,' % ( |
---|
[9770] | 1528 | self.context.student.student_id, |
---|
| 1529 | self.context.p_id, self.context.p_category, |
---|
| 1530 | self.context.amount_auth, self.context.r_code)) |
---|
[8420] | 1531 | self.flash(msg) |
---|
[6940] | 1532 | return |
---|
[6930] | 1533 | |
---|
| 1534 | def render(self): |
---|
[6940] | 1535 | self.redirect(self.url(self.context, '@@index')) |
---|
[6930] | 1536 | return |
---|
| 1537 | |
---|
[8420] | 1538 | class OnlinePaymentFakeApprovePage(OnlinePaymentApprovePage): |
---|
| 1539 | """ Approval view for students. |
---|
| 1540 | |
---|
| 1541 | This view is used for browser tests only and |
---|
| 1542 | must be neutralized in custom pages! |
---|
| 1543 | """ |
---|
| 1544 | |
---|
| 1545 | grok.name('fake_approve') |
---|
| 1546 | grok.require('waeup.payStudent') |
---|
| 1547 | |
---|
[7459] | 1548 | class ExportPDFPaymentSlipPage(UtilityView, grok.View): |
---|
[7019] | 1549 | """Deliver a PDF slip of the context. |
---|
| 1550 | """ |
---|
| 1551 | grok.context(IStudentOnlinePayment) |
---|
[8262] | 1552 | grok.name('payment_slip.pdf') |
---|
[7019] | 1553 | grok.require('waeup.viewStudent') |
---|
| 1554 | form_fields = grok.AutoFields(IStudentOnlinePayment) |
---|
[8173] | 1555 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 1556 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[7019] | 1557 | prefix = 'form' |
---|
[8258] | 1558 | note = None |
---|
[9702] | 1559 | omit_fields = ( |
---|
| 1560 | 'password', 'suspended', 'phone', |
---|
| 1561 | 'adm_code', 'sex', 'suspended_comment') |
---|
[7019] | 1562 | |
---|
| 1563 | @property |
---|
[8262] | 1564 | def title(self): |
---|
| 1565 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 1566 | return translate(_('Payment Data'), 'waeup.kofa', |
---|
| 1567 | target_language=portal_language) |
---|
| 1568 | |
---|
| 1569 | @property |
---|
[7019] | 1570 | def label(self): |
---|
[8262] | 1571 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 1572 | return translate(_('Online Payment Slip'), |
---|
| 1573 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 1574 | + ' %s' % self.context.p_id |
---|
[7019] | 1575 | |
---|
| 1576 | def render(self): |
---|
[8262] | 1577 | #if self.context.p_state != 'paid': |
---|
| 1578 | # self.flash('Ticket not yet paid.') |
---|
| 1579 | # self.redirect(self.url(self.context)) |
---|
| 1580 | # return |
---|
[9141] | 1581 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[9375] | 1582 | self.request, self.omit_fields) |
---|
[7150] | 1583 | students_utils = getUtility(IStudentsUtils) |
---|
[8262] | 1584 | return students_utils.renderPDF(self, 'payment_slip.pdf', |
---|
[8736] | 1585 | self.context.student, studentview, note=self.note) |
---|
[7019] | 1586 | |
---|
[6992] | 1587 | |
---|
[7819] | 1588 | class AccommodationManageFormPage(KofaEditFormPage): |
---|
[7009] | 1589 | """ Page to manage bed tickets. |
---|
[7642] | 1590 | |
---|
| 1591 | This manage form page is for both students and students officers. |
---|
[6635] | 1592 | """ |
---|
| 1593 | grok.context(IStudentAccommodation) |
---|
| 1594 | grok.name('index') |
---|
[7181] | 1595 | grok.require('waeup.handleAccommodation') |
---|
[6635] | 1596 | form_fields = grok.AutoFields(IStudentAccommodation) |
---|
[6992] | 1597 | grok.template('accommodationmanagepage') |
---|
[6642] | 1598 | pnav = 4 |
---|
[7723] | 1599 | officers_only_actions = [_('Remove selected')] |
---|
[6635] | 1600 | |
---|
| 1601 | @property |
---|
| 1602 | def label(self): |
---|
[7723] | 1603 | return _('${a}: Accommodation', |
---|
| 1604 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
[6637] | 1605 | |
---|
[6992] | 1606 | def update(self): |
---|
| 1607 | super(AccommodationManageFormPage, self).update() |
---|
| 1608 | datatable.need() |
---|
[7329] | 1609 | warning.need() |
---|
[6992] | 1610 | return |
---|
| 1611 | |
---|
[7723] | 1612 | @jsaction(_('Remove selected')) |
---|
[7009] | 1613 | def delBedTickets(self, **data): |
---|
[7240] | 1614 | if getattr(self.request.principal, 'user_type', None) == 'student': |
---|
[7723] | 1615 | self.flash(_('You are not allowed to remove bed tickets.')) |
---|
[7017] | 1616 | self.redirect(self.url(self.context)) |
---|
| 1617 | return |
---|
[6992] | 1618 | form = self.request.form |
---|
[9701] | 1619 | if 'val_id' in form: |
---|
[6992] | 1620 | child_id = form['val_id'] |
---|
| 1621 | else: |
---|
[7723] | 1622 | self.flash(_('No bed ticket selected.')) |
---|
[6992] | 1623 | self.redirect(self.url(self.context)) |
---|
| 1624 | return |
---|
| 1625 | if not isinstance(child_id, list): |
---|
| 1626 | child_id = [child_id] |
---|
| 1627 | deleted = [] |
---|
| 1628 | for id in child_id: |
---|
[7068] | 1629 | del self.context[id] |
---|
| 1630 | deleted.append(id) |
---|
[6992] | 1631 | if len(deleted): |
---|
[7723] | 1632 | self.flash(_('Successfully removed: ${a}', |
---|
| 1633 | mapping = {'a':', '.join(deleted)})) |
---|
[8735] | 1634 | self.context.writeLogMessage( |
---|
| 1635 | self,'removed: % s' % ', '.join(deleted)) |
---|
[6992] | 1636 | self.redirect(self.url(self.context)) |
---|
| 1637 | return |
---|
| 1638 | |
---|
[7009] | 1639 | @property |
---|
| 1640 | def selected_actions(self): |
---|
[7240] | 1641 | if getattr(self.request.principal, 'user_type', None) == 'student': |
---|
[7642] | 1642 | return [action for action in self.actions |
---|
| 1643 | if not action.label in self.officers_only_actions] |
---|
| 1644 | return self.actions |
---|
[7009] | 1645 | |
---|
[7819] | 1646 | class BedTicketAddPage(KofaPage): |
---|
[6992] | 1647 | """ Page to add an online payment ticket |
---|
| 1648 | """ |
---|
| 1649 | grok.context(IStudentAccommodation) |
---|
| 1650 | grok.name('add') |
---|
[7181] | 1651 | grok.require('waeup.handleAccommodation') |
---|
[6992] | 1652 | grok.template('enterpin') |
---|
[6993] | 1653 | ac_prefix = 'HOS' |
---|
[7723] | 1654 | label = _('Add bed ticket') |
---|
[6992] | 1655 | pnav = 4 |
---|
[7723] | 1656 | buttonname = _('Create bed ticket') |
---|
[6993] | 1657 | notice = '' |
---|
[9188] | 1658 | with_ac = True |
---|
[6992] | 1659 | |
---|
| 1660 | def update(self, SUBMIT=None): |
---|
[8736] | 1661 | student = self.context.student |
---|
[7150] | 1662 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1663 | acc_details = students_utils.getAccommodationDetails(student) |
---|
[8688] | 1664 | if acc_details.get('expired', False): |
---|
| 1665 | startdate = acc_details.get('startdate') |
---|
| 1666 | enddate = acc_details.get('enddate') |
---|
| 1667 | if startdate and enddate: |
---|
| 1668 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 1669 | startdate = to_timezone( |
---|
| 1670 | startdate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 1671 | enddate = to_timezone( |
---|
| 1672 | enddate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 1673 | self.flash(_("Outside booking period: ${a} - ${b}", |
---|
| 1674 | mapping = {'a': startdate, 'b': enddate})) |
---|
| 1675 | else: |
---|
| 1676 | self.flash(_("Outside booking period.")) |
---|
| 1677 | self.redirect(self.url(self.context)) |
---|
| 1678 | return |
---|
[7369] | 1679 | if not acc_details: |
---|
[7723] | 1680 | self.flash(_("Your data are incomplete.")) |
---|
[7369] | 1681 | self.redirect(self.url(self.context)) |
---|
| 1682 | return |
---|
[6996] | 1683 | if not student.state in acc_details['allowed_states']: |
---|
[7723] | 1684 | self.flash(_("You are in the wrong registration state.")) |
---|
[6992] | 1685 | self.redirect(self.url(self.context)) |
---|
| 1686 | return |
---|
[7642] | 1687 | if student['studycourse'].current_session != acc_details[ |
---|
| 1688 | 'booking_session']: |
---|
[7061] | 1689 | self.flash( |
---|
[7723] | 1690 | _('Your current session does not match accommodation session.')) |
---|
[7061] | 1691 | self.redirect(self.url(self.context)) |
---|
| 1692 | return |
---|
| 1693 | if str(acc_details['booking_session']) in self.context.keys(): |
---|
[7642] | 1694 | self.flash( |
---|
[7723] | 1695 | _('You already booked a bed space in current ' \ |
---|
| 1696 | + 'accommodation session.')) |
---|
[7004] | 1697 | self.redirect(self.url(self.context)) |
---|
| 1698 | return |
---|
[9188] | 1699 | if self.with_ac: |
---|
| 1700 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 1701 | self.ac_number = self.request.form.get('ac_number', None) |
---|
[6992] | 1702 | if SUBMIT is None: |
---|
| 1703 | return |
---|
[9188] | 1704 | if self.with_ac: |
---|
| 1705 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 1706 | code = get_access_code(pin) |
---|
| 1707 | if not code: |
---|
| 1708 | self.flash(_('Activation code is invalid.')) |
---|
| 1709 | return |
---|
[7060] | 1710 | # Search and book bed |
---|
[6997] | 1711 | cat = queryUtility(ICatalog, name='beds_catalog', default=None) |
---|
| 1712 | entries = cat.searchResults( |
---|
[7003] | 1713 | owner=(student.student_id,student.student_id)) |
---|
| 1714 | if len(entries): |
---|
[9188] | 1715 | # If bed space has been manually allocated use this bed |
---|
[7003] | 1716 | bed = [entry for entry in entries][0] |
---|
[9424] | 1717 | # Safety belt for paranoids: Does this bed really exist on portal? |
---|
| 1718 | # XXX: Can be remove if nobody complains. |
---|
| 1719 | if bed.__parent__.__parent__ is None: |
---|
| 1720 | self.flash(_('System error: Please contact the adminsitrator.')) |
---|
[9428] | 1721 | self.context.writeLogMessage(self, 'fatal error: %s' % bed.bed_id) |
---|
[9424] | 1722 | return |
---|
[7060] | 1723 | else: |
---|
| 1724 | # else search for other available beds |
---|
| 1725 | entries = cat.searchResults( |
---|
| 1726 | bed_type=(acc_details['bt'],acc_details['bt'])) |
---|
| 1727 | available_beds = [ |
---|
| 1728 | entry for entry in entries if entry.owner == NOT_OCCUPIED] |
---|
| 1729 | if available_beds: |
---|
[7150] | 1730 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1731 | bed = students_utils.selectBed(available_beds) |
---|
[9424] | 1732 | # Safety belt for paranoids: Does this bed really exist in portal? |
---|
| 1733 | # XXX: Can be remove if nobody complains. |
---|
| 1734 | if bed.__parent__.__parent__ is None: |
---|
| 1735 | self.flash(_('System error: Please contact the adminsitrator.')) |
---|
[9428] | 1736 | self.context.writeLogMessage(self, 'fatal error: %s' % bed.bed_id) |
---|
[9424] | 1737 | return |
---|
[7060] | 1738 | bed.bookBed(student.student_id) |
---|
| 1739 | else: |
---|
[7723] | 1740 | self.flash(_('There is no free bed in your category ${a}.', |
---|
| 1741 | mapping = {'a':acc_details['bt']})) |
---|
[7060] | 1742 | return |
---|
[9188] | 1743 | if self.with_ac: |
---|
| 1744 | # Mark pin as used (this also fires a pin related transition) |
---|
| 1745 | if code.state == USED: |
---|
| 1746 | self.flash(_('Activation code has already been used.')) |
---|
[6992] | 1747 | return |
---|
[9188] | 1748 | else: |
---|
| 1749 | comment = _(u'invalidated') |
---|
| 1750 | # Here we know that the ac is in state initialized so we do not |
---|
| 1751 | # expect an exception, but the owner might be different |
---|
| 1752 | if not invalidate_accesscode( |
---|
| 1753 | pin,comment,self.context.student.student_id): |
---|
| 1754 | self.flash(_('You are not the owner of this access code.')) |
---|
| 1755 | return |
---|
[7060] | 1756 | # Create bed ticket |
---|
[6992] | 1757 | bedticket = createObject(u'waeup.BedTicket') |
---|
[9189] | 1758 | if self.with_ac: |
---|
| 1759 | bedticket.booking_code = pin |
---|
[6994] | 1760 | bedticket.booking_session = acc_details['booking_session'] |
---|
[6996] | 1761 | bedticket.bed_type = acc_details['bt'] |
---|
[7006] | 1762 | bedticket.bed = bed |
---|
[6996] | 1763 | hall_title = bed.__parent__.hostel_name |
---|
[9199] | 1764 | coordinates = bed.coordinates[1:] |
---|
[6996] | 1765 | block, room_nr, bed_nr = coordinates |
---|
[7723] | 1766 | bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = { |
---|
| 1767 | 'a':hall_title, 'b':block, |
---|
| 1768 | 'c':room_nr, 'd':bed_nr, |
---|
| 1769 | 'e':bed.bed_type}) |
---|
[7819] | 1770 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7723] | 1771 | bedticket.bed_coordinates = translate( |
---|
[7811] | 1772 | bc, 'waeup.kofa',target_language=portal_language) |
---|
[9423] | 1773 | self.context.addBedTicket(bedticket) |
---|
[9411] | 1774 | self.context.writeLogMessage(self, 'booked: %s' % bed.bed_id) |
---|
[7723] | 1775 | self.flash(_('Bed ticket created and bed booked: ${a}', |
---|
| 1776 | mapping = {'a':bedticket.bed_coordinates})) |
---|
[6992] | 1777 | self.redirect(self.url(self.context)) |
---|
| 1778 | return |
---|
| 1779 | |
---|
[7819] | 1780 | class BedTicketDisplayFormPage(KofaDisplayFormPage): |
---|
[6994] | 1781 | """ Page to display bed tickets |
---|
| 1782 | """ |
---|
| 1783 | grok.context(IBedTicket) |
---|
| 1784 | grok.name('index') |
---|
[7181] | 1785 | grok.require('waeup.handleAccommodation') |
---|
[6994] | 1786 | form_fields = grok.AutoFields(IBedTicket) |
---|
[9201] | 1787 | form_fields['booking_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[6994] | 1788 | pnav = 4 |
---|
| 1789 | |
---|
| 1790 | @property |
---|
| 1791 | def label(self): |
---|
[7723] | 1792 | return _('Bed Ticket for Session ${a}', |
---|
| 1793 | mapping = {'a':self.context.getSessionString()}) |
---|
[6994] | 1794 | |
---|
[7459] | 1795 | class ExportPDFBedTicketSlipPage(UtilityView, grok.View): |
---|
[7027] | 1796 | """Deliver a PDF slip of the context. |
---|
| 1797 | """ |
---|
| 1798 | grok.context(IBedTicket) |
---|
[9452] | 1799 | grok.name('bed_allocation_slip.pdf') |
---|
[7181] | 1800 | grok.require('waeup.handleAccommodation') |
---|
[7027] | 1801 | form_fields = grok.AutoFields(IBedTicket) |
---|
[8173] | 1802 | form_fields['booking_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[7027] | 1803 | prefix = 'form' |
---|
[9702] | 1804 | omit_fields = ( |
---|
| 1805 | 'password', 'suspended', 'phone', 'adm_code', 'suspended_comment') |
---|
[7027] | 1806 | |
---|
| 1807 | @property |
---|
[7723] | 1808 | def title(self): |
---|
[7819] | 1809 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 1810 | return translate(_('Bed Allocation Data'), 'waeup.kofa', |
---|
[7723] | 1811 | target_language=portal_language) |
---|
| 1812 | |
---|
| 1813 | @property |
---|
[7027] | 1814 | def label(self): |
---|
[7819] | 1815 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9201] | 1816 | #return translate(_('Bed Allocation: '), |
---|
| 1817 | # 'waeup.kofa', target_language=portal_language) \ |
---|
| 1818 | # + ' %s' % self.context.bed_coordinates |
---|
| 1819 | return translate(_('Bed Allocation Slip'), |
---|
[7811] | 1820 | 'waeup.kofa', target_language=portal_language) \ |
---|
[9201] | 1821 | + ' %s' % self.context.getSessionString() |
---|
[7027] | 1822 | |
---|
| 1823 | def render(self): |
---|
[9141] | 1824 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[9375] | 1825 | self.request, self.omit_fields) |
---|
[7150] | 1826 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1827 | return students_utils.renderPDF( |
---|
[9452] | 1828 | self, 'bed_allocation_slip.pdf', |
---|
[8736] | 1829 | self.context.student, studentview) |
---|
[7027] | 1830 | |
---|
[7459] | 1831 | class BedTicketRelocationPage(UtilityView, grok.View): |
---|
[7015] | 1832 | """ Callback view |
---|
| 1833 | """ |
---|
| 1834 | grok.context(IBedTicket) |
---|
| 1835 | grok.name('relocate') |
---|
| 1836 | grok.require('waeup.manageHostels') |
---|
| 1837 | |
---|
[7059] | 1838 | # Relocate student if student parameters have changed or the bed_type |
---|
| 1839 | # of the bed has changed |
---|
[7015] | 1840 | def update(self): |
---|
[8736] | 1841 | student = self.context.student |
---|
[7150] | 1842 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1843 | acc_details = students_utils.getAccommodationDetails(student) |
---|
[7068] | 1844 | if self.context.bed != None and \ |
---|
| 1845 | 'reserved' in self.context.bed.bed_type: |
---|
[7723] | 1846 | self.flash(_("Students in reserved beds can't be relocated.")) |
---|
[7068] | 1847 | self.redirect(self.url(self.context)) |
---|
| 1848 | return |
---|
[7059] | 1849 | if acc_details['bt'] == self.context.bed_type and \ |
---|
[7068] | 1850 | self.context.bed != None and \ |
---|
[7059] | 1851 | self.context.bed.bed_type == self.context.bed_type: |
---|
[7723] | 1852 | self.flash(_("Student can't be relocated.")) |
---|
[7068] | 1853 | self.redirect(self.url(self.context)) |
---|
[7015] | 1854 | return |
---|
[7068] | 1855 | # Search a bed |
---|
[7015] | 1856 | cat = queryUtility(ICatalog, name='beds_catalog', default=None) |
---|
| 1857 | entries = cat.searchResults( |
---|
[7068] | 1858 | owner=(student.student_id,student.student_id)) |
---|
| 1859 | if len(entries) and self.context.bed == None: |
---|
| 1860 | # If booking has been cancelled but other bed space has been |
---|
| 1861 | # manually allocated after cancellation use this bed |
---|
| 1862 | new_bed = [entry for entry in entries][0] |
---|
| 1863 | else: |
---|
| 1864 | # Search for other available beds |
---|
| 1865 | entries = cat.searchResults( |
---|
| 1866 | bed_type=(acc_details['bt'],acc_details['bt'])) |
---|
| 1867 | available_beds = [ |
---|
| 1868 | entry for entry in entries if entry.owner == NOT_OCCUPIED] |
---|
| 1869 | if available_beds: |
---|
[7150] | 1870 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1871 | new_bed = students_utils.selectBed(available_beds) |
---|
[7068] | 1872 | new_bed.bookBed(student.student_id) |
---|
| 1873 | else: |
---|
[7723] | 1874 | self.flash(_('There is no free bed in your category ${a}.', |
---|
| 1875 | mapping = {'a':acc_details['bt']})) |
---|
[7068] | 1876 | self.redirect(self.url(self.context)) |
---|
| 1877 | return |
---|
[7642] | 1878 | # Release old bed if exists |
---|
[7068] | 1879 | if self.context.bed != None: |
---|
| 1880 | self.context.bed.owner = NOT_OCCUPIED |
---|
| 1881 | notify(grok.ObjectModifiedEvent(self.context.bed)) |
---|
[7015] | 1882 | # Alocate new bed |
---|
| 1883 | self.context.bed_type = acc_details['bt'] |
---|
[7068] | 1884 | self.context.bed = new_bed |
---|
| 1885 | hall_title = new_bed.__parent__.hostel_name |
---|
[9199] | 1886 | coordinates = new_bed.coordinates[1:] |
---|
[7015] | 1887 | block, room_nr, bed_nr = coordinates |
---|
[7723] | 1888 | bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = { |
---|
| 1889 | 'a':hall_title, 'b':block, |
---|
| 1890 | 'c':room_nr, 'd':bed_nr, |
---|
| 1891 | 'e':new_bed.bed_type}) |
---|
[7819] | 1892 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7723] | 1893 | self.context.bed_coordinates = translate( |
---|
[7811] | 1894 | bc, 'waeup.kofa',target_language=portal_language) |
---|
[9411] | 1895 | self.context.writeLogMessage(self, 'relocated: %s' % new_bed.bed_id) |
---|
[7723] | 1896 | self.flash(_('Student relocated: ${a}', |
---|
| 1897 | mapping = {'a':self.context.bed_coordinates})) |
---|
[7015] | 1898 | self.redirect(self.url(self.context)) |
---|
| 1899 | return |
---|
| 1900 | |
---|
| 1901 | def render(self): |
---|
| 1902 | return |
---|
| 1903 | |
---|
[7819] | 1904 | class StudentHistoryPage(KofaPage): |
---|
[6637] | 1905 | """ Page to display student clearance data |
---|
| 1906 | """ |
---|
| 1907 | grok.context(IStudent) |
---|
| 1908 | grok.name('history') |
---|
[6660] | 1909 | grok.require('waeup.viewStudent') |
---|
[6637] | 1910 | grok.template('studenthistory') |
---|
[6642] | 1911 | pnav = 4 |
---|
[6637] | 1912 | |
---|
| 1913 | @property |
---|
| 1914 | def label(self): |
---|
[7723] | 1915 | return _('${a}: History', mapping = {'a':self.context.display_fullname}) |
---|
[6694] | 1916 | |
---|
| 1917 | # Pages for students only |
---|
| 1918 | |
---|
[7819] | 1919 | class StudentBaseEditFormPage(KofaEditFormPage): |
---|
[7133] | 1920 | """ View to edit student base data |
---|
| 1921 | """ |
---|
| 1922 | grok.context(IStudent) |
---|
| 1923 | grok.name('edit_base') |
---|
| 1924 | grok.require('waeup.handleStudent') |
---|
| 1925 | form_fields = grok.AutoFields(IStudentBase).select( |
---|
| 1926 | 'email', 'phone') |
---|
[7723] | 1927 | label = _('Edit base data') |
---|
[7133] | 1928 | pnav = 4 |
---|
| 1929 | |
---|
[7723] | 1930 | @action(_('Save'), style='primary') |
---|
[7133] | 1931 | def save(self, **data): |
---|
| 1932 | msave(self, **data) |
---|
| 1933 | return |
---|
| 1934 | |
---|
[7819] | 1935 | class StudentChangePasswordPage(KofaEditFormPage): |
---|
[7144] | 1936 | """ View to manage student base data |
---|
[6756] | 1937 | """ |
---|
| 1938 | grok.context(IStudent) |
---|
[7114] | 1939 | grok.name('change_password') |
---|
[6694] | 1940 | grok.require('waeup.handleStudent') |
---|
[7144] | 1941 | grok.template('change_password') |
---|
[7723] | 1942 | label = _('Change password') |
---|
[6694] | 1943 | pnav = 4 |
---|
| 1944 | |
---|
[7723] | 1945 | @action(_('Save'), style='primary') |
---|
[7144] | 1946 | def save(self, **data): |
---|
| 1947 | form = self.request.form |
---|
| 1948 | password = form.get('change_password', None) |
---|
| 1949 | password_ctl = form.get('change_password_repeat', None) |
---|
| 1950 | if password: |
---|
[7147] | 1951 | validator = getUtility(IPasswordValidator) |
---|
| 1952 | errors = validator.validate_password(password, password_ctl) |
---|
| 1953 | if not errors: |
---|
| 1954 | IUserAccount(self.context).setPassword(password) |
---|
[8735] | 1955 | self.context.writeLogMessage(self, 'saved: password') |
---|
[7723] | 1956 | self.flash(_('Password changed.')) |
---|
[6756] | 1957 | else: |
---|
[7147] | 1958 | self.flash( ' '.join(errors)) |
---|
[6756] | 1959 | return |
---|
| 1960 | |
---|
[7819] | 1961 | class StudentFilesUploadPage(KofaPage): |
---|
[7114] | 1962 | """ View to upload files by student |
---|
| 1963 | """ |
---|
| 1964 | grok.context(IStudent) |
---|
| 1965 | grok.name('change_portrait') |
---|
[7127] | 1966 | grok.require('waeup.uploadStudentFile') |
---|
[7114] | 1967 | grok.template('filesuploadpage') |
---|
[7723] | 1968 | label = _('Upload portrait') |
---|
[7114] | 1969 | pnav = 4 |
---|
| 1970 | |
---|
[7133] | 1971 | def update(self): |
---|
[8736] | 1972 | if self.context.student.state != ADMITTED: |
---|
[7145] | 1973 | emit_lock_message(self) |
---|
[7133] | 1974 | return |
---|
| 1975 | super(StudentFilesUploadPage, self).update() |
---|
| 1976 | return |
---|
| 1977 | |
---|
[7819] | 1978 | class StartClearancePage(KofaPage): |
---|
[6770] | 1979 | grok.context(IStudent) |
---|
| 1980 | grok.name('start_clearance') |
---|
| 1981 | grok.require('waeup.handleStudent') |
---|
| 1982 | grok.template('enterpin') |
---|
[7723] | 1983 | label = _('Start clearance') |
---|
[6770] | 1984 | ac_prefix = 'CLR' |
---|
| 1985 | notice = '' |
---|
| 1986 | pnav = 4 |
---|
[7723] | 1987 | buttonname = _('Start clearance now') |
---|
[6770] | 1988 | |
---|
[7133] | 1989 | @property |
---|
| 1990 | def all_required_fields_filled(self): |
---|
| 1991 | if self.context.email and self.context.phone: |
---|
| 1992 | return True |
---|
| 1993 | return False |
---|
| 1994 | |
---|
| 1995 | @property |
---|
| 1996 | def portrait_uploaded(self): |
---|
| 1997 | store = getUtility(IExtFileStore) |
---|
| 1998 | if store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
| 1999 | return True |
---|
| 2000 | return False |
---|
| 2001 | |
---|
[6770] | 2002 | def update(self, SUBMIT=None): |
---|
[7671] | 2003 | if not self.context.state == ADMITTED: |
---|
[7745] | 2004 | self.flash(_("Wrong state")) |
---|
[6936] | 2005 | self.redirect(self.url(self.context)) |
---|
| 2006 | return |
---|
[7133] | 2007 | if not self.portrait_uploaded: |
---|
[7723] | 2008 | self.flash(_("No portrait uploaded.")) |
---|
[7133] | 2009 | self.redirect(self.url(self.context, 'change_portrait')) |
---|
| 2010 | return |
---|
| 2011 | if not self.all_required_fields_filled: |
---|
[7723] | 2012 | self.flash(_("Not all required fields filled.")) |
---|
[7133] | 2013 | self.redirect(self.url(self.context, 'edit_base')) |
---|
| 2014 | return |
---|
[6770] | 2015 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 2016 | self.ac_number = self.request.form.get('ac_number', None) |
---|
| 2017 | |
---|
| 2018 | if SUBMIT is None: |
---|
| 2019 | return |
---|
| 2020 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 2021 | code = get_access_code(pin) |
---|
| 2022 | if not code: |
---|
[7723] | 2023 | self.flash(_('Activation code is invalid.')) |
---|
[6770] | 2024 | return |
---|
| 2025 | if code.state == USED: |
---|
[7723] | 2026 | self.flash(_('Activation code has already been used.')) |
---|
[6770] | 2027 | return |
---|
[8974] | 2028 | # Mark pin as used (this also fires a pin related transition) |
---|
| 2029 | # and fire transition start_clearance |
---|
| 2030 | comment = _(u"invalidated") |
---|
| 2031 | # Here we know that the ac is in state initialized so we do not |
---|
| 2032 | # expect an exception, but the owner might be different |
---|
| 2033 | if not invalidate_accesscode(pin, comment, self.context.student_id): |
---|
| 2034 | self.flash(_('You are not the owner of this access code.')) |
---|
| 2035 | return |
---|
| 2036 | self.context.clr_code = pin |
---|
[6770] | 2037 | IWorkflowInfo(self.context).fireTransition('start_clearance') |
---|
[7723] | 2038 | self.flash(_('Clearance process has been started.')) |
---|
[6770] | 2039 | self.redirect(self.url(self.context,'cedit')) |
---|
| 2040 | return |
---|
| 2041 | |
---|
[6695] | 2042 | class StudentClearanceEditFormPage(StudentClearanceManageFormPage): |
---|
| 2043 | """ View to edit student clearance data by student |
---|
| 2044 | """ |
---|
| 2045 | grok.context(IStudent) |
---|
| 2046 | grok.name('cedit') |
---|
| 2047 | grok.require('waeup.handleStudent') |
---|
[7723] | 2048 | label = _('Edit clearance data') |
---|
[6718] | 2049 | |
---|
[7993] | 2050 | @property |
---|
| 2051 | def form_fields(self): |
---|
[8472] | 2052 | if self.context.is_postgrad: |
---|
[8974] | 2053 | form_fields = grok.AutoFields(IPGStudentClearance).omit( |
---|
[9486] | 2054 | 'clearance_locked', 'clr_code', 'officer_comment') |
---|
[7993] | 2055 | else: |
---|
[8974] | 2056 | form_fields = grok.AutoFields(IUGStudentClearance).omit( |
---|
[9486] | 2057 | 'clearance_locked', 'clr_code', 'officer_comment') |
---|
[7993] | 2058 | return form_fields |
---|
| 2059 | |
---|
[6718] | 2060 | def update(self): |
---|
| 2061 | if self.context.clearance_locked: |
---|
[7145] | 2062 | emit_lock_message(self) |
---|
[6718] | 2063 | return |
---|
| 2064 | return super(StudentClearanceEditFormPage, self).update() |
---|
[6719] | 2065 | |
---|
[7723] | 2066 | @action(_('Save'), style='primary') |
---|
[6722] | 2067 | def save(self, **data): |
---|
| 2068 | self.applyData(self.context, **data) |
---|
[7723] | 2069 | self.flash(_('Clearance form has been saved.')) |
---|
[6722] | 2070 | return |
---|
| 2071 | |
---|
[7253] | 2072 | def dataNotComplete(self): |
---|
[7642] | 2073 | """To be implemented in the customization package. |
---|
| 2074 | """ |
---|
[7253] | 2075 | return False |
---|
| 2076 | |
---|
[7723] | 2077 | @action(_('Save and request clearance'), style='primary') |
---|
[7186] | 2078 | def requestClearance(self, **data): |
---|
[6722] | 2079 | self.applyData(self.context, **data) |
---|
[7253] | 2080 | if self.dataNotComplete(): |
---|
| 2081 | self.flash(self.dataNotComplete()) |
---|
| 2082 | return |
---|
[7723] | 2083 | self.flash(_('Clearance form has been saved.')) |
---|
[9021] | 2084 | if self.context.clr_code: |
---|
| 2085 | self.redirect(self.url(self.context, 'request_clearance')) |
---|
| 2086 | else: |
---|
| 2087 | # We bypass the request_clearance page if student |
---|
| 2088 | # has been imported in state 'clearance started' and |
---|
| 2089 | # no clr_code was entered before. |
---|
| 2090 | state = IWorkflowState(self.context).getState() |
---|
| 2091 | if state != CLEARANCE: |
---|
| 2092 | # This shouldn't happen, but the application officer |
---|
| 2093 | # might have forgotten to lock the form after changing the state |
---|
| 2094 | self.flash(_('This form cannot be submitted. Wrong state!')) |
---|
| 2095 | return |
---|
| 2096 | IWorkflowInfo(self.context).fireTransition('request_clearance') |
---|
| 2097 | self.flash(_('Clearance has been requested.')) |
---|
| 2098 | self.redirect(self.url(self.context)) |
---|
[6722] | 2099 | return |
---|
| 2100 | |
---|
[7819] | 2101 | class RequestClearancePage(KofaPage): |
---|
[6769] | 2102 | grok.context(IStudent) |
---|
| 2103 | grok.name('request_clearance') |
---|
| 2104 | grok.require('waeup.handleStudent') |
---|
| 2105 | grok.template('enterpin') |
---|
[7723] | 2106 | label = _('Request clearance') |
---|
| 2107 | notice = _('Enter the CLR access code used for starting clearance.') |
---|
[6769] | 2108 | ac_prefix = 'CLR' |
---|
| 2109 | pnav = 4 |
---|
[7723] | 2110 | buttonname = _('Request clearance now') |
---|
[6769] | 2111 | |
---|
| 2112 | def update(self, SUBMIT=None): |
---|
| 2113 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 2114 | self.ac_number = self.request.form.get('ac_number', None) |
---|
| 2115 | if SUBMIT is None: |
---|
| 2116 | return |
---|
| 2117 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
[9021] | 2118 | if self.context.clr_code and self.context.clr_code != pin: |
---|
[7723] | 2119 | self.flash(_("This isn't your CLR access code.")) |
---|
[6769] | 2120 | return |
---|
| 2121 | state = IWorkflowState(self.context).getState() |
---|
| 2122 | if state != CLEARANCE: |
---|
[9021] | 2123 | # This shouldn't happen, but the application officer |
---|
| 2124 | # might have forgotten to lock the form after changing the state |
---|
[7723] | 2125 | self.flash(_('This form cannot be submitted. Wrong state!')) |
---|
[6769] | 2126 | return |
---|
| 2127 | IWorkflowInfo(self.context).fireTransition('request_clearance') |
---|
[7723] | 2128 | self.flash(_('Clearance has been requested.')) |
---|
[6769] | 2129 | self.redirect(self.url(self.context)) |
---|
[6789] | 2130 | return |
---|
[6806] | 2131 | |
---|
[8471] | 2132 | class StartSessionPage(KofaPage): |
---|
[6944] | 2133 | grok.context(IStudentStudyCourse) |
---|
[8471] | 2134 | grok.name('start_session') |
---|
[6944] | 2135 | grok.require('waeup.handleStudent') |
---|
| 2136 | grok.template('enterpin') |
---|
[8471] | 2137 | label = _('Start session') |
---|
[6944] | 2138 | ac_prefix = 'SFE' |
---|
| 2139 | notice = '' |
---|
| 2140 | pnav = 4 |
---|
[8471] | 2141 | buttonname = _('Start now') |
---|
[6944] | 2142 | |
---|
| 2143 | def update(self, SUBMIT=None): |
---|
[9139] | 2144 | if not self.context.is_current: |
---|
| 2145 | emit_lock_message(self) |
---|
| 2146 | return |
---|
| 2147 | super(StartSessionPage, self).update() |
---|
[8471] | 2148 | if not self.context.next_session_allowed: |
---|
| 2149 | self.flash(_("You are not entitled to start session.")) |
---|
[6944] | 2150 | self.redirect(self.url(self.context)) |
---|
| 2151 | return |
---|
| 2152 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 2153 | self.ac_number = self.request.form.get('ac_number', None) |
---|
| 2154 | |
---|
| 2155 | if SUBMIT is None: |
---|
| 2156 | return |
---|
| 2157 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 2158 | code = get_access_code(pin) |
---|
| 2159 | if not code: |
---|
[7723] | 2160 | self.flash(_('Activation code is invalid.')) |
---|
[6944] | 2161 | return |
---|
| 2162 | # Mark pin as used (this also fires a pin related transition) |
---|
| 2163 | if code.state == USED: |
---|
[7723] | 2164 | self.flash(_('Activation code has already been used.')) |
---|
[6944] | 2165 | return |
---|
| 2166 | else: |
---|
[7723] | 2167 | comment = _(u"invalidated") |
---|
[6944] | 2168 | # Here we know that the ac is in state initialized so we do not |
---|
[8471] | 2169 | # expect an error, but the owner might be different |
---|
[6944] | 2170 | if not invalidate_accesscode( |
---|
[8736] | 2171 | pin,comment,self.context.student.student_id): |
---|
[7723] | 2172 | self.flash(_('You are not the owner of this access code.')) |
---|
[6944] | 2173 | return |
---|
[9637] | 2174 | try: |
---|
| 2175 | if self.context.student.state == CLEARED: |
---|
| 2176 | IWorkflowInfo(self.context.student).fireTransition( |
---|
| 2177 | 'pay_first_school_fee') |
---|
| 2178 | elif self.context.student.state == RETURNING: |
---|
| 2179 | IWorkflowInfo(self.context.student).fireTransition( |
---|
| 2180 | 'pay_school_fee') |
---|
| 2181 | elif self.context.student.state == PAID: |
---|
| 2182 | IWorkflowInfo(self.context.student).fireTransition( |
---|
| 2183 | 'pay_pg_fee') |
---|
| 2184 | except ConstraintNotSatisfied: |
---|
| 2185 | self.flash(_('An error occurred, please contact the system administrator.')) |
---|
| 2186 | return |
---|
[8471] | 2187 | self.flash(_('Session started.')) |
---|
[6944] | 2188 | self.redirect(self.url(self.context)) |
---|
| 2189 | return |
---|
| 2190 | |
---|
[7819] | 2191 | class AddStudyLevelFormPage(KofaEditFormPage): |
---|
[6806] | 2192 | """ Page for students to add current study levels |
---|
| 2193 | """ |
---|
| 2194 | grok.context(IStudentStudyCourse) |
---|
| 2195 | grok.name('add') |
---|
| 2196 | grok.require('waeup.handleStudent') |
---|
| 2197 | grok.template('studyleveladdpage') |
---|
| 2198 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 2199 | pnav = 4 |
---|
| 2200 | |
---|
| 2201 | @property |
---|
| 2202 | def label(self): |
---|
| 2203 | studylevelsource = StudyLevelSource().factory |
---|
| 2204 | code = self.context.current_level |
---|
| 2205 | title = studylevelsource.getTitle(self.context, code) |
---|
[7723] | 2206 | return _('Add current level ${a}', mapping = {'a':title}) |
---|
[6806] | 2207 | |
---|
| 2208 | def update(self): |
---|
[9139] | 2209 | if not self.context.is_current: |
---|
| 2210 | emit_lock_message(self) |
---|
| 2211 | return |
---|
[8736] | 2212 | if self.context.student.state != PAID: |
---|
[7145] | 2213 | emit_lock_message(self) |
---|
[6806] | 2214 | return |
---|
| 2215 | super(AddStudyLevelFormPage, self).update() |
---|
| 2216 | return |
---|
| 2217 | |
---|
[7723] | 2218 | @action(_('Create course list now'), style='primary') |
---|
[6806] | 2219 | def addStudyLevel(self, **data): |
---|
[8323] | 2220 | studylevel = createObject(u'waeup.StudentStudyLevel') |
---|
[6806] | 2221 | studylevel.level = self.context.current_level |
---|
| 2222 | studylevel.level_session = self.context.current_session |
---|
| 2223 | try: |
---|
| 2224 | self.context.addStudentStudyLevel( |
---|
| 2225 | self.context.certificate,studylevel) |
---|
| 2226 | except KeyError: |
---|
[7723] | 2227 | self.flash(_('This level exists.')) |
---|
[9467] | 2228 | except RequiredMissing: |
---|
| 2229 | self.flash(_('Your data are incomplete')) |
---|
[6806] | 2230 | self.redirect(self.url(self.context)) |
---|
| 2231 | return |
---|
[6808] | 2232 | |
---|
[7819] | 2233 | class StudyLevelEditFormPage(KofaEditFormPage): |
---|
[6808] | 2234 | """ Page to edit the student study level data by students |
---|
| 2235 | """ |
---|
| 2236 | grok.context(IStudentStudyLevel) |
---|
| 2237 | grok.name('edit') |
---|
| 2238 | grok.require('waeup.handleStudent') |
---|
| 2239 | grok.template('studyleveleditpage') |
---|
| 2240 | form_fields = grok.AutoFields(IStudentStudyLevel).omit( |
---|
| 2241 | 'level_session', 'level_verdict') |
---|
| 2242 | pnav = 4 |
---|
| 2243 | |
---|
| 2244 | def update(self): |
---|
[9139] | 2245 | if not self.context.__parent__.is_current: |
---|
| 2246 | emit_lock_message(self) |
---|
| 2247 | return |
---|
[9257] | 2248 | if self.context.student.state != PAID or \ |
---|
| 2249 | not self.context.is_current_level: |
---|
[7539] | 2250 | emit_lock_message(self) |
---|
| 2251 | return |
---|
[6808] | 2252 | super(StudyLevelEditFormPage, self).update() |
---|
| 2253 | datatable.need() |
---|
[7329] | 2254 | warning.need() |
---|
[6808] | 2255 | return |
---|
| 2256 | |
---|
| 2257 | @property |
---|
| 2258 | def label(self): |
---|
[7833] | 2259 | # Here we know that the cookie has been set |
---|
| 2260 | lang = self.request.cookies.get('kofa.language') |
---|
[7811] | 2261 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 2262 | target_language=lang) |
---|
[8920] | 2263 | return _('Edit course list of ${a}', |
---|
[7723] | 2264 | mapping = {'a':level_title}) |
---|
[6808] | 2265 | |
---|
| 2266 | @property |
---|
[8921] | 2267 | def translated_values(self): |
---|
| 2268 | return translated_values(self) |
---|
| 2269 | |
---|
[7723] | 2270 | @action(_('Add course ticket')) |
---|
[6808] | 2271 | def addCourseTicket(self, **data): |
---|
| 2272 | self.redirect(self.url(self.context, 'ctadd')) |
---|
| 2273 | |
---|
[9280] | 2274 | def _delCourseTicket(self, **data): |
---|
[6808] | 2275 | form = self.request.form |
---|
[9701] | 2276 | if 'val_id' in form: |
---|
[6808] | 2277 | child_id = form['val_id'] |
---|
| 2278 | else: |
---|
[7723] | 2279 | self.flash(_('No ticket selected.')) |
---|
[6808] | 2280 | self.redirect(self.url(self.context, '@@edit')) |
---|
| 2281 | return |
---|
| 2282 | if not isinstance(child_id, list): |
---|
| 2283 | child_id = [child_id] |
---|
| 2284 | deleted = [] |
---|
| 2285 | for id in child_id: |
---|
[6940] | 2286 | # Students are not allowed to remove core tickets |
---|
[9700] | 2287 | if id in self.context and \ |
---|
| 2288 | self.context[id].removable_by_student: |
---|
[7723] | 2289 | del self.context[id] |
---|
| 2290 | deleted.append(id) |
---|
[6808] | 2291 | if len(deleted): |
---|
[7723] | 2292 | self.flash(_('Successfully removed: ${a}', |
---|
| 2293 | mapping = {'a':', '.join(deleted)})) |
---|
[9332] | 2294 | self.context.writeLogMessage( |
---|
| 2295 | self,'removed: %s' % ', '.join(deleted)) |
---|
[6808] | 2296 | self.redirect(self.url(self.context, u'@@edit')) |
---|
| 2297 | return |
---|
| 2298 | |
---|
[9280] | 2299 | @jsaction(_('Remove selected tickets')) |
---|
| 2300 | def delCourseTicket(self, **data): |
---|
| 2301 | self._delCourseTicket(**data) |
---|
| 2302 | return |
---|
| 2303 | |
---|
| 2304 | def _registerCourses(self, **data): |
---|
[9252] | 2305 | if self.context.student.is_postgrad: |
---|
| 2306 | self.flash(_( |
---|
| 2307 | "You are a postgraduate student, " |
---|
| 2308 | "your course list can't bee registered.")) |
---|
| 2309 | self.redirect(self.url(self.context)) |
---|
| 2310 | return |
---|
[9830] | 2311 | students_utils = getUtility(IStudentsUtils) |
---|
| 2312 | max_credits = students_utils.maxCredits(self.context) |
---|
| 2313 | if self.context.total_credits > max_credits: |
---|
[8642] | 2314 | self.flash(_('Maximum credits of ${a} exceeded.', |
---|
[9830] | 2315 | mapping = {'a':max_credits})) |
---|
[8642] | 2316 | return |
---|
[8736] | 2317 | IWorkflowInfo(self.context.student).fireTransition( |
---|
[7642] | 2318 | 'register_courses') |
---|
[7723] | 2319 | self.flash(_('Course list has been registered.')) |
---|
[6810] | 2320 | self.redirect(self.url(self.context)) |
---|
| 2321 | return |
---|
| 2322 | |
---|
[9280] | 2323 | @action(_('Register course list'), style='primary') |
---|
| 2324 | def registerCourses(self, **data): |
---|
| 2325 | self._registerCourses(**data) |
---|
| 2326 | return |
---|
| 2327 | |
---|
| 2328 | |
---|
[6808] | 2329 | class CourseTicketAddFormPage2(CourseTicketAddFormPage): |
---|
| 2330 | """Add a course ticket by student. |
---|
| 2331 | """ |
---|
| 2332 | grok.name('ctadd') |
---|
| 2333 | grok.require('waeup.handleStudent') |
---|
[9420] | 2334 | form_fields = grok.AutoFields(ICourseTicketAdd) |
---|
[6808] | 2335 | |
---|
[7539] | 2336 | def update(self): |
---|
[9257] | 2337 | if self.context.student.state != PAID or \ |
---|
| 2338 | not self.context.is_current_level: |
---|
[7539] | 2339 | emit_lock_message(self) |
---|
| 2340 | return |
---|
| 2341 | super(CourseTicketAddFormPage2, self).update() |
---|
| 2342 | return |
---|
| 2343 | |
---|
[7723] | 2344 | @action(_('Add course ticket')) |
---|
[6808] | 2345 | def addCourseTicket(self, **data): |
---|
[9532] | 2346 | students_utils = getUtility(IStudentsUtils) |
---|
[7642] | 2347 | # Safety belt |
---|
[8736] | 2348 | if self.context.student.state != PAID: |
---|
[7539] | 2349 | return |
---|
[8325] | 2350 | ticket = createObject(u'waeup.CourseTicket') |
---|
[6808] | 2351 | course = data['course'] |
---|
| 2352 | ticket.automatic = False |
---|
[8920] | 2353 | ticket.carry_over = False |
---|
[9532] | 2354 | max_credits = students_utils.maxCreditsExceeded(self.context, course) |
---|
| 2355 | if max_credits: |
---|
| 2356 | self.flash(_( |
---|
| 2357 | 'Your total credits exceed ${a}.', |
---|
| 2358 | mapping = {'a': max_credits})) |
---|
| 2359 | return |
---|
[6808] | 2360 | try: |
---|
[8920] | 2361 | self.context.addCourseTicket(ticket, course) |
---|
[6808] | 2362 | except KeyError: |
---|
[7723] | 2363 | self.flash(_('The ticket exists.')) |
---|
[6808] | 2364 | return |
---|
[7723] | 2365 | self.flash(_('Successfully added ${a}.', |
---|
| 2366 | mapping = {'a':ticket.code})) |
---|
[6808] | 2367 | self.redirect(self.url(self.context, u'@@edit')) |
---|
| 2368 | return |
---|
[7369] | 2369 | |
---|
| 2370 | |
---|
[7819] | 2371 | class SetPasswordPage(KofaPage): |
---|
| 2372 | grok.context(IKofaObject) |
---|
[7660] | 2373 | grok.name('setpassword') |
---|
| 2374 | grok.require('waeup.Anonymous') |
---|
| 2375 | grok.template('setpassword') |
---|
[7723] | 2376 | label = _('Set password for first-time login') |
---|
[7660] | 2377 | ac_prefix = 'PWD' |
---|
| 2378 | pnav = 0 |
---|
[7738] | 2379 | set_button = _('Set') |
---|
[7660] | 2380 | |
---|
| 2381 | def update(self, SUBMIT=None): |
---|
| 2382 | self.reg_number = self.request.form.get('reg_number', None) |
---|
| 2383 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 2384 | self.ac_number = self.request.form.get('ac_number', None) |
---|
| 2385 | |
---|
| 2386 | if SUBMIT is None: |
---|
| 2387 | return |
---|
| 2388 | hitlist = search(query=self.reg_number, |
---|
| 2389 | searchtype='reg_number', view=self) |
---|
| 2390 | if not hitlist: |
---|
[7723] | 2391 | self.flash(_('No student found.')) |
---|
[7660] | 2392 | return |
---|
| 2393 | if len(hitlist) != 1: # Cannot happen but anyway |
---|
[7723] | 2394 | self.flash(_('More than one student found.')) |
---|
[7660] | 2395 | return |
---|
| 2396 | student = hitlist[0].context |
---|
| 2397 | self.student_id = student.student_id |
---|
| 2398 | student_pw = student.password |
---|
| 2399 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 2400 | code = get_access_code(pin) |
---|
| 2401 | if not code: |
---|
[7723] | 2402 | self.flash(_('Access code is invalid.')) |
---|
[7660] | 2403 | return |
---|
| 2404 | if student_pw and pin == student.adm_code: |
---|
[7723] | 2405 | self.flash(_( |
---|
| 2406 | 'Password has already been set. Your Student Id is ${a}', |
---|
| 2407 | mapping = {'a':self.student_id})) |
---|
[7660] | 2408 | return |
---|
| 2409 | elif student_pw: |
---|
| 2410 | self.flash( |
---|
[7723] | 2411 | _('Password has already been set. You are using the ' + |
---|
| 2412 | 'wrong Access Code.')) |
---|
[7660] | 2413 | return |
---|
| 2414 | # Mark pin as used (this also fires a pin related transition) |
---|
| 2415 | # and set student password |
---|
| 2416 | if code.state == USED: |
---|
[7723] | 2417 | self.flash(_('Access code has already been used.')) |
---|
[7660] | 2418 | return |
---|
| 2419 | else: |
---|
[7723] | 2420 | comment = _(u"invalidated") |
---|
[7660] | 2421 | # Here we know that the ac is in state initialized so we do not |
---|
| 2422 | # expect an exception |
---|
| 2423 | invalidate_accesscode(pin,comment) |
---|
| 2424 | IUserAccount(student).setPassword(self.ac_number) |
---|
| 2425 | student.adm_code = pin |
---|
[7723] | 2426 | self.flash(_('Password has been set. Your Student Id is ${a}', |
---|
| 2427 | mapping = {'a':self.student_id})) |
---|
[7811] | 2428 | return |
---|
[8779] | 2429 | |
---|
| 2430 | class StudentRequestPasswordPage(KofaAddFormPage): |
---|
| 2431 | """Captcha'd registration page for applicants. |
---|
| 2432 | """ |
---|
| 2433 | grok.name('requestpw') |
---|
| 2434 | grok.require('waeup.Anonymous') |
---|
| 2435 | grok.template('requestpw') |
---|
| 2436 | form_fields = grok.AutoFields(IStudentRequestPW).select( |
---|
[8854] | 2437 | 'firstname','number','email') |
---|
[8779] | 2438 | label = _('Request password for first-time login') |
---|
| 2439 | |
---|
| 2440 | def update(self): |
---|
| 2441 | # Handle captcha |
---|
| 2442 | self.captcha = getUtility(ICaptchaManager).getCaptcha() |
---|
| 2443 | self.captcha_result = self.captcha.verify(self.request) |
---|
| 2444 | self.captcha_code = self.captcha.display(self.captcha_result.error_code) |
---|
| 2445 | return |
---|
| 2446 | |
---|
| 2447 | def _redirect(self, email, password, student_id): |
---|
| 2448 | # Forward only email to landing page in base package. |
---|
| 2449 | self.redirect(self.url(self.context, 'requestpw_complete', |
---|
| 2450 | data = dict(email=email))) |
---|
| 2451 | return |
---|
| 2452 | |
---|
| 2453 | def _pw_used(self): |
---|
[8780] | 2454 | # XXX: False if password has not been used. We need an extra |
---|
| 2455 | # attribute which remembers if student logged in. |
---|
[8779] | 2456 | return True |
---|
| 2457 | |
---|
[8854] | 2458 | @action(_('Send login credentials to email address'), style='primary') |
---|
[8779] | 2459 | def get_credentials(self, **data): |
---|
| 2460 | if not self.captcha_result.is_valid: |
---|
| 2461 | # Captcha will display error messages automatically. |
---|
| 2462 | # No need to flash something. |
---|
| 2463 | return |
---|
[8854] | 2464 | number = data.get('number','') |
---|
[8779] | 2465 | firstname = data.get('firstname','') |
---|
| 2466 | cat = getUtility(ICatalog, name='students_catalog') |
---|
| 2467 | results = list( |
---|
[8854] | 2468 | cat.searchResults(reg_number=(number, number))) |
---|
| 2469 | if not results: |
---|
| 2470 | results = list( |
---|
| 2471 | cat.searchResults(matric_number=(number, number))) |
---|
[8779] | 2472 | if results: |
---|
| 2473 | student = results[0] |
---|
| 2474 | if getattr(student,'firstname',None) is None: |
---|
| 2475 | self.flash(_('An error occurred.')) |
---|
| 2476 | return |
---|
| 2477 | elif student.firstname.lower() != firstname.lower(): |
---|
| 2478 | # Don't tell the truth here. Anonymous must not |
---|
| 2479 | # know that a record was found and only the firstname |
---|
| 2480 | # verification failed. |
---|
| 2481 | self.flash(_('No student record found.')) |
---|
| 2482 | return |
---|
| 2483 | elif student.password is not None and self._pw_used: |
---|
| 2484 | self.flash(_('Your password has already been set and used. ' |
---|
| 2485 | 'Please proceed to the login page.')) |
---|
| 2486 | return |
---|
| 2487 | # Store email address but nothing else. |
---|
| 2488 | student.email = data['email'] |
---|
| 2489 | notify(grok.ObjectModifiedEvent(student)) |
---|
| 2490 | else: |
---|
| 2491 | # No record found, this is the truth. |
---|
| 2492 | self.flash(_('No student record found.')) |
---|
| 2493 | return |
---|
| 2494 | |
---|
| 2495 | kofa_utils = getUtility(IKofaUtils) |
---|
| 2496 | password = kofa_utils.genPassword() |
---|
[8857] | 2497 | mandate = PasswordMandate() |
---|
[8853] | 2498 | mandate.params['password'] = password |
---|
[8858] | 2499 | mandate.params['user'] = student |
---|
[8853] | 2500 | site = grok.getSite() |
---|
| 2501 | site['mandates'].addMandate(mandate) |
---|
[8779] | 2502 | # Send email with credentials |
---|
[8853] | 2503 | args = {'mandate_id':mandate.mandate_id} |
---|
| 2504 | mandate_url = self.url(site) + '/mandate?%s' % urlencode(args) |
---|
| 2505 | url_info = u'Confirmation link: %s' % mandate_url |
---|
[8779] | 2506 | msg = _('You have successfully requested a password for the') |
---|
| 2507 | if kofa_utils.sendCredentials(IUserAccount(student), |
---|
[8853] | 2508 | password, url_info, msg): |
---|
[8779] | 2509 | email_sent = student.email |
---|
| 2510 | else: |
---|
| 2511 | email_sent = None |
---|
| 2512 | self._redirect(email=email_sent, password=password, |
---|
| 2513 | student_id=student.student_id) |
---|
[8856] | 2514 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 2515 | self.context.logger.info( |
---|
| 2516 | '%s - %s (%s) - %s' % (ob_class, number, student.student_id, email_sent)) |
---|
[8779] | 2517 | return |
---|
| 2518 | |
---|
| 2519 | class StudentRequestPasswordEmailSent(KofaPage): |
---|
| 2520 | """Landing page after successful password request. |
---|
| 2521 | |
---|
| 2522 | """ |
---|
| 2523 | grok.name('requestpw_complete') |
---|
| 2524 | grok.require('waeup.Public') |
---|
| 2525 | grok.template('requestpwmailsent') |
---|
| 2526 | label = _('Your password request was successful.') |
---|
| 2527 | |
---|
| 2528 | def update(self, email=None, student_id=None, password=None): |
---|
| 2529 | self.email = email |
---|
| 2530 | self.password = password |
---|
| 2531 | self.student_id = student_id |
---|
[8974] | 2532 | return |
---|
[9797] | 2533 | |
---|
[9806] | 2534 | class FilterStudentsInDepartmentPage(KofaPage): |
---|
| 2535 | """Page that filters and lists students. |
---|
| 2536 | """ |
---|
| 2537 | grok.context(IDepartment) |
---|
| 2538 | grok.require('waeup.showStudents') |
---|
| 2539 | grok.name('students') |
---|
| 2540 | grok.template('filterstudentspage') |
---|
| 2541 | pnav = 1 |
---|
[9819] | 2542 | session_label = _('Current Session') |
---|
| 2543 | level_label = _('Current Level') |
---|
[9806] | 2544 | |
---|
| 2545 | def label(self): |
---|
[9819] | 2546 | return 'Students in %s' % self.context.longtitle() |
---|
[9806] | 2547 | |
---|
| 2548 | def _set_session_values(self): |
---|
| 2549 | vocab_terms = academic_sessions_vocab.by_value.values() |
---|
| 2550 | self.sessions = sorted( |
---|
| 2551 | [(x.title, x.token) for x in vocab_terms], reverse=True) |
---|
| 2552 | self.sessions += [('All Sessions', 'all')] |
---|
| 2553 | return |
---|
| 2554 | |
---|
| 2555 | def _set_level_values(self): |
---|
| 2556 | vocab_terms = course_levels.by_value.values() |
---|
| 2557 | self.levels = sorted( |
---|
| 2558 | [(x.title, x.token) for x in vocab_terms]) |
---|
| 2559 | self.levels += [('All Levels', 'all')] |
---|
| 2560 | return |
---|
| 2561 | |
---|
| 2562 | def _searchCatalog(self, session, level): |
---|
| 2563 | if level not in (10, 999, None): |
---|
| 2564 | start_level = 100 * (level // 100) |
---|
| 2565 | end_level = start_level + 90 |
---|
| 2566 | else: |
---|
| 2567 | start_level = end_level = level |
---|
| 2568 | cat = queryUtility(ICatalog, name='students_catalog') |
---|
| 2569 | students = cat.searchResults( |
---|
| 2570 | current_session=(session, session), |
---|
| 2571 | current_level=(start_level, end_level), |
---|
| 2572 | depcode=(self.context.code, self.context.code) |
---|
| 2573 | ) |
---|
| 2574 | hitlist = [] |
---|
| 2575 | for student in students: |
---|
| 2576 | hitlist.append(StudentQueryResultItem(student, view=self)) |
---|
| 2577 | return hitlist |
---|
| 2578 | |
---|
| 2579 | def update(self, SHOW=None, session=None, level=None): |
---|
| 2580 | datatable.need() |
---|
| 2581 | self.parent_url = self.url(self.context.__parent__) |
---|
| 2582 | self._set_session_values() |
---|
| 2583 | self._set_level_values() |
---|
| 2584 | self.hitlist = [] |
---|
| 2585 | self.session_default = session |
---|
| 2586 | self.level_default = level |
---|
| 2587 | if SHOW is not None: |
---|
| 2588 | if session != 'all': |
---|
| 2589 | self.session = int(session) |
---|
| 2590 | self.session_string = '%s %s/%s' % ( |
---|
| 2591 | self.session_label, self.session, self.session+1) |
---|
| 2592 | else: |
---|
| 2593 | self.session = None |
---|
| 2594 | self.session_string = _('in any session') |
---|
| 2595 | if level != 'all': |
---|
| 2596 | self.level = int(level) |
---|
| 2597 | self.level_string = '%s %s' % (self.level_label, self.level) |
---|
| 2598 | else: |
---|
| 2599 | self.level = None |
---|
| 2600 | self.level_string = _('at any level') |
---|
| 2601 | self.hitlist = self._searchCatalog(self.session, self.level) |
---|
| 2602 | if not self.hitlist: |
---|
| 2603 | self.flash(_('No student found.')) |
---|
| 2604 | return |
---|
| 2605 | |
---|
| 2606 | class FilterStudentsInCertificatePage(FilterStudentsInDepartmentPage): |
---|
| 2607 | """Page that filters and lists students. |
---|
| 2608 | """ |
---|
| 2609 | grok.context(ICertificate) |
---|
| 2610 | |
---|
| 2611 | def label(self): |
---|
[9819] | 2612 | return 'Students studying %s' % self.context.longtitle() |
---|
[9806] | 2613 | |
---|
| 2614 | def _searchCatalog(self, session, level): |
---|
| 2615 | if level not in (10, 999, None): |
---|
| 2616 | start_level = 100 * (level // 100) |
---|
| 2617 | end_level = start_level + 90 |
---|
| 2618 | else: |
---|
| 2619 | start_level = end_level = level |
---|
| 2620 | cat = queryUtility(ICatalog, name='students_catalog') |
---|
| 2621 | students = cat.searchResults( |
---|
| 2622 | current_session=(session, session), |
---|
| 2623 | current_level=(start_level, end_level), |
---|
| 2624 | certcode=(self.context.code, self.context.code) |
---|
| 2625 | ) |
---|
| 2626 | hitlist = [] |
---|
| 2627 | for student in students: |
---|
| 2628 | hitlist.append(StudentQueryResultItem(student, view=self)) |
---|
| 2629 | return hitlist |
---|
| 2630 | |
---|
| 2631 | class FilterStudentsInCoursePage(FilterStudentsInDepartmentPage): |
---|
| 2632 | """Page that filters and lists students. |
---|
| 2633 | """ |
---|
| 2634 | grok.context(ICourse) |
---|
| 2635 | |
---|
| 2636 | def label(self): |
---|
[9819] | 2637 | return 'Students registered for %s' % self.context.longtitle() |
---|
[9806] | 2638 | |
---|
| 2639 | def _searchCatalog(self, session, level): |
---|
| 2640 | if level not in (10, 999, None): |
---|
| 2641 | start_level = 100 * (level // 100) |
---|
| 2642 | end_level = start_level + 90 |
---|
| 2643 | else: |
---|
| 2644 | start_level = end_level = level |
---|
| 2645 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
---|
| 2646 | coursetickets = cat.searchResults( |
---|
| 2647 | session=(session, session), |
---|
| 2648 | level=(start_level, end_level), |
---|
| 2649 | code=(self.context.code, self.context.code) |
---|
| 2650 | ) |
---|
| 2651 | hitlist = [] |
---|
| 2652 | for ticket in coursetickets: |
---|
| 2653 | # XXX: If students have registered the same courses twice |
---|
| 2654 | # they will be listed twice. |
---|
| 2655 | hitlist.append(StudentQueryResultItem(ticket.student, view=self)) |
---|
| 2656 | return hitlist |
---|
| 2657 | |
---|
[9813] | 2658 | class ExportJobContainerOverview(KofaPage): |
---|
[9835] | 2659 | """Page that lists active student data export jobs and provides links |
---|
| 2660 | to discard or download CSV files. |
---|
| 2661 | |
---|
[9797] | 2662 | """ |
---|
[9813] | 2663 | grok.context(VirtualExportJobContainer) |
---|
[9797] | 2664 | grok.require('waeup.showStudents') |
---|
| 2665 | grok.name('index.html') |
---|
| 2666 | grok.template('exportjobsindex') |
---|
[9813] | 2667 | label = _('Student Data Exports') |
---|
[9797] | 2668 | pnav = 1 |
---|
| 2669 | |
---|
| 2670 | def update(self, CREATE=None, DISCARD=None, job_id=None): |
---|
| 2671 | if CREATE: |
---|
[9836] | 2672 | self.redirect(self.url('@@exportconfig')) |
---|
[9797] | 2673 | return |
---|
| 2674 | if DISCARD and job_id: |
---|
| 2675 | entry = self.context.entry_from_job_id(job_id) |
---|
| 2676 | self.context.delete_export_entry(entry) |
---|
[9836] | 2677 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 2678 | self.context.logger.info( |
---|
| 2679 | '%s - discarded: job_id=%s' % (ob_class, job_id)) |
---|
[9819] | 2680 | self.flash(_('Discarded export') + ' %s' % job_id) |
---|
[9822] | 2681 | self.entries = doll_up(self, user=self.request.principal.id) |
---|
[9797] | 2682 | return |
---|
| 2683 | |
---|
[9833] | 2684 | class ExportJobContainerJobConfig(KofaPage): |
---|
[9797] | 2685 | """Page that configures a students export job. |
---|
[9833] | 2686 | |
---|
| 2687 | This is a baseclass. |
---|
[9797] | 2688 | """ |
---|
[9833] | 2689 | grok.baseclass() |
---|
[9836] | 2690 | grok.name('exportconfig') |
---|
[9797] | 2691 | grok.require('waeup.showStudents') |
---|
[9836] | 2692 | grok.template('exportconfig') |
---|
[9833] | 2693 | label = _('Configure student data export') |
---|
[9797] | 2694 | pnav = 1 |
---|
[9835] | 2695 | redirect_target = '' |
---|
[9797] | 2696 | |
---|
| 2697 | def _set_session_values(self): |
---|
| 2698 | vocab_terms = academic_sessions_vocab.by_value.values() |
---|
| 2699 | self.sessions = sorted( |
---|
| 2700 | [(x.title, x.token) for x in vocab_terms], reverse=True) |
---|
[9819] | 2701 | self.sessions += [(_('All Sessions'), 'all')] |
---|
[9797] | 2702 | return |
---|
| 2703 | |
---|
| 2704 | def _set_level_values(self): |
---|
| 2705 | vocab_terms = course_levels.by_value.values() |
---|
| 2706 | self.levels = sorted( |
---|
| 2707 | [(x.title, x.token) for x in vocab_terms]) |
---|
[9819] | 2708 | self.levels += [(_('All Levels'), 'all')] |
---|
[9797] | 2709 | return |
---|
| 2710 | |
---|
[9803] | 2711 | def _set_mode_values(self): |
---|
| 2712 | utils = getUtility(IKofaUtils) |
---|
[9838] | 2713 | self.modes = sorted([(value, key) for key, value in |
---|
| 2714 | utils.STUDY_MODES_DICT.items()]) |
---|
[9819] | 2715 | self.modes +=[(_('All Modes'), 'all')] |
---|
[9803] | 2716 | return |
---|
| 2717 | |
---|
[9804] | 2718 | def _set_exporter_values(self): |
---|
| 2719 | # We provide all student exporters, nothing else, yet. |
---|
| 2720 | exporters = [] |
---|
| 2721 | for name in EXPORTER_NAMES: |
---|
| 2722 | util = getUtility(ICSVExporter, name=name) |
---|
| 2723 | exporters.append((util.title, name),) |
---|
| 2724 | self.exporters = exporters |
---|
| 2725 | |
---|
[9833] | 2726 | @property |
---|
| 2727 | def depcode(self): |
---|
| 2728 | return None |
---|
| 2729 | |
---|
[9842] | 2730 | @property |
---|
| 2731 | def certcode(self): |
---|
| 2732 | return None |
---|
| 2733 | |
---|
[9804] | 2734 | def update(self, START=None, session=None, level=None, mode=None, |
---|
| 2735 | exporter=None): |
---|
[9797] | 2736 | self._set_session_values() |
---|
| 2737 | self._set_level_values() |
---|
[9803] | 2738 | self._set_mode_values() |
---|
[9804] | 2739 | self._set_exporter_values() |
---|
[9797] | 2740 | if START is None: |
---|
| 2741 | return |
---|
| 2742 | if session == 'all': |
---|
| 2743 | session=None |
---|
| 2744 | if level == 'all': |
---|
| 2745 | level = None |
---|
[9803] | 2746 | if mode == 'all': |
---|
| 2747 | mode = None |
---|
[9836] | 2748 | job_id = self.context.start_export_job(exporter, |
---|
| 2749 | self.request.principal.id, |
---|
[9797] | 2750 | current_session=session, |
---|
| 2751 | current_level=level, |
---|
[9803] | 2752 | current_mode=mode, |
---|
[9842] | 2753 | depcode=self.depcode, |
---|
| 2754 | certcode=self.certcode) |
---|
[9836] | 2755 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 2756 | self.context.logger.info( |
---|
[9842] | 2757 | '%s - exported: %s (%s, %s, %s, %s, %s), job_id=%s' |
---|
| 2758 | % (ob_class, exporter, session, level, mode, self.depcode, |
---|
| 2759 | self.certcode, job_id)) |
---|
[9833] | 2760 | self.flash(_('Export started for students with') + |
---|
| 2761 | ' current_session=%s, current_level=%s, study_mode=%s' % ( |
---|
| 2762 | session, level, mode)) |
---|
[9835] | 2763 | self.redirect(self.url(self.redirect_target)) |
---|
[9797] | 2764 | return |
---|
| 2765 | |
---|
[9822] | 2766 | class ExportJobContainerDownload(ExportCSVView): |
---|
[9835] | 2767 | """Page that downloads a students export csv file. |
---|
| 2768 | |
---|
[9797] | 2769 | """ |
---|
[9813] | 2770 | grok.context(VirtualExportJobContainer) |
---|
[9797] | 2771 | grok.require('waeup.showStudents') |
---|
[9833] | 2772 | |
---|
| 2773 | class DatacenterExportJobContainerJobConfig(ExportJobContainerJobConfig): |
---|
| 2774 | """Page that configures a students export job in datacenter. |
---|
| 2775 | |
---|
| 2776 | """ |
---|
| 2777 | grok.context(IDataCenter) |
---|
[9835] | 2778 | redirect_target = '@@export' |
---|
[9833] | 2779 | |
---|
| 2780 | class DepartmentExportJobContainerJobConfig(ExportJobContainerJobConfig): |
---|
| 2781 | """Page that configures a students export job in departments. |
---|
| 2782 | |
---|
| 2783 | """ |
---|
| 2784 | grok.context(VirtualDepartmentExportJobContainer) |
---|
| 2785 | |
---|
| 2786 | @property |
---|
| 2787 | def depcode(self): |
---|
[9835] | 2788 | return self.context.__parent__.code |
---|
[9842] | 2789 | |
---|
| 2790 | class CertificateExportJobContainerJobConfig(ExportJobContainerJobConfig): |
---|
| 2791 | """Page that configures a students export job for certificates. |
---|
| 2792 | |
---|
| 2793 | """ |
---|
| 2794 | grok.context(VirtualCertificateExportJobContainer) |
---|
[9843] | 2795 | grok.template('exportconfig_certificate') |
---|
[9842] | 2796 | |
---|
| 2797 | @property |
---|
| 2798 | def certcode(self): |
---|
| 2799 | return self.context.__parent__.code |
---|
[9843] | 2800 | |
---|
| 2801 | class CourseExportJobContainerJobConfig(ExportJobContainerJobConfig): |
---|
| 2802 | """Page that configures a students export job for courses. |
---|
| 2803 | |
---|
| 2804 | In contrast to department or certificate student data exports the |
---|
| 2805 | coursetickets_catalog is searched here. Therefore the update |
---|
| 2806 | method from the base class is customized. |
---|
| 2807 | """ |
---|
| 2808 | grok.context(VirtualCourseExportJobContainer) |
---|
| 2809 | grok.template('exportconfig_course') |
---|
| 2810 | |
---|
| 2811 | def _set_exporter_values(self): |
---|
[9844] | 2812 | # We provide only two exporters. |
---|
[9843] | 2813 | exporters = [] |
---|
[9844] | 2814 | for name in ('students', 'coursetickets'): |
---|
[9843] | 2815 | util = getUtility(ICSVExporter, name=name) |
---|
| 2816 | exporters.append((util.title, name),) |
---|
| 2817 | self.exporters = exporters |
---|
| 2818 | |
---|
| 2819 | def update(self, START=None, session=None, level=None, mode=None, |
---|
| 2820 | exporter=None): |
---|
| 2821 | self._set_session_values() |
---|
| 2822 | self._set_level_values() |
---|
| 2823 | self._set_mode_values() |
---|
| 2824 | self._set_exporter_values() |
---|
| 2825 | if START is None: |
---|
| 2826 | return |
---|
| 2827 | if session == 'all': |
---|
| 2828 | session=None |
---|
| 2829 | if level == 'all': |
---|
| 2830 | level = None |
---|
| 2831 | job_id = self.context.start_export_job(exporter, |
---|
| 2832 | self.request.principal.id, |
---|
| 2833 | # Use a different catalog and |
---|
| 2834 | # pass different keywords than |
---|
| 2835 | # for the (default) students_catalog |
---|
[9845] | 2836 | catalog='coursetickets', |
---|
[9843] | 2837 | session=session, |
---|
| 2838 | level=level, |
---|
| 2839 | code=self.context.__parent__.code) |
---|
| 2840 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 2841 | self.context.logger.info( |
---|
| 2842 | '%s - exported: %s (%s, %s, %s), job_id=%s' |
---|
| 2843 | % (ob_class, exporter, session, level, |
---|
| 2844 | self.context.__parent__.code, job_id)) |
---|
| 2845 | self.flash(_('Export started for course tickets with') + |
---|
| 2846 | ' level_session=%s, level=%s' % ( |
---|
| 2847 | session, level)) |
---|
| 2848 | self.redirect(self.url(self.redirect_target)) |
---|
| 2849 | return |
---|