[7191] | 1 | ## $Id: browser.py 9148 2012-09-03 14:47:24Z 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 |
---|
[8099] | 29 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
[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 |
---|
| 35 | from waeup.kofa.browser import ( |
---|
[7819] | 36 | KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage, |
---|
[7834] | 37 | ContactAdminForm, KofaForm, NullValidator) |
---|
[7811] | 38 | from waeup.kofa.browser.breadcrumbs import Breadcrumb |
---|
| 39 | from waeup.kofa.browser.resources import datepicker, datatable, tabs, warning |
---|
| 40 | from waeup.kofa.browser.layout import jsaction, action, UtilityView |
---|
[8779] | 41 | from waeup.kofa.browser.interfaces import ICaptchaManager |
---|
[7811] | 42 | from waeup.kofa.interfaces import ( |
---|
[7819] | 43 | IKofaObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm, |
---|
[9124] | 44 | IKofaUtils, IUniversity, IObjectHistory) |
---|
[7811] | 45 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[8170] | 46 | from waeup.kofa.widgets.datewidget import ( |
---|
| 47 | FriendlyDateWidget, FriendlyDateDisplayWidget, |
---|
| 48 | FriendlyDatetimeDisplayWidget) |
---|
[7868] | 49 | from waeup.kofa.widgets.restwidget import ReSTDisplayWidget |
---|
[7811] | 50 | from waeup.kofa.students.interfaces import ( |
---|
[7993] | 51 | IStudentsContainer, IStudent, |
---|
| 52 | IUGStudentClearance,IPGStudentClearance, |
---|
[6859] | 53 | IStudentPersonal, IStudentBase, IStudentStudyCourse, |
---|
[9138] | 54 | IStudentStudyCourseTransfer, |
---|
[7538] | 55 | IStudentAccommodation, IStudentStudyLevel, |
---|
[6877] | 56 | ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer, |
---|
[9148] | 57 | IStudentOnlinePayment, IStudentPreviousPayment, |
---|
| 58 | IBedTicket, IStudentsUtils, IStudentRequestPW |
---|
[6621] | 59 | ) |
---|
[7811] | 60 | from waeup.kofa.students.catalog import search |
---|
[8779] | 61 | from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID, |
---|
[9028] | 62 | CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED, |
---|
| 63 | FORBIDDEN_POSTGRAD_TRANS) |
---|
[7811] | 64 | from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket |
---|
| 65 | from waeup.kofa.students.vocabularies import StudyLevelSource |
---|
| 66 | from waeup.kofa.browser.resources import toggleall |
---|
| 67 | from waeup.kofa.hostels.hostel import NOT_OCCUPIED |
---|
[8737] | 68 | from waeup.kofa.utils.helpers import get_current_principal, to_timezone |
---|
[8857] | 69 | from waeup.kofa.mandates.mandate import PasswordMandate |
---|
[6621] | 70 | |
---|
[8779] | 71 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
| 72 | |
---|
[8737] | 73 | # Save function used for save methods in pages |
---|
| 74 | def msave(view, **data): |
---|
| 75 | changed_fields = view.applyData(view.context, **data) |
---|
| 76 | # Turn list of lists into single list |
---|
| 77 | if changed_fields: |
---|
| 78 | changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) |
---|
| 79 | # Inform catalog if certificate has changed |
---|
| 80 | # (applyData does this only for the context) |
---|
| 81 | if 'certificate' in changed_fields: |
---|
| 82 | notify(grok.ObjectModifiedEvent(view.context.student)) |
---|
| 83 | fields_string = ' + '.join(changed_fields) |
---|
| 84 | view.flash(_('Form has been saved.')) |
---|
| 85 | if fields_string: |
---|
| 86 | view.context.writeLogMessage(view, 'saved: %s' % fields_string) |
---|
| 87 | return |
---|
| 88 | |
---|
[7145] | 89 | def emit_lock_message(view): |
---|
[7642] | 90 | """Flash a lock message. |
---|
| 91 | """ |
---|
[7723] | 92 | view.flash(_('The requested form is locked (read-only).')) |
---|
[7133] | 93 | view.redirect(view.url(view.context)) |
---|
| 94 | return |
---|
| 95 | |
---|
[8921] | 96 | def translated_values(view): |
---|
| 97 | lang = view.request.cookies.get('kofa.language') |
---|
| 98 | for value in view.context.values(): |
---|
| 99 | value_dict = dict([i for i in value.__dict__.items()]) |
---|
| 100 | value_dict['mandatory_bool'] = value.mandatory |
---|
| 101 | value_dict['mandatory'] = translate(str(value.mandatory), 'zope', |
---|
| 102 | target_language=lang) |
---|
| 103 | value_dict['carry_over'] = translate(str(value.carry_over), 'zope', |
---|
| 104 | target_language=lang) |
---|
| 105 | value_dict['automatic'] = translate(str(value.automatic), 'zope', |
---|
| 106 | target_language=lang) |
---|
| 107 | yield value_dict |
---|
| 108 | |
---|
[6629] | 109 | class StudentsBreadcrumb(Breadcrumb): |
---|
| 110 | """A breadcrumb for the students container. |
---|
| 111 | """ |
---|
| 112 | grok.context(IStudentsContainer) |
---|
[7723] | 113 | title = _('Students') |
---|
[6629] | 114 | |
---|
[7459] | 115 | @property |
---|
| 116 | def target(self): |
---|
| 117 | user = get_current_principal() |
---|
| 118 | if getattr(user, 'user_type', None) == 'student': |
---|
| 119 | return None |
---|
| 120 | return self.viewname |
---|
| 121 | |
---|
[6818] | 122 | class StudentBreadcrumb(Breadcrumb): |
---|
| 123 | """A breadcrumb for the student container. |
---|
| 124 | """ |
---|
| 125 | grok.context(IStudent) |
---|
| 126 | |
---|
| 127 | def title(self): |
---|
[7364] | 128 | return self.context.display_fullname |
---|
[6818] | 129 | |
---|
[6635] | 130 | class SudyCourseBreadcrumb(Breadcrumb): |
---|
| 131 | """A breadcrumb for the student study course. |
---|
| 132 | """ |
---|
| 133 | grok.context(IStudentStudyCourse) |
---|
| 134 | |
---|
[9140] | 135 | def title(self): |
---|
| 136 | if self.context.is_current: |
---|
| 137 | return _('Study Course') |
---|
| 138 | else: |
---|
| 139 | return _('Previous Study Course') |
---|
| 140 | |
---|
[6635] | 141 | class PaymentsBreadcrumb(Breadcrumb): |
---|
| 142 | """A breadcrumb for the student payments folder. |
---|
| 143 | """ |
---|
[6859] | 144 | grok.context(IStudentPaymentsContainer) |
---|
[7723] | 145 | title = _('Payments') |
---|
[6635] | 146 | |
---|
[6870] | 147 | class OnlinePaymentBreadcrumb(Breadcrumb): |
---|
[7251] | 148 | """A breadcrumb for payments. |
---|
[6870] | 149 | """ |
---|
[6877] | 150 | grok.context(IStudentOnlinePayment) |
---|
[6870] | 151 | |
---|
| 152 | @property |
---|
| 153 | def title(self): |
---|
| 154 | return self.context.p_id |
---|
| 155 | |
---|
[6635] | 156 | class AccommodationBreadcrumb(Breadcrumb): |
---|
| 157 | """A breadcrumb for the student accommodation folder. |
---|
| 158 | """ |
---|
| 159 | grok.context(IStudentAccommodation) |
---|
[7723] | 160 | title = _('Accommodation') |
---|
[6635] | 161 | |
---|
[6994] | 162 | class BedTicketBreadcrumb(Breadcrumb): |
---|
| 163 | """A breadcrumb for bed tickets. |
---|
| 164 | """ |
---|
| 165 | grok.context(IBedTicket) |
---|
[7009] | 166 | |
---|
[6994] | 167 | @property |
---|
| 168 | def title(self): |
---|
[7723] | 169 | return _('Bed Ticket ${a}', |
---|
| 170 | mapping = {'a':self.context.getSessionString()}) |
---|
[6994] | 171 | |
---|
[6776] | 172 | class StudyLevelBreadcrumb(Breadcrumb): |
---|
| 173 | """A breadcrumb for course lists. |
---|
| 174 | """ |
---|
| 175 | grok.context(IStudentStudyLevel) |
---|
| 176 | |
---|
| 177 | @property |
---|
| 178 | def title(self): |
---|
[7834] | 179 | return self.context.level_title |
---|
[6776] | 180 | |
---|
[7819] | 181 | class StudentsContainerPage(KofaPage): |
---|
[6626] | 182 | """The standard view for student containers. |
---|
[6621] | 183 | """ |
---|
| 184 | grok.context(IStudentsContainer) |
---|
| 185 | grok.name('index') |
---|
[7240] | 186 | grok.require('waeup.viewStudentsContainer') |
---|
[6695] | 187 | grok.template('containerpage') |
---|
[7723] | 188 | label = _('Student Section') |
---|
[7735] | 189 | search_button = _('Search') |
---|
[6642] | 190 | pnav = 4 |
---|
[6621] | 191 | |
---|
[6626] | 192 | def update(self, *args, **kw): |
---|
| 193 | datatable.need() |
---|
| 194 | form = self.request.form |
---|
| 195 | self.hitlist = [] |
---|
| 196 | if 'searchterm' in form and form['searchterm']: |
---|
| 197 | self.searchterm = form['searchterm'] |
---|
| 198 | self.searchtype = form['searchtype'] |
---|
| 199 | elif 'old_searchterm' in form: |
---|
| 200 | self.searchterm = form['old_searchterm'] |
---|
| 201 | self.searchtype = form['old_searchtype'] |
---|
| 202 | else: |
---|
| 203 | if 'search' in form: |
---|
[7745] | 204 | self.flash(_('Empty search string')) |
---|
[6626] | 205 | return |
---|
[7068] | 206 | if self.searchtype == 'current_session': |
---|
[8081] | 207 | try: |
---|
| 208 | self.searchterm = int(self.searchterm) |
---|
| 209 | except ValueError: |
---|
[8404] | 210 | self.flash(_('Only year dates allowed (e.g. 2011).')) |
---|
[8081] | 211 | return |
---|
[6626] | 212 | self.hitlist = search(query=self.searchterm, |
---|
| 213 | searchtype=self.searchtype, view=self) |
---|
| 214 | if not self.hitlist: |
---|
[8404] | 215 | self.flash(_('No student found.')) |
---|
[6626] | 216 | return |
---|
| 217 | |
---|
[7819] | 218 | class StudentsContainerManagePage(KofaPage): |
---|
[6626] | 219 | """The manage page for student containers. |
---|
[6622] | 220 | """ |
---|
| 221 | grok.context(IStudentsContainer) |
---|
| 222 | grok.name('manage') |
---|
[7136] | 223 | grok.require('waeup.manageStudent') |
---|
[6695] | 224 | grok.template('containermanagepage') |
---|
[6642] | 225 | pnav = 4 |
---|
[7723] | 226 | label = _('Manage student section') |
---|
[7735] | 227 | search_button = _('Search') |
---|
| 228 | remove_button = _('Remove selected') |
---|
[6622] | 229 | |
---|
[6626] | 230 | def update(self, *args, **kw): |
---|
| 231 | datatable.need() |
---|
[6820] | 232 | toggleall.need() |
---|
[7329] | 233 | warning.need() |
---|
[6626] | 234 | form = self.request.form |
---|
| 235 | self.hitlist = [] |
---|
| 236 | if 'searchterm' in form and form['searchterm']: |
---|
| 237 | self.searchterm = form['searchterm'] |
---|
| 238 | self.searchtype = form['searchtype'] |
---|
| 239 | elif 'old_searchterm' in form: |
---|
| 240 | self.searchterm = form['old_searchterm'] |
---|
| 241 | self.searchtype = form['old_searchtype'] |
---|
| 242 | else: |
---|
| 243 | if 'search' in form: |
---|
[7745] | 244 | self.flash(_('Empty search string')) |
---|
[6626] | 245 | return |
---|
[8082] | 246 | if self.searchtype == 'current_session': |
---|
| 247 | try: |
---|
| 248 | self.searchterm = int(self.searchterm) |
---|
| 249 | except ValueError: |
---|
| 250 | self.flash('Only year dates allowed (e.g. 2011).') |
---|
| 251 | return |
---|
[6626] | 252 | if not 'entries' in form: |
---|
| 253 | self.hitlist = search(query=self.searchterm, |
---|
| 254 | searchtype=self.searchtype, view=self) |
---|
| 255 | if not self.hitlist: |
---|
[7723] | 256 | self.flash(_('No student found.')) |
---|
[7459] | 257 | if 'remove' in form: |
---|
[7723] | 258 | self.flash(_('No item selected.')) |
---|
[6626] | 259 | return |
---|
| 260 | entries = form['entries'] |
---|
| 261 | if isinstance(entries, basestring): |
---|
| 262 | entries = [entries] |
---|
| 263 | deleted = [] |
---|
| 264 | for entry in entries: |
---|
| 265 | if 'remove' in form: |
---|
| 266 | del self.context[entry] |
---|
| 267 | deleted.append(entry) |
---|
| 268 | self.hitlist = search(query=self.searchterm, |
---|
| 269 | searchtype=self.searchtype, view=self) |
---|
| 270 | if len(deleted): |
---|
[7723] | 271 | self.flash(_('Successfully removed: ${a}', |
---|
| 272 | mapping = {'a':', '.join(deleted)})) |
---|
[6622] | 273 | return |
---|
| 274 | |
---|
[7819] | 275 | class StudentAddFormPage(KofaAddFormPage): |
---|
[6622] | 276 | """Add-form to add a student. |
---|
| 277 | """ |
---|
| 278 | grok.context(IStudentsContainer) |
---|
[7136] | 279 | grok.require('waeup.manageStudent') |
---|
[6622] | 280 | grok.name('addstudent') |
---|
[7357] | 281 | form_fields = grok.AutoFields(IStudent).select( |
---|
[7520] | 282 | 'firstname', 'middlename', 'lastname', 'reg_number') |
---|
[7723] | 283 | label = _('Add student') |
---|
[6642] | 284 | pnav = 4 |
---|
[6622] | 285 | |
---|
[7723] | 286 | @action(_('Create student record'), style='primary') |
---|
[6622] | 287 | def addStudent(self, **data): |
---|
| 288 | student = createObject(u'waeup.Student') |
---|
| 289 | self.applyData(student, **data) |
---|
[6652] | 290 | self.context.addStudent(student) |
---|
[7723] | 291 | self.flash(_('Student record created.')) |
---|
[6651] | 292 | self.redirect(self.url(self.context[student.student_id], 'index')) |
---|
[6622] | 293 | return |
---|
| 294 | |
---|
[7819] | 295 | class StudentBaseDisplayFormPage(KofaDisplayFormPage): |
---|
[6631] | 296 | """ Page to display student base data |
---|
| 297 | """ |
---|
[6622] | 298 | grok.context(IStudent) |
---|
| 299 | grok.name('index') |
---|
[6660] | 300 | grok.require('waeup.viewStudent') |
---|
[6695] | 301 | grok.template('basepage') |
---|
[8983] | 302 | form_fields = grok.AutoFields(IStudentBase).omit('password', 'suspended') |
---|
[6642] | 303 | pnav = 4 |
---|
[6622] | 304 | |
---|
| 305 | @property |
---|
| 306 | def label(self): |
---|
[8983] | 307 | if self.context.suspended: |
---|
[9124] | 308 | return _('${a}: Base Data (account deactivated)', |
---|
[8983] | 309 | mapping = {'a':self.context.display_fullname}) |
---|
| 310 | return _('${a}: Base Data', |
---|
[7723] | 311 | mapping = {'a':self.context.display_fullname}) |
---|
[6631] | 312 | |
---|
[6699] | 313 | @property |
---|
| 314 | def hasPassword(self): |
---|
| 315 | if self.context.password: |
---|
[7723] | 316 | return _('set') |
---|
| 317 | return _('unset') |
---|
[6699] | 318 | |
---|
[9141] | 319 | class StudentBasePDFFormPage(KofaDisplayFormPage): |
---|
| 320 | """ Page to display student base data in pdf files. |
---|
| 321 | """ |
---|
| 322 | form_fields = grok.AutoFields(IStudentBase).omit( |
---|
| 323 | 'password', 'suspended', 'phone', 'adm_code', 'sex') |
---|
| 324 | |
---|
[7229] | 325 | class ContactStudentForm(ContactAdminForm): |
---|
| 326 | grok.context(IStudent) |
---|
[7230] | 327 | grok.name('contactstudent') |
---|
[7275] | 328 | grok.require('waeup.viewStudent') |
---|
[7229] | 329 | pnav = 4 |
---|
| 330 | form_fields = grok.AutoFields(IContactForm).select('subject', 'body') |
---|
| 331 | |
---|
[7275] | 332 | def update(self, subject=u''): |
---|
| 333 | self.form_fields.get('subject').field.default = subject |
---|
| 334 | self.subject = subject |
---|
| 335 | return |
---|
| 336 | |
---|
[7229] | 337 | def label(self): |
---|
[7723] | 338 | return _(u'Send message to ${a}', |
---|
| 339 | mapping = {'a':self.context.display_fullname}) |
---|
[7229] | 340 | |
---|
[7459] | 341 | @action('Send message now', style='primary') |
---|
[7229] | 342 | def send(self, *args, **data): |
---|
[7234] | 343 | try: |
---|
[7403] | 344 | email = self.request.principal.email |
---|
[7234] | 345 | except AttributeError: |
---|
[7403] | 346 | email = self.config.email_admin |
---|
| 347 | usertype = getattr(self.request.principal, |
---|
| 348 | 'user_type', 'system').title() |
---|
[7819] | 349 | kofa_utils = getUtility(IKofaUtils) |
---|
[7811] | 350 | success = kofa_utils.sendContactForm( |
---|
[7403] | 351 | self.request.principal.title,email, |
---|
| 352 | self.context.display_fullname,self.context.email, |
---|
| 353 | self.request.principal.id,usertype, |
---|
| 354 | self.config.name, |
---|
| 355 | data['body'],data['subject']) |
---|
[7229] | 356 | if success: |
---|
[7723] | 357 | self.flash(_('Your message has been sent.')) |
---|
[7229] | 358 | else: |
---|
[7723] | 359 | self.flash(_('An smtp server error occurred.')) |
---|
[7229] | 360 | return |
---|
| 361 | |
---|
[7819] | 362 | class StudentBaseManageFormPage(KofaEditFormPage): |
---|
[7133] | 363 | """ View to manage student base data |
---|
[6631] | 364 | """ |
---|
| 365 | grok.context(IStudent) |
---|
[7133] | 366 | grok.name('manage_base') |
---|
[7136] | 367 | grok.require('waeup.manageStudent') |
---|
[9124] | 368 | form_fields = grok.AutoFields(IStudentBase).omit( |
---|
| 369 | 'student_id', 'adm_code', 'suspended') |
---|
[6695] | 370 | grok.template('basemanagepage') |
---|
[7723] | 371 | label = _('Manage base data') |
---|
[6642] | 372 | pnav = 4 |
---|
[6631] | 373 | |
---|
[6638] | 374 | def update(self): |
---|
| 375 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
[7134] | 376 | tabs.need() |
---|
[7490] | 377 | self.tab1 = self.tab2 = '' |
---|
| 378 | qs = self.request.get('QUERY_STRING', '') |
---|
| 379 | if not qs: |
---|
| 380 | qs = 'tab1' |
---|
| 381 | setattr(self, qs, 'active') |
---|
[6638] | 382 | super(StudentBaseManageFormPage, self).update() |
---|
| 383 | self.wf_info = IWorkflowInfo(self.context) |
---|
| 384 | return |
---|
| 385 | |
---|
| 386 | def getTransitions(self): |
---|
| 387 | """Return a list of dicts of allowed transition ids and titles. |
---|
| 388 | |
---|
| 389 | Each list entry provides keys ``name`` and ``title`` for |
---|
| 390 | internal name and (human readable) title of a single |
---|
| 391 | transition. |
---|
| 392 | """ |
---|
[8434] | 393 | allowed_transitions = [t for t in self.wf_info.getManualTransitions() |
---|
| 394 | if not t[0].startswith('pay')] |
---|
[9028] | 395 | if self.context.is_postgrad: |
---|
| 396 | allowed_transitions = [t for t in allowed_transitions |
---|
| 397 | if not t[0] in FORBIDDEN_POSTGRAD_TRANS] |
---|
[7687] | 398 | return [dict(name='', title=_('No transition'))] +[ |
---|
[6638] | 399 | dict(name=x, title=y) for x, y in allowed_transitions] |
---|
| 400 | |
---|
[7723] | 401 | @action(_('Save'), style='primary') |
---|
[6638] | 402 | def save(self, **data): |
---|
[6701] | 403 | form = self.request.form |
---|
[6790] | 404 | password = form.get('password', None) |
---|
| 405 | password_ctl = form.get('control_password', None) |
---|
| 406 | if password: |
---|
[7147] | 407 | validator = getUtility(IPasswordValidator) |
---|
| 408 | errors = validator.validate_password(password, password_ctl) |
---|
| 409 | if errors: |
---|
| 410 | self.flash( ' '.join(errors)) |
---|
| 411 | return |
---|
| 412 | changed_fields = self.applyData(self.context, **data) |
---|
[6771] | 413 | # Turn list of lists into single list |
---|
| 414 | if changed_fields: |
---|
| 415 | changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) |
---|
[7147] | 416 | else: |
---|
| 417 | changed_fields = [] |
---|
| 418 | if password: |
---|
| 419 | # Now we know that the form has no errors and can set password ... |
---|
| 420 | IUserAccount(self.context).setPassword(password) |
---|
| 421 | changed_fields.append('password') |
---|
| 422 | # ... and execute transition |
---|
[6638] | 423 | if form.has_key('transition') and form['transition']: |
---|
| 424 | transition_id = form['transition'] |
---|
| 425 | self.wf_info.fireTransition(transition_id) |
---|
[7147] | 426 | fields_string = ' + '.join(changed_fields) |
---|
[7723] | 427 | self.flash(_('Form has been saved.')) |
---|
[6644] | 428 | if fields_string: |
---|
[8735] | 429 | self.context.writeLogMessage(self, 'saved: % s' % fields_string) |
---|
[6638] | 430 | return |
---|
| 431 | |
---|
[9124] | 432 | class StudentActivatePage(UtilityView, grok.View): |
---|
| 433 | """ Activate student account |
---|
| 434 | """ |
---|
| 435 | grok.context(IStudent) |
---|
| 436 | grok.name('activate') |
---|
| 437 | grok.require('waeup.manageStudent') |
---|
| 438 | |
---|
| 439 | def update(self): |
---|
| 440 | self.context.suspended = False |
---|
| 441 | self.context.writeLogMessage(self, 'account activated') |
---|
| 442 | history = IObjectHistory(self.context) |
---|
| 443 | history.addMessage('Student account activated') |
---|
| 444 | self.flash(_('Student account has been activated.')) |
---|
| 445 | self.redirect(self.url(self.context)) |
---|
| 446 | return |
---|
| 447 | |
---|
| 448 | def render(self): |
---|
| 449 | return |
---|
| 450 | |
---|
| 451 | class StudentDeactivatePage(UtilityView, grok.View): |
---|
| 452 | """ Deactivate student account |
---|
| 453 | """ |
---|
| 454 | grok.context(IStudent) |
---|
| 455 | grok.name('deactivate') |
---|
| 456 | grok.require('waeup.manageStudent') |
---|
| 457 | |
---|
| 458 | def update(self): |
---|
| 459 | self.context.suspended = True |
---|
| 460 | self.context.writeLogMessage(self, 'account deactivated') |
---|
| 461 | history = IObjectHistory(self.context) |
---|
| 462 | history.addMessage('Student account deactivated') |
---|
| 463 | self.flash(_('Student account has been deactivated.')) |
---|
| 464 | self.redirect(self.url(self.context)) |
---|
| 465 | return |
---|
| 466 | |
---|
| 467 | def render(self): |
---|
| 468 | return |
---|
| 469 | |
---|
[7819] | 470 | class StudentClearanceDisplayFormPage(KofaDisplayFormPage): |
---|
[6631] | 471 | """ Page to display student clearance data |
---|
| 472 | """ |
---|
| 473 | grok.context(IStudent) |
---|
| 474 | grok.name('view_clearance') |
---|
[6660] | 475 | grok.require('waeup.viewStudent') |
---|
[6642] | 476 | pnav = 4 |
---|
[6631] | 477 | |
---|
| 478 | @property |
---|
[8099] | 479 | def separators(self): |
---|
| 480 | return getUtility(IStudentsUtils).SEPARATORS_DICT |
---|
| 481 | |
---|
| 482 | @property |
---|
[7993] | 483 | def form_fields(self): |
---|
[8472] | 484 | if self.context.is_postgrad: |
---|
[8977] | 485 | form_fields = grok.AutoFields( |
---|
| 486 | IPGStudentClearance).omit('clearance_locked') |
---|
[7993] | 487 | else: |
---|
[8977] | 488 | form_fields = grok.AutoFields( |
---|
| 489 | IUGStudentClearance).omit('clearance_locked') |
---|
[7993] | 490 | return form_fields |
---|
| 491 | |
---|
| 492 | @property |
---|
[6631] | 493 | def label(self): |
---|
[7723] | 494 | return _('${a}: Clearance Data', |
---|
| 495 | mapping = {'a':self.context.display_fullname}) |
---|
[6631] | 496 | |
---|
[7277] | 497 | class ExportPDFClearanceSlipPage(grok.View): |
---|
| 498 | """Deliver a PDF slip of the context. |
---|
| 499 | """ |
---|
| 500 | grok.context(IStudent) |
---|
| 501 | grok.name('clearance.pdf') |
---|
| 502 | grok.require('waeup.viewStudent') |
---|
| 503 | prefix = 'form' |
---|
| 504 | |
---|
| 505 | @property |
---|
[7993] | 506 | def form_fields(self): |
---|
[8472] | 507 | if self.context.is_postgrad: |
---|
[8977] | 508 | form_fields = grok.AutoFields( |
---|
| 509 | IPGStudentClearance).omit('clearance_locked') |
---|
[7993] | 510 | else: |
---|
[8977] | 511 | form_fields = grok.AutoFields( |
---|
| 512 | IUGStudentClearance).omit('clearance_locked') |
---|
[7993] | 513 | return form_fields |
---|
| 514 | |
---|
| 515 | @property |
---|
[7723] | 516 | def title(self): |
---|
[7819] | 517 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 518 | return translate(_('Clearance Data'), 'waeup.kofa', |
---|
[7723] | 519 | target_language=portal_language) |
---|
| 520 | |
---|
| 521 | @property |
---|
[7277] | 522 | def label(self): |
---|
[7819] | 523 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9026] | 524 | return translate(_('Clearance Slip of'), |
---|
[7811] | 525 | 'waeup.kofa', target_language=portal_language) \ |
---|
[7723] | 526 | + ' %s' % self.context.display_fullname |
---|
[7277] | 527 | |
---|
[9010] | 528 | def _signatures(self): |
---|
| 529 | if self.context.state == CLEARED: |
---|
| 530 | return (_('Student Signature'), _('Clearance Officer Signature')) |
---|
| 531 | return |
---|
| 532 | |
---|
[7277] | 533 | def render(self): |
---|
[9141] | 534 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[7277] | 535 | self.request) |
---|
| 536 | students_utils = getUtility(IStudentsUtils) |
---|
| 537 | return students_utils.renderPDF( |
---|
[7318] | 538 | self, 'clearance.pdf', |
---|
[9010] | 539 | self.context.student, studentview, signatures=self._signatures()) |
---|
[7277] | 540 | |
---|
[7819] | 541 | class StudentClearanceManageFormPage(KofaEditFormPage): |
---|
[8120] | 542 | """ Page to manage student clearance data |
---|
[6631] | 543 | """ |
---|
| 544 | grok.context(IStudent) |
---|
[8119] | 545 | grok.name('manage_clearance') |
---|
[7136] | 546 | grok.require('waeup.manageStudent') |
---|
[7134] | 547 | grok.template('clearanceeditpage') |
---|
[7723] | 548 | label = _('Manage clearance data') |
---|
[6642] | 549 | pnav = 4 |
---|
[6650] | 550 | |
---|
[7993] | 551 | @property |
---|
[8099] | 552 | def separators(self): |
---|
| 553 | return getUtility(IStudentsUtils).SEPARATORS_DICT |
---|
| 554 | |
---|
| 555 | @property |
---|
[7993] | 556 | def form_fields(self): |
---|
[8472] | 557 | if self.context.is_postgrad: |
---|
[8977] | 558 | form_fields = grok.AutoFields(IPGStudentClearance).omit('clr_code') |
---|
[7993] | 559 | else: |
---|
[8977] | 560 | form_fields = grok.AutoFields(IUGStudentClearance).omit('clr_code') |
---|
[7993] | 561 | return form_fields |
---|
| 562 | |
---|
[6650] | 563 | def update(self): |
---|
| 564 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
[7134] | 565 | tabs.need() |
---|
[7490] | 566 | self.tab1 = self.tab2 = '' |
---|
| 567 | qs = self.request.get('QUERY_STRING', '') |
---|
| 568 | if not qs: |
---|
| 569 | qs = 'tab1' |
---|
| 570 | setattr(self, qs, 'active') |
---|
[6650] | 571 | return super(StudentClearanceManageFormPage, self).update() |
---|
| 572 | |
---|
[7723] | 573 | @action(_('Save'), style='primary') |
---|
[6695] | 574 | def save(self, **data): |
---|
[6762] | 575 | msave(self, **data) |
---|
[6695] | 576 | return |
---|
| 577 | |
---|
[7459] | 578 | class StudentClearPage(UtilityView, grok.View): |
---|
[7158] | 579 | """ Clear student by clearance officer |
---|
| 580 | """ |
---|
| 581 | grok.context(IStudent) |
---|
| 582 | grok.name('clear') |
---|
| 583 | grok.require('waeup.clearStudent') |
---|
| 584 | |
---|
| 585 | def update(self): |
---|
| 586 | if self.context.state == REQUESTED: |
---|
| 587 | IWorkflowInfo(self.context).fireTransition('clear') |
---|
[7723] | 588 | self.flash(_('Student has been cleared.')) |
---|
[7158] | 589 | else: |
---|
[7723] | 590 | self.flash(_('Student is in wrong state.')) |
---|
[7158] | 591 | self.redirect(self.url(self.context,'view_clearance')) |
---|
| 592 | return |
---|
| 593 | |
---|
| 594 | def render(self): |
---|
| 595 | return |
---|
| 596 | |
---|
[7459] | 597 | class StudentRejectClearancePage(UtilityView, grok.View): |
---|
[7158] | 598 | """ Reject clearance by clearance officers |
---|
| 599 | """ |
---|
| 600 | grok.context(IStudent) |
---|
| 601 | grok.name('reject_clearance') |
---|
| 602 | grok.require('waeup.clearStudent') |
---|
| 603 | |
---|
| 604 | def update(self): |
---|
| 605 | if self.context.state == CLEARED: |
---|
| 606 | IWorkflowInfo(self.context).fireTransition('reset4') |
---|
[7723] | 607 | message = _('Clearance has been annulled.') |
---|
[7275] | 608 | self.flash(message) |
---|
[7158] | 609 | elif self.context.state == REQUESTED: |
---|
| 610 | IWorkflowInfo(self.context).fireTransition('reset3') |
---|
[7723] | 611 | message = _('Clearance request has been rejected.') |
---|
[7275] | 612 | self.flash(message) |
---|
[7158] | 613 | else: |
---|
[7723] | 614 | self.flash(_('Student is in wrong state.')) |
---|
[7334] | 615 | self.redirect(self.url(self.context,'view_clearance')) |
---|
[7275] | 616 | return |
---|
| 617 | args = {'subject':message} |
---|
| 618 | self.redirect(self.url(self.context) + |
---|
| 619 | '/contactstudent?%s' % urlencode(args)) |
---|
[7158] | 620 | return |
---|
| 621 | |
---|
| 622 | def render(self): |
---|
| 623 | return |
---|
| 624 | |
---|
[7819] | 625 | class StudentPersonalDisplayFormPage(KofaDisplayFormPage): |
---|
[6631] | 626 | """ Page to display student personal data |
---|
| 627 | """ |
---|
| 628 | grok.context(IStudent) |
---|
| 629 | grok.name('view_personal') |
---|
[6660] | 630 | grok.require('waeup.viewStudent') |
---|
[6631] | 631 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
[7386] | 632 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
[6642] | 633 | pnav = 4 |
---|
[6631] | 634 | |
---|
| 635 | @property |
---|
| 636 | def label(self): |
---|
[7723] | 637 | return _('${a}: Personal Data', |
---|
| 638 | mapping = {'a':self.context.display_fullname}) |
---|
[6631] | 639 | |
---|
[8903] | 640 | class StudentPersonalManageFormPage(KofaEditFormPage): |
---|
| 641 | """ Page to manage personal data |
---|
[6631] | 642 | """ |
---|
| 643 | grok.context(IStudent) |
---|
[8903] | 644 | grok.name('manage_personal') |
---|
| 645 | grok.require('waeup.manageStudent') |
---|
[6631] | 646 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
[8903] | 647 | label = _('Manage personal data') |
---|
[6642] | 648 | pnav = 4 |
---|
[6631] | 649 | |
---|
[7723] | 650 | @action(_('Save'), style='primary') |
---|
[6762] | 651 | def save(self, **data): |
---|
| 652 | msave(self, **data) |
---|
| 653 | return |
---|
| 654 | |
---|
[8903] | 655 | class StudentPersonalEditFormPage(StudentPersonalManageFormPage): |
---|
| 656 | """ Page to edit personal data |
---|
| 657 | """ |
---|
| 658 | grok.name('edit_personal') |
---|
| 659 | grok.require('waeup.handleStudent') |
---|
| 660 | label = _('Edit personal data') |
---|
| 661 | pnav = 4 |
---|
| 662 | |
---|
[7819] | 663 | class StudyCourseDisplayFormPage(KofaDisplayFormPage): |
---|
[6635] | 664 | """ Page to display the student study course data |
---|
| 665 | """ |
---|
| 666 | grok.context(IStudentStudyCourse) |
---|
| 667 | grok.name('index') |
---|
[6660] | 668 | grok.require('waeup.viewStudent') |
---|
[6775] | 669 | grok.template('studycoursepage') |
---|
[6642] | 670 | pnav = 4 |
---|
[6635] | 671 | |
---|
| 672 | @property |
---|
[8972] | 673 | def form_fields(self): |
---|
| 674 | if self.context.is_postgrad: |
---|
| 675 | form_fields = grok.AutoFields(IStudentStudyCourse).omit( |
---|
| 676 | 'current_verdict', 'previous_verdict') |
---|
| 677 | else: |
---|
| 678 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 679 | return form_fields |
---|
| 680 | |
---|
| 681 | @property |
---|
[6635] | 682 | def label(self): |
---|
[9140] | 683 | if self.context.is_current: |
---|
| 684 | return _('${a}: Study Course', |
---|
| 685 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
| 686 | else: |
---|
| 687 | return _('${a}: Previous Study Course', |
---|
| 688 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
[6635] | 689 | |
---|
[6912] | 690 | @property |
---|
| 691 | def current_mode(self): |
---|
[7641] | 692 | if self.context.certificate is not None: |
---|
[7841] | 693 | studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
---|
[7681] | 694 | return studymodes_dict[self.context.certificate.study_mode] |
---|
[7171] | 695 | return |
---|
[7642] | 696 | |
---|
[7171] | 697 | @property |
---|
| 698 | def department(self): |
---|
[7205] | 699 | if self.context.certificate is not None: |
---|
[7171] | 700 | return self.context.certificate.__parent__.__parent__ |
---|
| 701 | return |
---|
[6912] | 702 | |
---|
[7171] | 703 | @property |
---|
| 704 | def faculty(self): |
---|
[7205] | 705 | if self.context.certificate is not None: |
---|
[7171] | 706 | return self.context.certificate.__parent__.__parent__.__parent__ |
---|
| 707 | return |
---|
| 708 | |
---|
[9140] | 709 | @property |
---|
| 710 | def prev_studycourses(self): |
---|
| 711 | if self.context.is_current: |
---|
| 712 | if self.context.__parent__.get('studycourse_2', None) is not None: |
---|
| 713 | return ( |
---|
| 714 | {'href':self.url(self.context.student) + '/studycourse_1', |
---|
| 715 | 'title':_('First Study Course, ')}, |
---|
| 716 | {'href':self.url(self.context.student) + '/studycourse_2', |
---|
| 717 | 'title':_('Second Study Course')} |
---|
| 718 | ) |
---|
| 719 | if self.context.__parent__.get('studycourse_1', None) is not None: |
---|
| 720 | return ( |
---|
| 721 | {'href':self.url(self.context.student) + '/studycourse_1', |
---|
| 722 | 'title':_('First Study Course')}, |
---|
| 723 | ) |
---|
| 724 | return |
---|
| 725 | |
---|
[7819] | 726 | class StudyCourseManageFormPage(KofaEditFormPage): |
---|
[6649] | 727 | """ Page to edit the student study course data |
---|
| 728 | """ |
---|
| 729 | grok.context(IStudentStudyCourse) |
---|
[6775] | 730 | grok.name('manage') |
---|
[7136] | 731 | grok.require('waeup.manageStudent') |
---|
[6775] | 732 | grok.template('studycoursemanagepage') |
---|
[7723] | 733 | label = _('Manage study course') |
---|
[6649] | 734 | pnav = 4 |
---|
[7723] | 735 | taboneactions = [_('Save'),_('Cancel')] |
---|
| 736 | tabtwoactions = [_('Remove selected levels'),_('Cancel')] |
---|
| 737 | tabthreeactions = [_('Add study level')] |
---|
[6649] | 738 | |
---|
[8972] | 739 | @property |
---|
| 740 | def form_fields(self): |
---|
| 741 | if self.context.is_postgrad: |
---|
| 742 | form_fields = grok.AutoFields(IStudentStudyCourse).omit( |
---|
| 743 | 'current_verdict', 'previous_verdict') |
---|
| 744 | else: |
---|
| 745 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 746 | return form_fields |
---|
| 747 | |
---|
[6775] | 748 | def update(self): |
---|
[9139] | 749 | if not self.context.is_current: |
---|
| 750 | emit_lock_message(self) |
---|
| 751 | return |
---|
[6775] | 752 | super(StudyCourseManageFormPage, self).update() |
---|
| 753 | tabs.need() |
---|
[7484] | 754 | self.tab1 = self.tab2 = '' |
---|
| 755 | qs = self.request.get('QUERY_STRING', '') |
---|
| 756 | if not qs: |
---|
| 757 | qs = 'tab1' |
---|
| 758 | setattr(self, qs, 'active') |
---|
[7490] | 759 | warning.need() |
---|
| 760 | datatable.need() |
---|
| 761 | return |
---|
[6775] | 762 | |
---|
[7723] | 763 | @action(_('Save'), style='primary') |
---|
[6761] | 764 | def save(self, **data): |
---|
[8099] | 765 | try: |
---|
| 766 | msave(self, **data) |
---|
| 767 | except ConstraintNotSatisfied: |
---|
| 768 | # The selected level might not exist in certificate |
---|
| 769 | self.flash(_('Current level not available for certificate.')) |
---|
| 770 | return |
---|
[8081] | 771 | notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
---|
[6761] | 772 | return |
---|
| 773 | |
---|
[6775] | 774 | @property |
---|
| 775 | def level_dict(self): |
---|
| 776 | studylevelsource = StudyLevelSource().factory |
---|
| 777 | for code in studylevelsource.getValues(self.context): |
---|
| 778 | title = studylevelsource.getTitle(self.context, code) |
---|
| 779 | yield(dict(code=code, title=title)) |
---|
| 780 | |
---|
[7723] | 781 | @action(_('Add study level')) |
---|
[6774] | 782 | def addStudyLevel(self, **data): |
---|
[6775] | 783 | level_code = self.request.form.get('addlevel', None) |
---|
[8323] | 784 | studylevel = createObject(u'waeup.StudentStudyLevel') |
---|
[6775] | 785 | studylevel.level = int(level_code) |
---|
| 786 | try: |
---|
[6782] | 787 | self.context.addStudentStudyLevel( |
---|
| 788 | self.context.certificate,studylevel) |
---|
[7723] | 789 | self.flash(_('Study level has been added.')) |
---|
[6775] | 790 | except KeyError: |
---|
[7723] | 791 | self.flash(_('This level exists.')) |
---|
[7484] | 792 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6774] | 793 | return |
---|
| 794 | |
---|
[7723] | 795 | @jsaction(_('Remove selected levels')) |
---|
[6775] | 796 | def delStudyLevels(self, **data): |
---|
| 797 | form = self.request.form |
---|
| 798 | if form.has_key('val_id'): |
---|
| 799 | child_id = form['val_id'] |
---|
| 800 | else: |
---|
[7723] | 801 | self.flash(_('No study level selected.')) |
---|
[7484] | 802 | self.redirect(self.url(self.context, '@@manage')+'?tab2') |
---|
[6775] | 803 | return |
---|
| 804 | if not isinstance(child_id, list): |
---|
| 805 | child_id = [child_id] |
---|
| 806 | deleted = [] |
---|
| 807 | for id in child_id: |
---|
[7723] | 808 | del self.context[id] |
---|
| 809 | deleted.append(id) |
---|
[6775] | 810 | if len(deleted): |
---|
[7723] | 811 | self.flash(_('Successfully removed: ${a}', |
---|
| 812 | mapping = {'a':', '.join(deleted)})) |
---|
[7484] | 813 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6775] | 814 | return |
---|
[6774] | 815 | |
---|
[9138] | 816 | class StudentTransferFormPage(KofaAddFormPage): |
---|
| 817 | """Page to transfer the student. |
---|
| 818 | """ |
---|
| 819 | grok.context(IStudent) |
---|
| 820 | grok.name('transfer') |
---|
| 821 | grok.require('waeup.manageStudent') |
---|
| 822 | label = _('Transfer student') |
---|
| 823 | form_fields = grok.AutoFields(IStudentStudyCourseTransfer).omit( |
---|
| 824 | 'entry_mode', 'entry_session') |
---|
| 825 | pnav = 4 |
---|
| 826 | |
---|
| 827 | def update(self): |
---|
| 828 | super(StudentTransferFormPage, self).update() |
---|
| 829 | warning.need() |
---|
| 830 | return |
---|
| 831 | |
---|
| 832 | @jsaction(_('Transfer')) |
---|
| 833 | def transferStudent(self, **data): |
---|
| 834 | error = self.context.transfer(**data) |
---|
| 835 | if error == -1: |
---|
| 836 | self.flash(_('Current level does not match certificate levels.')) |
---|
| 837 | elif error == -2: |
---|
| 838 | self.flash(_('Former study course record incomplete.')) |
---|
| 839 | elif error == -3: |
---|
| 840 | self.flash(_('Maximum number of transfers exceeded.')) |
---|
| 841 | else: |
---|
| 842 | self.flash(_('Successfully transferred.')) |
---|
| 843 | return |
---|
| 844 | |
---|
[7819] | 845 | class StudyLevelDisplayFormPage(KofaDisplayFormPage): |
---|
[6774] | 846 | """ Page to display student study levels |
---|
| 847 | """ |
---|
| 848 | grok.context(IStudentStudyLevel) |
---|
| 849 | grok.name('index') |
---|
| 850 | grok.require('waeup.viewStudent') |
---|
[6775] | 851 | form_fields = grok.AutoFields(IStudentStudyLevel) |
---|
[6783] | 852 | grok.template('studylevelpage') |
---|
[6774] | 853 | pnav = 4 |
---|
| 854 | |
---|
[7310] | 855 | def update(self): |
---|
| 856 | super(StudyLevelDisplayFormPage, self).update() |
---|
| 857 | datatable.need() |
---|
| 858 | return |
---|
| 859 | |
---|
[6774] | 860 | @property |
---|
[8141] | 861 | def translated_values(self): |
---|
[8921] | 862 | return translated_values(self) |
---|
[8141] | 863 | |
---|
| 864 | @property |
---|
[6774] | 865 | def label(self): |
---|
[7833] | 866 | # Here we know that the cookie has been set |
---|
| 867 | lang = self.request.cookies.get('kofa.language') |
---|
[7811] | 868 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 869 | target_language=lang) |
---|
| 870 | return _('${a}: Study Level ${b}', mapping = { |
---|
[8736] | 871 | 'a':self.context.student.display_fullname, |
---|
[7723] | 872 | 'b':level_title}) |
---|
[6774] | 873 | |
---|
[6803] | 874 | @property |
---|
| 875 | def total_credits(self): |
---|
| 876 | total_credits = 0 |
---|
| 877 | for key, val in self.context.items(): |
---|
| 878 | total_credits += val.credits |
---|
| 879 | return total_credits |
---|
| 880 | |
---|
[7459] | 881 | class ExportPDFCourseRegistrationSlipPage(UtilityView, grok.View): |
---|
[7028] | 882 | """Deliver a PDF slip of the context. |
---|
| 883 | """ |
---|
| 884 | grok.context(IStudentStudyLevel) |
---|
| 885 | grok.name('course_registration.pdf') |
---|
| 886 | grok.require('waeup.viewStudent') |
---|
| 887 | form_fields = grok.AutoFields(IStudentStudyLevel) |
---|
| 888 | prefix = 'form' |
---|
| 889 | |
---|
| 890 | @property |
---|
[7723] | 891 | def title(self): |
---|
[7819] | 892 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 893 | return translate(_('Level Data'), 'waeup.kofa', |
---|
[7723] | 894 | target_language=portal_language) |
---|
| 895 | |
---|
| 896 | @property |
---|
| 897 | def content_title(self): |
---|
[7819] | 898 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 899 | return translate(_('Course List'), 'waeup.kofa', |
---|
[7723] | 900 | target_language=portal_language) |
---|
| 901 | |
---|
| 902 | @property |
---|
[7028] | 903 | def label(self): |
---|
[7819] | 904 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 905 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
| 906 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 907 | target_language=lang) |
---|
[8141] | 908 | return translate(_('Course Registration Slip'), |
---|
[7811] | 909 | 'waeup.kofa', target_language=portal_language) \ |
---|
[7723] | 910 | + ' %s' % level_title |
---|
[7028] | 911 | |
---|
| 912 | def render(self): |
---|
[7819] | 913 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 914 | Sem = translate(_('Sem.'), 'waeup.kofa', target_language=portal_language) |
---|
| 915 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
| 916 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
| 917 | Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language) |
---|
| 918 | Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language) |
---|
| 919 | Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language) |
---|
| 920 | Mand = translate(_('Mand.'), 'waeup.kofa', target_language=portal_language) |
---|
| 921 | Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
[9141] | 922 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[7028] | 923 | self.request) |
---|
[7150] | 924 | students_utils = getUtility(IStudentsUtils) |
---|
[7318] | 925 | tabledata = sorted(self.context.values(), |
---|
| 926 | key=lambda value: str(value.semester) + value.code) |
---|
[7186] | 927 | return students_utils.renderPDF( |
---|
[7318] | 928 | self, 'course_registration.pdf', |
---|
[8736] | 929 | self.context.student, studentview, |
---|
[7723] | 930 | tableheader=[(Sem,'semester', 1.5),(Code,'code', 2.5), |
---|
| 931 | (Title,'title', 5), |
---|
| 932 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
| 933 | (Cred, 'credits', 1.5), |
---|
| 934 | (Mand, 'mandatory', 1.5), |
---|
[8141] | 935 | (Score, 'score', 1.5), |
---|
| 936 | #('Auto', 'automatic', 1.5) |
---|
[7304] | 937 | ], |
---|
[7318] | 938 | tabledata=tabledata) |
---|
[7028] | 939 | |
---|
[7819] | 940 | class StudyLevelManageFormPage(KofaEditFormPage): |
---|
[6792] | 941 | """ Page to edit the student study level data |
---|
| 942 | """ |
---|
| 943 | grok.context(IStudentStudyLevel) |
---|
| 944 | grok.name('manage') |
---|
[7136] | 945 | grok.require('waeup.manageStudent') |
---|
[6792] | 946 | grok.template('studylevelmanagepage') |
---|
| 947 | form_fields = grok.AutoFields(IStudentStudyLevel) |
---|
| 948 | pnav = 4 |
---|
[7723] | 949 | taboneactions = [_('Save'),_('Cancel')] |
---|
| 950 | tabtwoactions = [_('Add course ticket'), |
---|
| 951 | _('Remove selected tickets'),_('Cancel')] |
---|
[6792] | 952 | |
---|
| 953 | def update(self): |
---|
[9139] | 954 | if not self.context.__parent__.is_current: |
---|
| 955 | emit_lock_message(self) |
---|
| 956 | return |
---|
[6792] | 957 | super(StudyLevelManageFormPage, self).update() |
---|
| 958 | tabs.need() |
---|
[7484] | 959 | self.tab1 = self.tab2 = '' |
---|
| 960 | qs = self.request.get('QUERY_STRING', '') |
---|
| 961 | if not qs: |
---|
| 962 | qs = 'tab1' |
---|
| 963 | setattr(self, qs, 'active') |
---|
[7490] | 964 | warning.need() |
---|
| 965 | datatable.need() |
---|
[6792] | 966 | return |
---|
| 967 | |
---|
| 968 | @property |
---|
[8921] | 969 | def translated_values(self): |
---|
| 970 | return translated_values(self) |
---|
| 971 | |
---|
| 972 | @property |
---|
[6792] | 973 | def label(self): |
---|
[7833] | 974 | # Here we know that the cookie has been set |
---|
| 975 | lang = self.request.cookies.get('kofa.language') |
---|
[7811] | 976 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 977 | target_language=lang) |
---|
| 978 | return _('Manage study level ${a}', |
---|
| 979 | mapping = {'a':level_title}) |
---|
[6792] | 980 | |
---|
[7723] | 981 | @action(_('Save'), style='primary') |
---|
[6792] | 982 | def save(self, **data): |
---|
| 983 | msave(self, **data) |
---|
| 984 | return |
---|
| 985 | |
---|
[7723] | 986 | @action(_('Add course ticket')) |
---|
[6795] | 987 | def addCourseTicket(self, **data): |
---|
| 988 | self.redirect(self.url(self.context, '@@add')) |
---|
[6792] | 989 | |
---|
[7723] | 990 | @jsaction(_('Remove selected tickets')) |
---|
[6792] | 991 | def delCourseTicket(self, **data): |
---|
| 992 | form = self.request.form |
---|
| 993 | if form.has_key('val_id'): |
---|
| 994 | child_id = form['val_id'] |
---|
| 995 | else: |
---|
[7723] | 996 | self.flash(_('No ticket selected.')) |
---|
[7484] | 997 | self.redirect(self.url(self.context, '@@manage')+'?tab2') |
---|
[6792] | 998 | return |
---|
| 999 | if not isinstance(child_id, list): |
---|
| 1000 | child_id = [child_id] |
---|
| 1001 | deleted = [] |
---|
| 1002 | for id in child_id: |
---|
[7723] | 1003 | del self.context[id] |
---|
| 1004 | deleted.append(id) |
---|
[6792] | 1005 | if len(deleted): |
---|
[7723] | 1006 | self.flash(_('Successfully removed: ${a}', |
---|
| 1007 | mapping = {'a':', '.join(deleted)})) |
---|
[7484] | 1008 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6792] | 1009 | return |
---|
| 1010 | |
---|
[7459] | 1011 | class ValidateCoursesPage(UtilityView, grok.View): |
---|
[7334] | 1012 | """ Validate course list by course adviser |
---|
| 1013 | """ |
---|
| 1014 | grok.context(IStudentStudyLevel) |
---|
| 1015 | grok.name('validate_courses') |
---|
| 1016 | grok.require('waeup.validateStudent') |
---|
| 1017 | |
---|
| 1018 | def update(self): |
---|
[9139] | 1019 | if not self.context.__parent__.is_current: |
---|
| 1020 | emit_lock_message(self) |
---|
| 1021 | return |
---|
[7334] | 1022 | if str(self.context.__parent__.current_level) != self.context.__name__: |
---|
[7723] | 1023 | self.flash(_('This level does not correspond current level.')) |
---|
[8736] | 1024 | elif self.context.student.state == REGISTERED: |
---|
| 1025 | IWorkflowInfo(self.context.student).fireTransition( |
---|
[7642] | 1026 | 'validate_courses') |
---|
[7723] | 1027 | self.flash(_('Course list has been validated.')) |
---|
[7334] | 1028 | else: |
---|
[7723] | 1029 | self.flash(_('Student is in the wrong state.')) |
---|
[7334] | 1030 | self.redirect(self.url(self.context)) |
---|
| 1031 | return |
---|
| 1032 | |
---|
| 1033 | def render(self): |
---|
| 1034 | return |
---|
| 1035 | |
---|
[7459] | 1036 | class RejectCoursesPage(UtilityView, grok.View): |
---|
[7334] | 1037 | """ Reject course list by course adviser |
---|
| 1038 | """ |
---|
| 1039 | grok.context(IStudentStudyLevel) |
---|
| 1040 | grok.name('reject_courses') |
---|
| 1041 | grok.require('waeup.validateStudent') |
---|
| 1042 | |
---|
| 1043 | def update(self): |
---|
[9139] | 1044 | if not self.context.__parent__.is_current: |
---|
| 1045 | emit_lock_message(self) |
---|
| 1046 | return |
---|
[7334] | 1047 | if str(self.context.__parent__.current_level) != self.context.__name__: |
---|
[7723] | 1048 | self.flash(_('This level does not correspond current level.')) |
---|
[7334] | 1049 | self.redirect(self.url(self.context)) |
---|
| 1050 | return |
---|
[8736] | 1051 | elif self.context.student.state == VALIDATED: |
---|
| 1052 | IWorkflowInfo(self.context.student).fireTransition('reset8') |
---|
[7723] | 1053 | message = _('Course list request has been annulled.') |
---|
[7334] | 1054 | self.flash(message) |
---|
[8736] | 1055 | elif self.context.student.state == REGISTERED: |
---|
| 1056 | IWorkflowInfo(self.context.student).fireTransition('reset7') |
---|
[7723] | 1057 | message = _('Course list request has been rejected:') |
---|
[7334] | 1058 | self.flash(message) |
---|
| 1059 | else: |
---|
[7723] | 1060 | self.flash(_('Student is in the wrong state.')) |
---|
[7334] | 1061 | self.redirect(self.url(self.context)) |
---|
| 1062 | return |
---|
| 1063 | args = {'subject':message} |
---|
[8736] | 1064 | self.redirect(self.url(self.context.student) + |
---|
[7334] | 1065 | '/contactstudent?%s' % urlencode(args)) |
---|
| 1066 | return |
---|
| 1067 | |
---|
| 1068 | def render(self): |
---|
| 1069 | return |
---|
| 1070 | |
---|
[7819] | 1071 | class CourseTicketAddFormPage(KofaAddFormPage): |
---|
[6808] | 1072 | """Add a course ticket. |
---|
[6795] | 1073 | """ |
---|
| 1074 | grok.context(IStudentStudyLevel) |
---|
| 1075 | grok.name('add') |
---|
[7136] | 1076 | grok.require('waeup.manageStudent') |
---|
[7723] | 1077 | label = _('Add course ticket') |
---|
[6808] | 1078 | form_fields = grok.AutoFields(ICourseTicketAdd).omit( |
---|
[8141] | 1079 | 'score', 'automatic', 'carry_over') |
---|
[6795] | 1080 | pnav = 4 |
---|
| 1081 | |
---|
[9139] | 1082 | def update(self): |
---|
| 1083 | if not self.context.__parent__.is_current: |
---|
| 1084 | emit_lock_message(self) |
---|
| 1085 | return |
---|
| 1086 | super(CourseTicketAddFormPage, self).update() |
---|
| 1087 | return |
---|
| 1088 | |
---|
[7723] | 1089 | @action(_('Add course ticket')) |
---|
[6795] | 1090 | def addCourseTicket(self, **data): |
---|
[8325] | 1091 | ticket = createObject(u'waeup.CourseTicket') |
---|
[6795] | 1092 | course = data['course'] |
---|
[6802] | 1093 | ticket.automatic = False |
---|
[8141] | 1094 | ticket.carry_over = False |
---|
[6795] | 1095 | try: |
---|
[8920] | 1096 | self.context.addCourseTicket(ticket, course) |
---|
[6795] | 1097 | except KeyError: |
---|
[7723] | 1098 | self.flash(_('The ticket exists.')) |
---|
[6795] | 1099 | return |
---|
[7723] | 1100 | self.flash(_('Successfully added ${a}.', |
---|
| 1101 | mapping = {'a':ticket.code})) |
---|
[7484] | 1102 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6795] | 1103 | return |
---|
| 1104 | |
---|
[7834] | 1105 | @action(_('Cancel'), validator=NullValidator) |
---|
[6795] | 1106 | def cancel(self, **data): |
---|
| 1107 | self.redirect(self.url(self.context)) |
---|
| 1108 | |
---|
[7819] | 1109 | class CourseTicketDisplayFormPage(KofaDisplayFormPage): |
---|
[6796] | 1110 | """ Page to display course tickets |
---|
| 1111 | """ |
---|
| 1112 | grok.context(ICourseTicket) |
---|
| 1113 | grok.name('index') |
---|
| 1114 | grok.require('waeup.viewStudent') |
---|
| 1115 | form_fields = grok.AutoFields(ICourseTicket) |
---|
| 1116 | grok.template('courseticketpage') |
---|
| 1117 | pnav = 4 |
---|
| 1118 | |
---|
| 1119 | @property |
---|
| 1120 | def label(self): |
---|
[7723] | 1121 | return _('${a}: Course Ticket ${b}', mapping = { |
---|
[8736] | 1122 | 'a':self.context.student.display_fullname, |
---|
[7723] | 1123 | 'b':self.context.code}) |
---|
[6796] | 1124 | |
---|
[7819] | 1125 | class CourseTicketManageFormPage(KofaEditFormPage): |
---|
[6796] | 1126 | """ Page to manage course tickets |
---|
| 1127 | """ |
---|
| 1128 | grok.context(ICourseTicket) |
---|
| 1129 | grok.name('manage') |
---|
[7136] | 1130 | grok.require('waeup.manageStudent') |
---|
[6796] | 1131 | form_fields = grok.AutoFields(ICourseTicket) |
---|
| 1132 | grok.template('courseticketmanagepage') |
---|
| 1133 | pnav = 4 |
---|
| 1134 | |
---|
| 1135 | @property |
---|
| 1136 | def label(self): |
---|
[7723] | 1137 | return _('Manage course ticket ${a}', mapping = {'a':self.context.code}) |
---|
[6796] | 1138 | |
---|
[7459] | 1139 | @action('Save', style='primary') |
---|
[6796] | 1140 | def save(self, **data): |
---|
| 1141 | msave(self, **data) |
---|
| 1142 | return |
---|
| 1143 | |
---|
[7819] | 1144 | class PaymentsManageFormPage(KofaEditFormPage): |
---|
[6869] | 1145 | """ Page to manage the student payments |
---|
[7642] | 1146 | |
---|
| 1147 | This manage form page is for both students and students officers. |
---|
[6869] | 1148 | """ |
---|
| 1149 | grok.context(IStudentPaymentsContainer) |
---|
[6940] | 1150 | grok.name('index') |
---|
[7181] | 1151 | grok.require('waeup.payStudent') |
---|
[6869] | 1152 | form_fields = grok.AutoFields(IStudentPaymentsContainer) |
---|
| 1153 | grok.template('paymentsmanagepage') |
---|
| 1154 | pnav = 4 |
---|
| 1155 | |
---|
[6940] | 1156 | def unremovable(self, ticket): |
---|
[7251] | 1157 | usertype = getattr(self.request.principal, 'user_type', None) |
---|
| 1158 | if not usertype: |
---|
| 1159 | return False |
---|
| 1160 | return (self.request.principal.user_type == 'student' and ticket.r_code) |
---|
[6940] | 1161 | |
---|
[6869] | 1162 | @property |
---|
| 1163 | def label(self): |
---|
[7723] | 1164 | return _('${a}: Payments', |
---|
| 1165 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
[6869] | 1166 | |
---|
| 1167 | def update(self): |
---|
| 1168 | super(PaymentsManageFormPage, self).update() |
---|
| 1169 | datatable.need() |
---|
[7329] | 1170 | warning.need() |
---|
[6869] | 1171 | return |
---|
| 1172 | |
---|
[7723] | 1173 | @jsaction(_('Remove selected tickets')) |
---|
[6869] | 1174 | def delPaymentTicket(self, **data): |
---|
| 1175 | form = self.request.form |
---|
| 1176 | if form.has_key('val_id'): |
---|
| 1177 | child_id = form['val_id'] |
---|
| 1178 | else: |
---|
[7723] | 1179 | self.flash(_('No payment selected.')) |
---|
[6940] | 1180 | self.redirect(self.url(self.context)) |
---|
[6869] | 1181 | return |
---|
| 1182 | if not isinstance(child_id, list): |
---|
| 1183 | child_id = [child_id] |
---|
| 1184 | deleted = [] |
---|
| 1185 | for id in child_id: |
---|
[6992] | 1186 | # Students are not allowed to remove used payment tickets |
---|
[6940] | 1187 | if not self.unremovable(self.context[id]): |
---|
[7723] | 1188 | del self.context[id] |
---|
| 1189 | deleted.append(id) |
---|
[6869] | 1190 | if len(deleted): |
---|
[7723] | 1191 | self.flash(_('Successfully removed: ${a}', |
---|
| 1192 | mapping = {'a': ', '.join(deleted)})) |
---|
[8735] | 1193 | self.context.writeLogMessage( |
---|
[8885] | 1194 | self,'removed: %s' % ', '.join(deleted)) |
---|
[6940] | 1195 | self.redirect(self.url(self.context)) |
---|
[6869] | 1196 | return |
---|
| 1197 | |
---|
[7723] | 1198 | @action(_('Add online payment ticket')) |
---|
[6869] | 1199 | def addPaymentTicket(self, **data): |
---|
| 1200 | self.redirect(self.url(self.context, '@@addop')) |
---|
| 1201 | |
---|
[7819] | 1202 | class OnlinePaymentAddFormPage(KofaAddFormPage): |
---|
[6869] | 1203 | """ Page to add an online payment ticket |
---|
| 1204 | """ |
---|
| 1205 | grok.context(IStudentPaymentsContainer) |
---|
| 1206 | grok.name('addop') |
---|
[7181] | 1207 | grok.require('waeup.payStudent') |
---|
[6877] | 1208 | form_fields = grok.AutoFields(IStudentOnlinePayment).select( |
---|
[6869] | 1209 | 'p_category') |
---|
[7723] | 1210 | label = _('Add online payment') |
---|
[6869] | 1211 | pnav = 4 |
---|
[7642] | 1212 | |
---|
[7723] | 1213 | @action(_('Create ticket'), style='primary') |
---|
[6869] | 1214 | def createTicket(self, **data): |
---|
[7024] | 1215 | p_category = data['p_category'] |
---|
[9148] | 1216 | previous_session = data.get('p_session', None) |
---|
| 1217 | previous_level = data.get('p_level', None) |
---|
[7024] | 1218 | student = self.context.__parent__ |
---|
| 1219 | if p_category == 'bed_allocation' and student[ |
---|
| 1220 | 'studycourse'].current_session != grok.getSite()[ |
---|
[8685] | 1221 | 'hostels'].accommodation_session: |
---|
[7024] | 1222 | self.flash( |
---|
[7723] | 1223 | _('Your current session does not match ' + \ |
---|
| 1224 | 'accommodation session.')) |
---|
[7024] | 1225 | self.redirect(self.url(self.context)) |
---|
| 1226 | return |
---|
[7150] | 1227 | students_utils = getUtility(IStudentsUtils) |
---|
[9148] | 1228 | error, payment = students_utils.setPaymentDetails( |
---|
| 1229 | p_category, student, previous_session, previous_level) |
---|
[8595] | 1230 | if error is not None: |
---|
| 1231 | self.flash(error) |
---|
[9148] | 1232 | if 'Would you like' in error: |
---|
| 1233 | self.redirect(self.url(self.context) + '/@@addpp') |
---|
| 1234 | return |
---|
[8081] | 1235 | self.redirect(self.url(self.context)) |
---|
| 1236 | return |
---|
[6869] | 1237 | self.context[payment.p_id] = payment |
---|
[7723] | 1238 | self.flash(_('Payment ticket created.')) |
---|
[6940] | 1239 | self.redirect(self.url(self.context)) |
---|
[6869] | 1240 | return |
---|
| 1241 | |
---|
[9148] | 1242 | class PreviousPaymentAddFormPage(OnlinePaymentAddFormPage): |
---|
| 1243 | """ Page to add an online payment ticket for previous sessions |
---|
| 1244 | """ |
---|
| 1245 | grok.context(IStudentPaymentsContainer) |
---|
| 1246 | grok.name('addpp') |
---|
| 1247 | grok.require('waeup.payStudent') |
---|
| 1248 | form_fields = grok.AutoFields(IStudentPreviousPayment).select( |
---|
| 1249 | 'p_category', 'p_session', 'p_level') |
---|
| 1250 | label = _('Add previous session online payment') |
---|
| 1251 | pnav = 4 |
---|
| 1252 | |
---|
[7819] | 1253 | class OnlinePaymentDisplayFormPage(KofaDisplayFormPage): |
---|
[6869] | 1254 | """ Page to view an online payment ticket |
---|
| 1255 | """ |
---|
[6877] | 1256 | grok.context(IStudentOnlinePayment) |
---|
[6869] | 1257 | grok.name('index') |
---|
| 1258 | grok.require('waeup.viewStudent') |
---|
[6877] | 1259 | form_fields = grok.AutoFields(IStudentOnlinePayment) |
---|
[8170] | 1260 | form_fields[ |
---|
| 1261 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 1262 | form_fields[ |
---|
| 1263 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[6869] | 1264 | pnav = 4 |
---|
| 1265 | |
---|
| 1266 | @property |
---|
| 1267 | def label(self): |
---|
[7723] | 1268 | return _('${a}: Online Payment Ticket ${b}', mapping = { |
---|
[8736] | 1269 | 'a':self.context.student.display_fullname, |
---|
[7723] | 1270 | 'b':self.context.p_id}) |
---|
[6869] | 1271 | |
---|
[8420] | 1272 | class OnlinePaymentApprovePage(UtilityView, grok.View): |
---|
[6930] | 1273 | """ Callback view |
---|
| 1274 | """ |
---|
| 1275 | grok.context(IStudentOnlinePayment) |
---|
[8420] | 1276 | grok.name('approve') |
---|
| 1277 | grok.require('waeup.managePortal') |
---|
[6930] | 1278 | |
---|
| 1279 | def update(self): |
---|
[8428] | 1280 | success, msg, log = self.context.approveStudentPayment() |
---|
| 1281 | if log is not None: |
---|
[8735] | 1282 | self.context.writeLogMessage(self,log) |
---|
[8420] | 1283 | self.flash(msg) |
---|
[6940] | 1284 | return |
---|
[6930] | 1285 | |
---|
| 1286 | def render(self): |
---|
[6940] | 1287 | self.redirect(self.url(self.context, '@@index')) |
---|
[6930] | 1288 | return |
---|
| 1289 | |
---|
[8420] | 1290 | class OnlinePaymentFakeApprovePage(OnlinePaymentApprovePage): |
---|
| 1291 | """ Approval view for students. |
---|
| 1292 | |
---|
| 1293 | This view is used for browser tests only and |
---|
| 1294 | must be neutralized in custom pages! |
---|
| 1295 | """ |
---|
| 1296 | |
---|
| 1297 | grok.name('fake_approve') |
---|
| 1298 | grok.require('waeup.payStudent') |
---|
| 1299 | |
---|
[7459] | 1300 | class ExportPDFPaymentSlipPage(UtilityView, grok.View): |
---|
[7019] | 1301 | """Deliver a PDF slip of the context. |
---|
| 1302 | """ |
---|
| 1303 | grok.context(IStudentOnlinePayment) |
---|
[8262] | 1304 | grok.name('payment_slip.pdf') |
---|
[7019] | 1305 | grok.require('waeup.viewStudent') |
---|
| 1306 | form_fields = grok.AutoFields(IStudentOnlinePayment) |
---|
[8173] | 1307 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 1308 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[7019] | 1309 | prefix = 'form' |
---|
[8258] | 1310 | note = None |
---|
[7019] | 1311 | |
---|
| 1312 | @property |
---|
[8262] | 1313 | def title(self): |
---|
| 1314 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 1315 | return translate(_('Payment Data'), 'waeup.kofa', |
---|
| 1316 | target_language=portal_language) |
---|
| 1317 | |
---|
| 1318 | @property |
---|
[7019] | 1319 | def label(self): |
---|
[8262] | 1320 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 1321 | return translate(_('Online Payment Slip'), |
---|
| 1322 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 1323 | + ' %s' % self.context.p_id |
---|
[7019] | 1324 | |
---|
| 1325 | def render(self): |
---|
[8262] | 1326 | #if self.context.p_state != 'paid': |
---|
| 1327 | # self.flash('Ticket not yet paid.') |
---|
| 1328 | # self.redirect(self.url(self.context)) |
---|
| 1329 | # return |
---|
[9141] | 1330 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[7019] | 1331 | self.request) |
---|
[7150] | 1332 | students_utils = getUtility(IStudentsUtils) |
---|
[8262] | 1333 | return students_utils.renderPDF(self, 'payment_slip.pdf', |
---|
[8736] | 1334 | self.context.student, studentview, note=self.note) |
---|
[7019] | 1335 | |
---|
[6992] | 1336 | |
---|
[7819] | 1337 | class AccommodationManageFormPage(KofaEditFormPage): |
---|
[7009] | 1338 | """ Page to manage bed tickets. |
---|
[7642] | 1339 | |
---|
| 1340 | This manage form page is for both students and students officers. |
---|
[6635] | 1341 | """ |
---|
| 1342 | grok.context(IStudentAccommodation) |
---|
| 1343 | grok.name('index') |
---|
[7181] | 1344 | grok.require('waeup.handleAccommodation') |
---|
[6635] | 1345 | form_fields = grok.AutoFields(IStudentAccommodation) |
---|
[6992] | 1346 | grok.template('accommodationmanagepage') |
---|
[6642] | 1347 | pnav = 4 |
---|
[7723] | 1348 | officers_only_actions = [_('Remove selected')] |
---|
[6635] | 1349 | |
---|
| 1350 | @property |
---|
| 1351 | def label(self): |
---|
[7723] | 1352 | return _('${a}: Accommodation', |
---|
| 1353 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
[6637] | 1354 | |
---|
[6992] | 1355 | def update(self): |
---|
| 1356 | super(AccommodationManageFormPage, self).update() |
---|
| 1357 | datatable.need() |
---|
[7329] | 1358 | warning.need() |
---|
[6992] | 1359 | return |
---|
| 1360 | |
---|
[7723] | 1361 | @jsaction(_('Remove selected')) |
---|
[7009] | 1362 | def delBedTickets(self, **data): |
---|
[7240] | 1363 | if getattr(self.request.principal, 'user_type', None) == 'student': |
---|
[7723] | 1364 | self.flash(_('You are not allowed to remove bed tickets.')) |
---|
[7017] | 1365 | self.redirect(self.url(self.context)) |
---|
| 1366 | return |
---|
[6992] | 1367 | form = self.request.form |
---|
| 1368 | if form.has_key('val_id'): |
---|
| 1369 | child_id = form['val_id'] |
---|
| 1370 | else: |
---|
[7723] | 1371 | self.flash(_('No bed ticket selected.')) |
---|
[6992] | 1372 | self.redirect(self.url(self.context)) |
---|
| 1373 | return |
---|
| 1374 | if not isinstance(child_id, list): |
---|
| 1375 | child_id = [child_id] |
---|
| 1376 | deleted = [] |
---|
| 1377 | for id in child_id: |
---|
[7068] | 1378 | del self.context[id] |
---|
| 1379 | deleted.append(id) |
---|
[6992] | 1380 | if len(deleted): |
---|
[7723] | 1381 | self.flash(_('Successfully removed: ${a}', |
---|
| 1382 | mapping = {'a':', '.join(deleted)})) |
---|
[8735] | 1383 | self.context.writeLogMessage( |
---|
| 1384 | self,'removed: % s' % ', '.join(deleted)) |
---|
[6992] | 1385 | self.redirect(self.url(self.context)) |
---|
| 1386 | return |
---|
| 1387 | |
---|
[7009] | 1388 | @property |
---|
| 1389 | def selected_actions(self): |
---|
[7240] | 1390 | if getattr(self.request.principal, 'user_type', None) == 'student': |
---|
[7642] | 1391 | return [action for action in self.actions |
---|
| 1392 | if not action.label in self.officers_only_actions] |
---|
| 1393 | return self.actions |
---|
[7009] | 1394 | |
---|
[7819] | 1395 | class BedTicketAddPage(KofaPage): |
---|
[6992] | 1396 | """ Page to add an online payment ticket |
---|
| 1397 | """ |
---|
| 1398 | grok.context(IStudentAccommodation) |
---|
| 1399 | grok.name('add') |
---|
[7181] | 1400 | grok.require('waeup.handleAccommodation') |
---|
[6992] | 1401 | grok.template('enterpin') |
---|
[6993] | 1402 | ac_prefix = 'HOS' |
---|
[7723] | 1403 | label = _('Add bed ticket') |
---|
[6992] | 1404 | pnav = 4 |
---|
[7723] | 1405 | buttonname = _('Create bed ticket') |
---|
[6993] | 1406 | notice = '' |
---|
[6992] | 1407 | |
---|
| 1408 | def update(self, SUBMIT=None): |
---|
[8736] | 1409 | student = self.context.student |
---|
[7150] | 1410 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1411 | acc_details = students_utils.getAccommodationDetails(student) |
---|
[8688] | 1412 | if acc_details.get('expired', False): |
---|
| 1413 | startdate = acc_details.get('startdate') |
---|
| 1414 | enddate = acc_details.get('enddate') |
---|
| 1415 | if startdate and enddate: |
---|
| 1416 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 1417 | startdate = to_timezone( |
---|
| 1418 | startdate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 1419 | enddate = to_timezone( |
---|
| 1420 | enddate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 1421 | self.flash(_("Outside booking period: ${a} - ${b}", |
---|
| 1422 | mapping = {'a': startdate, 'b': enddate})) |
---|
| 1423 | else: |
---|
| 1424 | self.flash(_("Outside booking period.")) |
---|
| 1425 | self.redirect(self.url(self.context)) |
---|
| 1426 | return |
---|
[7369] | 1427 | if not acc_details: |
---|
[7723] | 1428 | self.flash(_("Your data are incomplete.")) |
---|
[7369] | 1429 | self.redirect(self.url(self.context)) |
---|
| 1430 | return |
---|
[6996] | 1431 | if not student.state in acc_details['allowed_states']: |
---|
[7723] | 1432 | self.flash(_("You are in the wrong registration state.")) |
---|
[6992] | 1433 | self.redirect(self.url(self.context)) |
---|
| 1434 | return |
---|
[7642] | 1435 | if student['studycourse'].current_session != acc_details[ |
---|
| 1436 | 'booking_session']: |
---|
[7061] | 1437 | self.flash( |
---|
[7723] | 1438 | _('Your current session does not match accommodation session.')) |
---|
[7061] | 1439 | self.redirect(self.url(self.context)) |
---|
| 1440 | return |
---|
| 1441 | if str(acc_details['booking_session']) in self.context.keys(): |
---|
[7642] | 1442 | self.flash( |
---|
[7723] | 1443 | _('You already booked a bed space in current ' \ |
---|
| 1444 | + 'accommodation session.')) |
---|
[7004] | 1445 | self.redirect(self.url(self.context)) |
---|
| 1446 | return |
---|
[6992] | 1447 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 1448 | self.ac_number = self.request.form.get('ac_number', None) |
---|
| 1449 | if SUBMIT is None: |
---|
| 1450 | return |
---|
| 1451 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 1452 | code = get_access_code(pin) |
---|
| 1453 | if not code: |
---|
[7723] | 1454 | self.flash(_('Activation code is invalid.')) |
---|
[6992] | 1455 | return |
---|
[7060] | 1456 | # Search and book bed |
---|
[6997] | 1457 | cat = queryUtility(ICatalog, name='beds_catalog', default=None) |
---|
| 1458 | entries = cat.searchResults( |
---|
[7003] | 1459 | owner=(student.student_id,student.student_id)) |
---|
| 1460 | if len(entries): |
---|
[7060] | 1461 | # If bed space has bee manually allocated use this bed |
---|
[7003] | 1462 | bed = [entry for entry in entries][0] |
---|
[7060] | 1463 | else: |
---|
| 1464 | # else search for other available beds |
---|
| 1465 | entries = cat.searchResults( |
---|
| 1466 | bed_type=(acc_details['bt'],acc_details['bt'])) |
---|
| 1467 | available_beds = [ |
---|
| 1468 | entry for entry in entries if entry.owner == NOT_OCCUPIED] |
---|
| 1469 | if available_beds: |
---|
[7150] | 1470 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1471 | bed = students_utils.selectBed(available_beds) |
---|
[7060] | 1472 | bed.bookBed(student.student_id) |
---|
| 1473 | else: |
---|
[7723] | 1474 | self.flash(_('There is no free bed in your category ${a}.', |
---|
| 1475 | mapping = {'a':acc_details['bt']})) |
---|
[7060] | 1476 | return |
---|
[6992] | 1477 | # Mark pin as used (this also fires a pin related transition) |
---|
| 1478 | if code.state == USED: |
---|
[7723] | 1479 | self.flash(_('Activation code has already been used.')) |
---|
[6992] | 1480 | return |
---|
| 1481 | else: |
---|
[7723] | 1482 | comment = _(u'invalidated') |
---|
[6992] | 1483 | # Here we know that the ac is in state initialized so we do not |
---|
| 1484 | # expect an exception, but the owner might be different |
---|
| 1485 | if not invalidate_accesscode( |
---|
[8736] | 1486 | pin,comment,self.context.student.student_id): |
---|
[7723] | 1487 | self.flash(_('You are not the owner of this access code.')) |
---|
[6992] | 1488 | return |
---|
[7060] | 1489 | # Create bed ticket |
---|
[6992] | 1490 | bedticket = createObject(u'waeup.BedTicket') |
---|
| 1491 | bedticket.booking_code = pin |
---|
[6994] | 1492 | bedticket.booking_session = acc_details['booking_session'] |
---|
[6996] | 1493 | bedticket.bed_type = acc_details['bt'] |
---|
[7006] | 1494 | bedticket.bed = bed |
---|
[6996] | 1495 | hall_title = bed.__parent__.hostel_name |
---|
| 1496 | coordinates = bed.getBedCoordinates()[1:] |
---|
| 1497 | block, room_nr, bed_nr = coordinates |
---|
[7723] | 1498 | bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = { |
---|
| 1499 | 'a':hall_title, 'b':block, |
---|
| 1500 | 'c':room_nr, 'd':bed_nr, |
---|
| 1501 | 'e':bed.bed_type}) |
---|
[7819] | 1502 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7723] | 1503 | bedticket.bed_coordinates = translate( |
---|
[7811] | 1504 | bc, 'waeup.kofa',target_language=portal_language) |
---|
[6996] | 1505 | key = str(acc_details['booking_session']) |
---|
| 1506 | self.context[key] = bedticket |
---|
[7723] | 1507 | self.flash(_('Bed ticket created and bed booked: ${a}', |
---|
| 1508 | mapping = {'a':bedticket.bed_coordinates})) |
---|
[6992] | 1509 | self.redirect(self.url(self.context)) |
---|
| 1510 | return |
---|
| 1511 | |
---|
[7819] | 1512 | class BedTicketDisplayFormPage(KofaDisplayFormPage): |
---|
[6994] | 1513 | """ Page to display bed tickets |
---|
| 1514 | """ |
---|
| 1515 | grok.context(IBedTicket) |
---|
| 1516 | grok.name('index') |
---|
[7181] | 1517 | grok.require('waeup.handleAccommodation') |
---|
[6994] | 1518 | form_fields = grok.AutoFields(IBedTicket) |
---|
| 1519 | pnav = 4 |
---|
| 1520 | |
---|
| 1521 | @property |
---|
| 1522 | def label(self): |
---|
[7723] | 1523 | return _('Bed Ticket for Session ${a}', |
---|
| 1524 | mapping = {'a':self.context.getSessionString()}) |
---|
[6994] | 1525 | |
---|
[7459] | 1526 | class ExportPDFBedTicketSlipPage(UtilityView, grok.View): |
---|
[7027] | 1527 | """Deliver a PDF slip of the context. |
---|
| 1528 | """ |
---|
| 1529 | grok.context(IBedTicket) |
---|
| 1530 | grok.name('bed_allocation.pdf') |
---|
[7181] | 1531 | grok.require('waeup.handleAccommodation') |
---|
[7027] | 1532 | form_fields = grok.AutoFields(IBedTicket) |
---|
[8173] | 1533 | form_fields['booking_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[7027] | 1534 | prefix = 'form' |
---|
| 1535 | |
---|
| 1536 | @property |
---|
[7723] | 1537 | def title(self): |
---|
[7819] | 1538 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 1539 | return translate(_('Bed Allocation Data'), 'waeup.kofa', |
---|
[7723] | 1540 | target_language=portal_language) |
---|
| 1541 | |
---|
| 1542 | @property |
---|
[7027] | 1543 | def label(self): |
---|
[7819] | 1544 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7723] | 1545 | return translate(_('Bed Allocation: '), |
---|
[7811] | 1546 | 'waeup.kofa', target_language=portal_language) \ |
---|
[7723] | 1547 | + ' %s' % self.context.bed_coordinates |
---|
[7027] | 1548 | |
---|
| 1549 | def render(self): |
---|
[9141] | 1550 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[7027] | 1551 | self.request) |
---|
[7150] | 1552 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1553 | return students_utils.renderPDF( |
---|
[7318] | 1554 | self, 'bed_allocation.pdf', |
---|
[8736] | 1555 | self.context.student, studentview) |
---|
[7027] | 1556 | |
---|
[7459] | 1557 | class BedTicketRelocationPage(UtilityView, grok.View): |
---|
[7015] | 1558 | """ Callback view |
---|
| 1559 | """ |
---|
| 1560 | grok.context(IBedTicket) |
---|
| 1561 | grok.name('relocate') |
---|
| 1562 | grok.require('waeup.manageHostels') |
---|
| 1563 | |
---|
[7059] | 1564 | # Relocate student if student parameters have changed or the bed_type |
---|
| 1565 | # of the bed has changed |
---|
[7015] | 1566 | def update(self): |
---|
[8736] | 1567 | student = self.context.student |
---|
[7150] | 1568 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1569 | acc_details = students_utils.getAccommodationDetails(student) |
---|
[7068] | 1570 | if self.context.bed != None and \ |
---|
| 1571 | 'reserved' in self.context.bed.bed_type: |
---|
[7723] | 1572 | self.flash(_("Students in reserved beds can't be relocated.")) |
---|
[7068] | 1573 | self.redirect(self.url(self.context)) |
---|
| 1574 | return |
---|
[7059] | 1575 | if acc_details['bt'] == self.context.bed_type and \ |
---|
[7068] | 1576 | self.context.bed != None and \ |
---|
[7059] | 1577 | self.context.bed.bed_type == self.context.bed_type: |
---|
[7723] | 1578 | self.flash(_("Student can't be relocated.")) |
---|
[7068] | 1579 | self.redirect(self.url(self.context)) |
---|
[7015] | 1580 | return |
---|
[7068] | 1581 | # Search a bed |
---|
[7015] | 1582 | cat = queryUtility(ICatalog, name='beds_catalog', default=None) |
---|
| 1583 | entries = cat.searchResults( |
---|
[7068] | 1584 | owner=(student.student_id,student.student_id)) |
---|
| 1585 | if len(entries) and self.context.bed == None: |
---|
| 1586 | # If booking has been cancelled but other bed space has been |
---|
| 1587 | # manually allocated after cancellation use this bed |
---|
| 1588 | new_bed = [entry for entry in entries][0] |
---|
| 1589 | else: |
---|
| 1590 | # Search for other available beds |
---|
| 1591 | entries = cat.searchResults( |
---|
| 1592 | bed_type=(acc_details['bt'],acc_details['bt'])) |
---|
| 1593 | available_beds = [ |
---|
| 1594 | entry for entry in entries if entry.owner == NOT_OCCUPIED] |
---|
| 1595 | if available_beds: |
---|
[7150] | 1596 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1597 | new_bed = students_utils.selectBed(available_beds) |
---|
[7068] | 1598 | new_bed.bookBed(student.student_id) |
---|
| 1599 | else: |
---|
[7723] | 1600 | self.flash(_('There is no free bed in your category ${a}.', |
---|
| 1601 | mapping = {'a':acc_details['bt']})) |
---|
[7068] | 1602 | self.redirect(self.url(self.context)) |
---|
| 1603 | return |
---|
[7642] | 1604 | # Release old bed if exists |
---|
[7068] | 1605 | if self.context.bed != None: |
---|
| 1606 | self.context.bed.owner = NOT_OCCUPIED |
---|
| 1607 | notify(grok.ObjectModifiedEvent(self.context.bed)) |
---|
[7015] | 1608 | # Alocate new bed |
---|
| 1609 | self.context.bed_type = acc_details['bt'] |
---|
[7068] | 1610 | self.context.bed = new_bed |
---|
| 1611 | hall_title = new_bed.__parent__.hostel_name |
---|
| 1612 | coordinates = new_bed.getBedCoordinates()[1:] |
---|
[7015] | 1613 | block, room_nr, bed_nr = coordinates |
---|
[7723] | 1614 | bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = { |
---|
| 1615 | 'a':hall_title, 'b':block, |
---|
| 1616 | 'c':room_nr, 'd':bed_nr, |
---|
| 1617 | 'e':new_bed.bed_type}) |
---|
[7819] | 1618 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7723] | 1619 | self.context.bed_coordinates = translate( |
---|
[7811] | 1620 | bc, 'waeup.kofa',target_language=portal_language) |
---|
[7723] | 1621 | self.flash(_('Student relocated: ${a}', |
---|
| 1622 | mapping = {'a':self.context.bed_coordinates})) |
---|
[7015] | 1623 | self.redirect(self.url(self.context)) |
---|
| 1624 | return |
---|
| 1625 | |
---|
| 1626 | def render(self): |
---|
| 1627 | return |
---|
| 1628 | |
---|
[7819] | 1629 | class StudentHistoryPage(KofaPage): |
---|
[6637] | 1630 | """ Page to display student clearance data |
---|
| 1631 | """ |
---|
| 1632 | grok.context(IStudent) |
---|
| 1633 | grok.name('history') |
---|
[6660] | 1634 | grok.require('waeup.viewStudent') |
---|
[6637] | 1635 | grok.template('studenthistory') |
---|
[6642] | 1636 | pnav = 4 |
---|
[6637] | 1637 | |
---|
| 1638 | @property |
---|
| 1639 | def label(self): |
---|
[7723] | 1640 | return _('${a}: History', mapping = {'a':self.context.display_fullname}) |
---|
[6694] | 1641 | |
---|
| 1642 | # Pages for students only |
---|
| 1643 | |
---|
[7819] | 1644 | class StudentBaseEditFormPage(KofaEditFormPage): |
---|
[7133] | 1645 | """ View to edit student base data |
---|
| 1646 | """ |
---|
| 1647 | grok.context(IStudent) |
---|
| 1648 | grok.name('edit_base') |
---|
| 1649 | grok.require('waeup.handleStudent') |
---|
| 1650 | form_fields = grok.AutoFields(IStudentBase).select( |
---|
| 1651 | 'email', 'phone') |
---|
[7723] | 1652 | label = _('Edit base data') |
---|
[7133] | 1653 | pnav = 4 |
---|
| 1654 | |
---|
[7723] | 1655 | @action(_('Save'), style='primary') |
---|
[7133] | 1656 | def save(self, **data): |
---|
| 1657 | msave(self, **data) |
---|
| 1658 | return |
---|
| 1659 | |
---|
[7819] | 1660 | class StudentChangePasswordPage(KofaEditFormPage): |
---|
[7144] | 1661 | """ View to manage student base data |
---|
[6756] | 1662 | """ |
---|
| 1663 | grok.context(IStudent) |
---|
[7114] | 1664 | grok.name('change_password') |
---|
[6694] | 1665 | grok.require('waeup.handleStudent') |
---|
[7144] | 1666 | grok.template('change_password') |
---|
[7723] | 1667 | label = _('Change password') |
---|
[6694] | 1668 | pnav = 4 |
---|
| 1669 | |
---|
[7723] | 1670 | @action(_('Save'), style='primary') |
---|
[7144] | 1671 | def save(self, **data): |
---|
| 1672 | form = self.request.form |
---|
| 1673 | password = form.get('change_password', None) |
---|
| 1674 | password_ctl = form.get('change_password_repeat', None) |
---|
| 1675 | if password: |
---|
[7147] | 1676 | validator = getUtility(IPasswordValidator) |
---|
| 1677 | errors = validator.validate_password(password, password_ctl) |
---|
| 1678 | if not errors: |
---|
| 1679 | IUserAccount(self.context).setPassword(password) |
---|
[8735] | 1680 | self.context.writeLogMessage(self, 'saved: password') |
---|
[7723] | 1681 | self.flash(_('Password changed.')) |
---|
[6756] | 1682 | else: |
---|
[7147] | 1683 | self.flash( ' '.join(errors)) |
---|
[6756] | 1684 | return |
---|
| 1685 | |
---|
[7819] | 1686 | class StudentFilesUploadPage(KofaPage): |
---|
[7114] | 1687 | """ View to upload files by student |
---|
| 1688 | """ |
---|
| 1689 | grok.context(IStudent) |
---|
| 1690 | grok.name('change_portrait') |
---|
[7127] | 1691 | grok.require('waeup.uploadStudentFile') |
---|
[7114] | 1692 | grok.template('filesuploadpage') |
---|
[7723] | 1693 | label = _('Upload portrait') |
---|
[7114] | 1694 | pnav = 4 |
---|
| 1695 | |
---|
[7133] | 1696 | def update(self): |
---|
[8736] | 1697 | if self.context.student.state != ADMITTED: |
---|
[7145] | 1698 | emit_lock_message(self) |
---|
[7133] | 1699 | return |
---|
| 1700 | super(StudentFilesUploadPage, self).update() |
---|
| 1701 | return |
---|
| 1702 | |
---|
[7819] | 1703 | class StartClearancePage(KofaPage): |
---|
[6770] | 1704 | grok.context(IStudent) |
---|
| 1705 | grok.name('start_clearance') |
---|
| 1706 | grok.require('waeup.handleStudent') |
---|
| 1707 | grok.template('enterpin') |
---|
[7723] | 1708 | label = _('Start clearance') |
---|
[6770] | 1709 | ac_prefix = 'CLR' |
---|
| 1710 | notice = '' |
---|
| 1711 | pnav = 4 |
---|
[7723] | 1712 | buttonname = _('Start clearance now') |
---|
[6770] | 1713 | |
---|
[7133] | 1714 | @property |
---|
| 1715 | def all_required_fields_filled(self): |
---|
| 1716 | if self.context.email and self.context.phone: |
---|
| 1717 | return True |
---|
| 1718 | return False |
---|
| 1719 | |
---|
| 1720 | @property |
---|
| 1721 | def portrait_uploaded(self): |
---|
| 1722 | store = getUtility(IExtFileStore) |
---|
| 1723 | if store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
| 1724 | return True |
---|
| 1725 | return False |
---|
| 1726 | |
---|
[6770] | 1727 | def update(self, SUBMIT=None): |
---|
[7671] | 1728 | if not self.context.state == ADMITTED: |
---|
[7745] | 1729 | self.flash(_("Wrong state")) |
---|
[6936] | 1730 | self.redirect(self.url(self.context)) |
---|
| 1731 | return |
---|
[7133] | 1732 | if not self.portrait_uploaded: |
---|
[7723] | 1733 | self.flash(_("No portrait uploaded.")) |
---|
[7133] | 1734 | self.redirect(self.url(self.context, 'change_portrait')) |
---|
| 1735 | return |
---|
| 1736 | if not self.all_required_fields_filled: |
---|
[7723] | 1737 | self.flash(_("Not all required fields filled.")) |
---|
[7133] | 1738 | self.redirect(self.url(self.context, 'edit_base')) |
---|
| 1739 | return |
---|
[6770] | 1740 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 1741 | self.ac_number = self.request.form.get('ac_number', None) |
---|
| 1742 | |
---|
| 1743 | if SUBMIT is None: |
---|
| 1744 | return |
---|
| 1745 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 1746 | code = get_access_code(pin) |
---|
| 1747 | if not code: |
---|
[7723] | 1748 | self.flash(_('Activation code is invalid.')) |
---|
[6770] | 1749 | return |
---|
| 1750 | if code.state == USED: |
---|
[7723] | 1751 | self.flash(_('Activation code has already been used.')) |
---|
[6770] | 1752 | return |
---|
[8974] | 1753 | # Mark pin as used (this also fires a pin related transition) |
---|
| 1754 | # and fire transition start_clearance |
---|
| 1755 | comment = _(u"invalidated") |
---|
| 1756 | # Here we know that the ac is in state initialized so we do not |
---|
| 1757 | # expect an exception, but the owner might be different |
---|
| 1758 | if not invalidate_accesscode(pin, comment, self.context.student_id): |
---|
| 1759 | self.flash(_('You are not the owner of this access code.')) |
---|
| 1760 | return |
---|
| 1761 | self.context.clr_code = pin |
---|
[6770] | 1762 | IWorkflowInfo(self.context).fireTransition('start_clearance') |
---|
[7723] | 1763 | self.flash(_('Clearance process has been started.')) |
---|
[6770] | 1764 | self.redirect(self.url(self.context,'cedit')) |
---|
| 1765 | return |
---|
| 1766 | |
---|
[6695] | 1767 | class StudentClearanceEditFormPage(StudentClearanceManageFormPage): |
---|
| 1768 | """ View to edit student clearance data by student |
---|
| 1769 | """ |
---|
| 1770 | grok.context(IStudent) |
---|
| 1771 | grok.name('cedit') |
---|
| 1772 | grok.require('waeup.handleStudent') |
---|
[7723] | 1773 | label = _('Edit clearance data') |
---|
[6718] | 1774 | |
---|
[7993] | 1775 | @property |
---|
| 1776 | def form_fields(self): |
---|
[8472] | 1777 | if self.context.is_postgrad: |
---|
[8974] | 1778 | form_fields = grok.AutoFields(IPGStudentClearance).omit( |
---|
[8977] | 1779 | 'clearance_locked', 'clr_code') |
---|
[7993] | 1780 | else: |
---|
[8974] | 1781 | form_fields = grok.AutoFields(IUGStudentClearance).omit( |
---|
[8977] | 1782 | 'clearance_locked', 'clr_code') |
---|
[7993] | 1783 | return form_fields |
---|
| 1784 | |
---|
[6718] | 1785 | def update(self): |
---|
| 1786 | if self.context.clearance_locked: |
---|
[7145] | 1787 | emit_lock_message(self) |
---|
[6718] | 1788 | return |
---|
| 1789 | return super(StudentClearanceEditFormPage, self).update() |
---|
[6719] | 1790 | |
---|
[7723] | 1791 | @action(_('Save'), style='primary') |
---|
[6722] | 1792 | def save(self, **data): |
---|
| 1793 | self.applyData(self.context, **data) |
---|
[7723] | 1794 | self.flash(_('Clearance form has been saved.')) |
---|
[6722] | 1795 | return |
---|
| 1796 | |
---|
[7253] | 1797 | def dataNotComplete(self): |
---|
[7642] | 1798 | """To be implemented in the customization package. |
---|
| 1799 | """ |
---|
[7253] | 1800 | return False |
---|
| 1801 | |
---|
[7723] | 1802 | @action(_('Save and request clearance'), style='primary') |
---|
[7186] | 1803 | def requestClearance(self, **data): |
---|
[6722] | 1804 | self.applyData(self.context, **data) |
---|
[7253] | 1805 | if self.dataNotComplete(): |
---|
| 1806 | self.flash(self.dataNotComplete()) |
---|
| 1807 | return |
---|
[7723] | 1808 | self.flash(_('Clearance form has been saved.')) |
---|
[9021] | 1809 | if self.context.clr_code: |
---|
| 1810 | self.redirect(self.url(self.context, 'request_clearance')) |
---|
| 1811 | else: |
---|
| 1812 | # We bypass the request_clearance page if student |
---|
| 1813 | # has been imported in state 'clearance started' and |
---|
| 1814 | # no clr_code was entered before. |
---|
| 1815 | state = IWorkflowState(self.context).getState() |
---|
| 1816 | if state != CLEARANCE: |
---|
| 1817 | # This shouldn't happen, but the application officer |
---|
| 1818 | # might have forgotten to lock the form after changing the state |
---|
| 1819 | self.flash(_('This form cannot be submitted. Wrong state!')) |
---|
| 1820 | return |
---|
| 1821 | IWorkflowInfo(self.context).fireTransition('request_clearance') |
---|
| 1822 | self.flash(_('Clearance has been requested.')) |
---|
| 1823 | self.redirect(self.url(self.context)) |
---|
[6722] | 1824 | return |
---|
| 1825 | |
---|
[7819] | 1826 | class RequestClearancePage(KofaPage): |
---|
[6769] | 1827 | grok.context(IStudent) |
---|
| 1828 | grok.name('request_clearance') |
---|
| 1829 | grok.require('waeup.handleStudent') |
---|
| 1830 | grok.template('enterpin') |
---|
[7723] | 1831 | label = _('Request clearance') |
---|
| 1832 | notice = _('Enter the CLR access code used for starting clearance.') |
---|
[6769] | 1833 | ac_prefix = 'CLR' |
---|
| 1834 | pnav = 4 |
---|
[7723] | 1835 | buttonname = _('Request clearance now') |
---|
[6769] | 1836 | |
---|
| 1837 | def update(self, SUBMIT=None): |
---|
| 1838 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 1839 | self.ac_number = self.request.form.get('ac_number', None) |
---|
| 1840 | if SUBMIT is None: |
---|
| 1841 | return |
---|
| 1842 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
[9021] | 1843 | if self.context.clr_code and self.context.clr_code != pin: |
---|
[7723] | 1844 | self.flash(_("This isn't your CLR access code.")) |
---|
[6769] | 1845 | return |
---|
| 1846 | state = IWorkflowState(self.context).getState() |
---|
| 1847 | if state != CLEARANCE: |
---|
[9021] | 1848 | # This shouldn't happen, but the application officer |
---|
| 1849 | # might have forgotten to lock the form after changing the state |
---|
[7723] | 1850 | self.flash(_('This form cannot be submitted. Wrong state!')) |
---|
[6769] | 1851 | return |
---|
| 1852 | IWorkflowInfo(self.context).fireTransition('request_clearance') |
---|
[7723] | 1853 | self.flash(_('Clearance has been requested.')) |
---|
[6769] | 1854 | self.redirect(self.url(self.context)) |
---|
[6789] | 1855 | return |
---|
[6806] | 1856 | |
---|
[8471] | 1857 | class StartSessionPage(KofaPage): |
---|
[6944] | 1858 | grok.context(IStudentStudyCourse) |
---|
[8471] | 1859 | grok.name('start_session') |
---|
[6944] | 1860 | grok.require('waeup.handleStudent') |
---|
| 1861 | grok.template('enterpin') |
---|
[8471] | 1862 | label = _('Start session') |
---|
[6944] | 1863 | ac_prefix = 'SFE' |
---|
| 1864 | notice = '' |
---|
| 1865 | pnav = 4 |
---|
[8471] | 1866 | buttonname = _('Start now') |
---|
[6944] | 1867 | |
---|
| 1868 | def update(self, SUBMIT=None): |
---|
[9139] | 1869 | if not self.context.is_current: |
---|
| 1870 | emit_lock_message(self) |
---|
| 1871 | return |
---|
| 1872 | super(StartSessionPage, self).update() |
---|
[8471] | 1873 | if not self.context.next_session_allowed: |
---|
| 1874 | self.flash(_("You are not entitled to start session.")) |
---|
[6944] | 1875 | self.redirect(self.url(self.context)) |
---|
| 1876 | return |
---|
| 1877 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 1878 | self.ac_number = self.request.form.get('ac_number', None) |
---|
| 1879 | |
---|
| 1880 | if SUBMIT is None: |
---|
| 1881 | return |
---|
| 1882 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 1883 | code = get_access_code(pin) |
---|
| 1884 | if not code: |
---|
[7723] | 1885 | self.flash(_('Activation code is invalid.')) |
---|
[6944] | 1886 | return |
---|
| 1887 | # Mark pin as used (this also fires a pin related transition) |
---|
| 1888 | if code.state == USED: |
---|
[7723] | 1889 | self.flash(_('Activation code has already been used.')) |
---|
[6944] | 1890 | return |
---|
| 1891 | else: |
---|
[7723] | 1892 | comment = _(u"invalidated") |
---|
[6944] | 1893 | # Here we know that the ac is in state initialized so we do not |
---|
[8471] | 1894 | # expect an error, but the owner might be different |
---|
[6944] | 1895 | if not invalidate_accesscode( |
---|
[8736] | 1896 | pin,comment,self.context.student.student_id): |
---|
[7723] | 1897 | self.flash(_('You are not the owner of this access code.')) |
---|
[6944] | 1898 | return |
---|
[8736] | 1899 | if self.context.student.state == CLEARED: |
---|
| 1900 | IWorkflowInfo(self.context.student).fireTransition( |
---|
[6944] | 1901 | 'pay_first_school_fee') |
---|
[8736] | 1902 | elif self.context.student.state == RETURNING: |
---|
| 1903 | IWorkflowInfo(self.context.student).fireTransition( |
---|
[6944] | 1904 | 'pay_school_fee') |
---|
[8736] | 1905 | elif self.context.student.state == PAID: |
---|
| 1906 | IWorkflowInfo(self.context.student).fireTransition( |
---|
[8471] | 1907 | 'pay_pg_fee') |
---|
| 1908 | self.flash(_('Session started.')) |
---|
[6944] | 1909 | self.redirect(self.url(self.context)) |
---|
| 1910 | return |
---|
| 1911 | |
---|
[7819] | 1912 | class AddStudyLevelFormPage(KofaEditFormPage): |
---|
[6806] | 1913 | """ Page for students to add current study levels |
---|
| 1914 | """ |
---|
| 1915 | grok.context(IStudentStudyCourse) |
---|
| 1916 | grok.name('add') |
---|
| 1917 | grok.require('waeup.handleStudent') |
---|
| 1918 | grok.template('studyleveladdpage') |
---|
| 1919 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 1920 | pnav = 4 |
---|
| 1921 | |
---|
| 1922 | @property |
---|
| 1923 | def label(self): |
---|
| 1924 | studylevelsource = StudyLevelSource().factory |
---|
| 1925 | code = self.context.current_level |
---|
| 1926 | title = studylevelsource.getTitle(self.context, code) |
---|
[7723] | 1927 | return _('Add current level ${a}', mapping = {'a':title}) |
---|
[6806] | 1928 | |
---|
| 1929 | def update(self): |
---|
[9139] | 1930 | if not self.context.is_current: |
---|
| 1931 | emit_lock_message(self) |
---|
| 1932 | return |
---|
[8736] | 1933 | if self.context.student.state != PAID: |
---|
[7145] | 1934 | emit_lock_message(self) |
---|
[6806] | 1935 | return |
---|
| 1936 | super(AddStudyLevelFormPage, self).update() |
---|
| 1937 | return |
---|
| 1938 | |
---|
[7723] | 1939 | @action(_('Create course list now'), style='primary') |
---|
[6806] | 1940 | def addStudyLevel(self, **data): |
---|
[8323] | 1941 | studylevel = createObject(u'waeup.StudentStudyLevel') |
---|
[6806] | 1942 | studylevel.level = self.context.current_level |
---|
| 1943 | studylevel.level_session = self.context.current_session |
---|
| 1944 | try: |
---|
| 1945 | self.context.addStudentStudyLevel( |
---|
| 1946 | self.context.certificate,studylevel) |
---|
| 1947 | except KeyError: |
---|
[7723] | 1948 | self.flash(_('This level exists.')) |
---|
[6806] | 1949 | self.redirect(self.url(self.context)) |
---|
| 1950 | return |
---|
[6808] | 1951 | |
---|
[7819] | 1952 | class StudyLevelEditFormPage(KofaEditFormPage): |
---|
[6808] | 1953 | """ Page to edit the student study level data by students |
---|
| 1954 | """ |
---|
| 1955 | grok.context(IStudentStudyLevel) |
---|
| 1956 | grok.name('edit') |
---|
| 1957 | grok.require('waeup.handleStudent') |
---|
| 1958 | grok.template('studyleveleditpage') |
---|
| 1959 | form_fields = grok.AutoFields(IStudentStudyLevel).omit( |
---|
| 1960 | 'level_session', 'level_verdict') |
---|
| 1961 | pnav = 4 |
---|
[8642] | 1962 | max_credits = 50 |
---|
[6808] | 1963 | |
---|
| 1964 | def update(self): |
---|
[9139] | 1965 | if not self.context.__parent__.is_current: |
---|
| 1966 | emit_lock_message(self) |
---|
| 1967 | return |
---|
[8736] | 1968 | if self.context.student.state != PAID: |
---|
[7539] | 1969 | emit_lock_message(self) |
---|
| 1970 | return |
---|
[6808] | 1971 | super(StudyLevelEditFormPage, self).update() |
---|
| 1972 | datatable.need() |
---|
[7329] | 1973 | warning.need() |
---|
[6808] | 1974 | return |
---|
| 1975 | |
---|
| 1976 | @property |
---|
| 1977 | def label(self): |
---|
[7833] | 1978 | # Here we know that the cookie has been set |
---|
| 1979 | lang = self.request.cookies.get('kofa.language') |
---|
[7811] | 1980 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 1981 | target_language=lang) |
---|
[8920] | 1982 | return _('Edit course list of ${a}', |
---|
[7723] | 1983 | mapping = {'a':level_title}) |
---|
[6808] | 1984 | |
---|
| 1985 | @property |
---|
| 1986 | def total_credits(self): |
---|
| 1987 | total_credits = 0 |
---|
| 1988 | for key, val in self.context.items(): |
---|
| 1989 | total_credits += val.credits |
---|
| 1990 | return total_credits |
---|
| 1991 | |
---|
[8921] | 1992 | @property |
---|
| 1993 | def translated_values(self): |
---|
| 1994 | return translated_values(self) |
---|
| 1995 | |
---|
[7723] | 1996 | @action(_('Add course ticket')) |
---|
[6808] | 1997 | def addCourseTicket(self, **data): |
---|
| 1998 | self.redirect(self.url(self.context, 'ctadd')) |
---|
| 1999 | |
---|
[7723] | 2000 | @jsaction(_('Remove selected tickets')) |
---|
[6808] | 2001 | def delCourseTicket(self, **data): |
---|
| 2002 | form = self.request.form |
---|
| 2003 | if form.has_key('val_id'): |
---|
| 2004 | child_id = form['val_id'] |
---|
| 2005 | else: |
---|
[7723] | 2006 | self.flash(_('No ticket selected.')) |
---|
[6808] | 2007 | self.redirect(self.url(self.context, '@@edit')) |
---|
| 2008 | return |
---|
| 2009 | if not isinstance(child_id, list): |
---|
| 2010 | child_id = [child_id] |
---|
| 2011 | deleted = [] |
---|
| 2012 | for id in child_id: |
---|
[6940] | 2013 | # Students are not allowed to remove core tickets |
---|
[7665] | 2014 | if not self.context[id].mandatory: |
---|
[7723] | 2015 | del self.context[id] |
---|
| 2016 | deleted.append(id) |
---|
[6808] | 2017 | if len(deleted): |
---|
[7723] | 2018 | self.flash(_('Successfully removed: ${a}', |
---|
| 2019 | mapping = {'a':', '.join(deleted)})) |
---|
[6808] | 2020 | self.redirect(self.url(self.context, u'@@edit')) |
---|
| 2021 | return |
---|
| 2022 | |
---|
[7723] | 2023 | @action(_('Register course list'), style='primary') |
---|
[8481] | 2024 | def registerCourses(self, **data): |
---|
[8642] | 2025 | if self.total_credits > self.max_credits: |
---|
| 2026 | self.flash(_('Maximum credits of ${a} exceeded.', |
---|
| 2027 | mapping = {'a':self.max_credits})) |
---|
| 2028 | return |
---|
[8736] | 2029 | IWorkflowInfo(self.context.student).fireTransition( |
---|
[7642] | 2030 | 'register_courses') |
---|
[7723] | 2031 | self.flash(_('Course list has been registered.')) |
---|
[6810] | 2032 | self.redirect(self.url(self.context)) |
---|
| 2033 | return |
---|
| 2034 | |
---|
[6808] | 2035 | class CourseTicketAddFormPage2(CourseTicketAddFormPage): |
---|
| 2036 | """Add a course ticket by student. |
---|
| 2037 | """ |
---|
| 2038 | grok.name('ctadd') |
---|
| 2039 | grok.require('waeup.handleStudent') |
---|
| 2040 | form_fields = grok.AutoFields(ICourseTicketAdd).omit( |
---|
[8141] | 2041 | 'score', 'mandatory', 'automatic', 'carry_over') |
---|
[6808] | 2042 | |
---|
[7539] | 2043 | def update(self): |
---|
[8736] | 2044 | if self.context.student.state != PAID: |
---|
[7539] | 2045 | emit_lock_message(self) |
---|
| 2046 | return |
---|
| 2047 | super(CourseTicketAddFormPage2, self).update() |
---|
| 2048 | return |
---|
| 2049 | |
---|
[7723] | 2050 | @action(_('Add course ticket')) |
---|
[6808] | 2051 | def addCourseTicket(self, **data): |
---|
[7642] | 2052 | # Safety belt |
---|
[8736] | 2053 | if self.context.student.state != PAID: |
---|
[7539] | 2054 | return |
---|
[8325] | 2055 | ticket = createObject(u'waeup.CourseTicket') |
---|
[6808] | 2056 | course = data['course'] |
---|
| 2057 | ticket.automatic = False |
---|
[8920] | 2058 | ticket.carry_over = False |
---|
[6808] | 2059 | try: |
---|
[8920] | 2060 | self.context.addCourseTicket(ticket, course) |
---|
[6808] | 2061 | except KeyError: |
---|
[7723] | 2062 | self.flash(_('The ticket exists.')) |
---|
[6808] | 2063 | return |
---|
[7723] | 2064 | self.flash(_('Successfully added ${a}.', |
---|
| 2065 | mapping = {'a':ticket.code})) |
---|
[6808] | 2066 | self.redirect(self.url(self.context, u'@@edit')) |
---|
| 2067 | return |
---|
[7369] | 2068 | |
---|
| 2069 | |
---|
[7819] | 2070 | class SetPasswordPage(KofaPage): |
---|
| 2071 | grok.context(IKofaObject) |
---|
[7660] | 2072 | grok.name('setpassword') |
---|
| 2073 | grok.require('waeup.Anonymous') |
---|
| 2074 | grok.template('setpassword') |
---|
[7723] | 2075 | label = _('Set password for first-time login') |
---|
[7660] | 2076 | ac_prefix = 'PWD' |
---|
| 2077 | pnav = 0 |
---|
[7738] | 2078 | set_button = _('Set') |
---|
[7660] | 2079 | |
---|
| 2080 | def update(self, SUBMIT=None): |
---|
| 2081 | self.reg_number = self.request.form.get('reg_number', None) |
---|
| 2082 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 2083 | self.ac_number = self.request.form.get('ac_number', None) |
---|
| 2084 | |
---|
| 2085 | if SUBMIT is None: |
---|
| 2086 | return |
---|
| 2087 | hitlist = search(query=self.reg_number, |
---|
| 2088 | searchtype='reg_number', view=self) |
---|
| 2089 | if not hitlist: |
---|
[7723] | 2090 | self.flash(_('No student found.')) |
---|
[7660] | 2091 | return |
---|
| 2092 | if len(hitlist) != 1: # Cannot happen but anyway |
---|
[7723] | 2093 | self.flash(_('More than one student found.')) |
---|
[7660] | 2094 | return |
---|
| 2095 | student = hitlist[0].context |
---|
| 2096 | self.student_id = student.student_id |
---|
| 2097 | student_pw = student.password |
---|
| 2098 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 2099 | code = get_access_code(pin) |
---|
| 2100 | if not code: |
---|
[7723] | 2101 | self.flash(_('Access code is invalid.')) |
---|
[7660] | 2102 | return |
---|
| 2103 | if student_pw and pin == student.adm_code: |
---|
[7723] | 2104 | self.flash(_( |
---|
| 2105 | 'Password has already been set. Your Student Id is ${a}', |
---|
| 2106 | mapping = {'a':self.student_id})) |
---|
[7660] | 2107 | return |
---|
| 2108 | elif student_pw: |
---|
| 2109 | self.flash( |
---|
[7723] | 2110 | _('Password has already been set. You are using the ' + |
---|
| 2111 | 'wrong Access Code.')) |
---|
[7660] | 2112 | return |
---|
| 2113 | # Mark pin as used (this also fires a pin related transition) |
---|
| 2114 | # and set student password |
---|
| 2115 | if code.state == USED: |
---|
[7723] | 2116 | self.flash(_('Access code has already been used.')) |
---|
[7660] | 2117 | return |
---|
| 2118 | else: |
---|
[7723] | 2119 | comment = _(u"invalidated") |
---|
[7660] | 2120 | # Here we know that the ac is in state initialized so we do not |
---|
| 2121 | # expect an exception |
---|
| 2122 | invalidate_accesscode(pin,comment) |
---|
| 2123 | IUserAccount(student).setPassword(self.ac_number) |
---|
| 2124 | student.adm_code = pin |
---|
[7723] | 2125 | self.flash(_('Password has been set. Your Student Id is ${a}', |
---|
| 2126 | mapping = {'a':self.student_id})) |
---|
[7811] | 2127 | return |
---|
[8779] | 2128 | |
---|
| 2129 | class StudentRequestPasswordPage(KofaAddFormPage): |
---|
| 2130 | """Captcha'd registration page for applicants. |
---|
| 2131 | """ |
---|
| 2132 | grok.name('requestpw') |
---|
| 2133 | grok.require('waeup.Anonymous') |
---|
| 2134 | grok.template('requestpw') |
---|
| 2135 | form_fields = grok.AutoFields(IStudentRequestPW).select( |
---|
[8854] | 2136 | 'firstname','number','email') |
---|
[8779] | 2137 | label = _('Request password for first-time login') |
---|
| 2138 | |
---|
| 2139 | def update(self): |
---|
| 2140 | # Handle captcha |
---|
| 2141 | self.captcha = getUtility(ICaptchaManager).getCaptcha() |
---|
| 2142 | self.captcha_result = self.captcha.verify(self.request) |
---|
| 2143 | self.captcha_code = self.captcha.display(self.captcha_result.error_code) |
---|
| 2144 | return |
---|
| 2145 | |
---|
| 2146 | def _redirect(self, email, password, student_id): |
---|
| 2147 | # Forward only email to landing page in base package. |
---|
| 2148 | self.redirect(self.url(self.context, 'requestpw_complete', |
---|
| 2149 | data = dict(email=email))) |
---|
| 2150 | return |
---|
| 2151 | |
---|
| 2152 | def _pw_used(self): |
---|
[8780] | 2153 | # XXX: False if password has not been used. We need an extra |
---|
| 2154 | # attribute which remembers if student logged in. |
---|
[8779] | 2155 | return True |
---|
| 2156 | |
---|
[8854] | 2157 | @action(_('Send login credentials to email address'), style='primary') |
---|
[8779] | 2158 | def get_credentials(self, **data): |
---|
| 2159 | if not self.captcha_result.is_valid: |
---|
| 2160 | # Captcha will display error messages automatically. |
---|
| 2161 | # No need to flash something. |
---|
| 2162 | return |
---|
[8854] | 2163 | number = data.get('number','') |
---|
[8779] | 2164 | firstname = data.get('firstname','') |
---|
| 2165 | cat = getUtility(ICatalog, name='students_catalog') |
---|
| 2166 | results = list( |
---|
[8854] | 2167 | cat.searchResults(reg_number=(number, number))) |
---|
| 2168 | if not results: |
---|
| 2169 | results = list( |
---|
| 2170 | cat.searchResults(matric_number=(number, number))) |
---|
[8779] | 2171 | if results: |
---|
| 2172 | student = results[0] |
---|
| 2173 | if getattr(student,'firstname',None) is None: |
---|
| 2174 | self.flash(_('An error occurred.')) |
---|
| 2175 | return |
---|
| 2176 | elif student.firstname.lower() != firstname.lower(): |
---|
| 2177 | # Don't tell the truth here. Anonymous must not |
---|
| 2178 | # know that a record was found and only the firstname |
---|
| 2179 | # verification failed. |
---|
| 2180 | self.flash(_('No student record found.')) |
---|
| 2181 | return |
---|
| 2182 | elif student.password is not None and self._pw_used: |
---|
| 2183 | self.flash(_('Your password has already been set and used. ' |
---|
| 2184 | 'Please proceed to the login page.')) |
---|
| 2185 | return |
---|
| 2186 | # Store email address but nothing else. |
---|
| 2187 | student.email = data['email'] |
---|
| 2188 | notify(grok.ObjectModifiedEvent(student)) |
---|
| 2189 | else: |
---|
| 2190 | # No record found, this is the truth. |
---|
| 2191 | self.flash(_('No student record found.')) |
---|
| 2192 | return |
---|
| 2193 | |
---|
| 2194 | kofa_utils = getUtility(IKofaUtils) |
---|
| 2195 | password = kofa_utils.genPassword() |
---|
[8857] | 2196 | mandate = PasswordMandate() |
---|
[8853] | 2197 | mandate.params['password'] = password |
---|
[8858] | 2198 | mandate.params['user'] = student |
---|
[8853] | 2199 | site = grok.getSite() |
---|
| 2200 | site['mandates'].addMandate(mandate) |
---|
[8779] | 2201 | # Send email with credentials |
---|
[8853] | 2202 | args = {'mandate_id':mandate.mandate_id} |
---|
| 2203 | mandate_url = self.url(site) + '/mandate?%s' % urlencode(args) |
---|
| 2204 | url_info = u'Confirmation link: %s' % mandate_url |
---|
[8779] | 2205 | msg = _('You have successfully requested a password for the') |
---|
| 2206 | if kofa_utils.sendCredentials(IUserAccount(student), |
---|
[8853] | 2207 | password, url_info, msg): |
---|
[8779] | 2208 | email_sent = student.email |
---|
| 2209 | else: |
---|
| 2210 | email_sent = None |
---|
| 2211 | self._redirect(email=email_sent, password=password, |
---|
| 2212 | student_id=student.student_id) |
---|
[8856] | 2213 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 2214 | self.context.logger.info( |
---|
| 2215 | '%s - %s (%s) - %s' % (ob_class, number, student.student_id, email_sent)) |
---|
[8779] | 2216 | return |
---|
| 2217 | |
---|
| 2218 | class StudentRequestPasswordEmailSent(KofaPage): |
---|
| 2219 | """Landing page after successful password request. |
---|
| 2220 | |
---|
| 2221 | """ |
---|
| 2222 | grok.name('requestpw_complete') |
---|
| 2223 | grok.require('waeup.Public') |
---|
| 2224 | grok.template('requestpwmailsent') |
---|
| 2225 | label = _('Your password request was successful.') |
---|
| 2226 | |
---|
| 2227 | def update(self, email=None, student_id=None, password=None): |
---|
| 2228 | self.email = email |
---|
| 2229 | self.password = password |
---|
| 2230 | self.student_id = student_id |
---|
[8974] | 2231 | return |
---|