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