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