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