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