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