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