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