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