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