[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 | """ |
---|
| 18 | import sys |
---|
| 19 | import grok |
---|
| 20 | |
---|
| 21 | from datetime import datetime |
---|
| 22 | from zope.formlib.widget import CustomWidgetFactory |
---|
| 23 | from zope.formlib.form import setUpEditWidgets |
---|
| 24 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
---|
| 25 | from zope.traversing.browser import absoluteURL |
---|
[6622] | 26 | from zope.component import ( |
---|
| 27 | createObject,) |
---|
[6621] | 28 | |
---|
| 29 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
| 30 | from reportlab.pdfgen import canvas |
---|
| 31 | from reportlab.lib.units import cm |
---|
| 32 | from reportlab.lib.pagesizes import A4 |
---|
| 33 | from reportlab.lib.styles import getSampleStyleSheet |
---|
| 34 | from reportlab.platypus import (Frame, Paragraph, Image, |
---|
| 35 | Table, Spacer) |
---|
| 36 | from reportlab.platypus.tables import TableStyle |
---|
| 37 | |
---|
| 38 | from waeup.sirp.accesscodes import invalidate_accesscode, get_access_code |
---|
| 39 | from waeup.sirp.accesscodes.workflow import USED |
---|
| 40 | from waeup.sirp.browser import ( |
---|
| 41 | WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage) |
---|
| 42 | from waeup.sirp.browser.breadcrumbs import Breadcrumb |
---|
| 43 | from waeup.sirp.browser.layout import NullValidator |
---|
| 44 | from waeup.sirp.browser.pages import add_local_role, del_local_roles |
---|
| 45 | from waeup.sirp.browser.resources import datepicker, tabs, datatable |
---|
| 46 | from waeup.sirp.browser.viewlets import ( |
---|
[6642] | 47 | ManageActionButton, PrimaryNavTab, |
---|
[6635] | 48 | AddActionButton, ActionButton, PlainActionButton, |
---|
[6621] | 49 | ) |
---|
| 50 | from waeup.sirp.image.browser.widget import ( |
---|
| 51 | ThumbnailWidget, EncodingImageFileWidget, |
---|
| 52 | ) |
---|
| 53 | from waeup.sirp.image.image import createWAeUPImageFile |
---|
[6682] | 54 | from waeup.sirp.interfaces import ( |
---|
| 55 | IWAeUPObject, ILocalRolesAssignable, IUserAccount, |
---|
| 56 | ) |
---|
[6621] | 57 | from waeup.sirp.permissions import get_users_with_local_roles |
---|
| 58 | from waeup.sirp.university.interfaces import ICertificate |
---|
| 59 | from waeup.sirp.widgets.datewidget import ( |
---|
| 60 | FriendlyDateWidget, FriendlyDateDisplayWidget) |
---|
| 61 | from waeup.sirp.widgets.restwidget import ReSTDisplayWidget |
---|
| 62 | from waeup.sirp.widgets.objectwidget import ( |
---|
| 63 | WAeUPObjectWidget, WAeUPObjectDisplayWidget) |
---|
| 64 | from waeup.sirp.students.interfaces import ( |
---|
[6756] | 65 | IStudentsContainer, IStudent, IStudentClearance, IStudentPasswordSetting, |
---|
[6635] | 66 | IStudentPersonal, IStudentBase, IStudentStudyCourse, |
---|
[6694] | 67 | IStudentPayments, IStudentAccommodation, IStudentNavigation, |
---|
[6695] | 68 | IStudentBaseEdit, IStudentClearanceEdit, |
---|
[6621] | 69 | ) |
---|
[6651] | 70 | from waeup.sirp.students.student import Student |
---|
[6626] | 71 | from waeup.sirp.students.catalog import search |
---|
[6699] | 72 | from waeup.sirp.accesscodes import invalidate_accesscode, get_access_code |
---|
| 73 | from waeup.sirp.accesscodes.workflow import USED |
---|
[6722] | 74 | from waeup.sirp.students.workflow import CLEARANCE |
---|
[6621] | 75 | |
---|
| 76 | class StudentsTab(PrimaryNavTab): |
---|
| 77 | """Students tab in primary navigation. |
---|
| 78 | """ |
---|
| 79 | |
---|
| 80 | grok.context(IWAeUPObject) |
---|
| 81 | grok.order(3) |
---|
[6660] | 82 | grok.require('waeup.viewStudent') |
---|
[6621] | 83 | grok.template('primarynavtab') |
---|
| 84 | |
---|
| 85 | pnav = 4 |
---|
| 86 | tab_title = u'Students' |
---|
| 87 | |
---|
| 88 | @property |
---|
| 89 | def link_target(self): |
---|
| 90 | return self.view.application_url('students') |
---|
| 91 | |
---|
[6629] | 92 | class StudentsBreadcrumb(Breadcrumb): |
---|
| 93 | """A breadcrumb for the students container. |
---|
| 94 | """ |
---|
| 95 | grok.context(IStudentsContainer) |
---|
| 96 | title = u'Students' |
---|
| 97 | |
---|
[6635] | 98 | class SudyCourseBreadcrumb(Breadcrumb): |
---|
| 99 | """A breadcrumb for the student study course. |
---|
| 100 | """ |
---|
| 101 | grok.context(IStudentStudyCourse) |
---|
| 102 | title = u'Study Course' |
---|
| 103 | |
---|
| 104 | class PaymentsBreadcrumb(Breadcrumb): |
---|
| 105 | """A breadcrumb for the student payments folder. |
---|
| 106 | """ |
---|
| 107 | grok.context(IStudentPayments) |
---|
| 108 | title = u'Payments' |
---|
| 109 | |
---|
| 110 | class AccommodationBreadcrumb(Breadcrumb): |
---|
| 111 | """A breadcrumb for the student accommodation folder. |
---|
| 112 | """ |
---|
| 113 | grok.context(IStudentAccommodation) |
---|
| 114 | title = u'Accommodation' |
---|
| 115 | |
---|
[6626] | 116 | class StudentsContainerPage(WAeUPPage): |
---|
| 117 | """The standard view for student containers. |
---|
[6621] | 118 | """ |
---|
| 119 | grok.context(IStudentsContainer) |
---|
| 120 | grok.name('index') |
---|
[6660] | 121 | grok.require('waeup.viewStudent') |
---|
[6695] | 122 | grok.template('containerpage') |
---|
[6654] | 123 | label = 'Student Section' |
---|
| 124 | title = 'Students' |
---|
[6642] | 125 | pnav = 4 |
---|
[6621] | 126 | |
---|
[6626] | 127 | def update(self, *args, **kw): |
---|
| 128 | datatable.need() |
---|
| 129 | form = self.request.form |
---|
| 130 | self.hitlist = [] |
---|
| 131 | if 'searchterm' in form and form['searchterm']: |
---|
| 132 | self.searchterm = form['searchterm'] |
---|
| 133 | self.searchtype = form['searchtype'] |
---|
| 134 | elif 'old_searchterm' in form: |
---|
| 135 | self.searchterm = form['old_searchterm'] |
---|
| 136 | self.searchtype = form['old_searchtype'] |
---|
| 137 | else: |
---|
| 138 | if 'search' in form: |
---|
| 139 | self.flash('Empty search string.') |
---|
| 140 | return |
---|
| 141 | self.hitlist = search(query=self.searchterm, |
---|
| 142 | searchtype=self.searchtype, view=self) |
---|
| 143 | if not self.hitlist: |
---|
| 144 | self.flash('No student found.') |
---|
| 145 | return |
---|
| 146 | |
---|
[6699] | 147 | class SetPassword(WAeUPPage): |
---|
| 148 | grok.context(IWAeUPObject) |
---|
| 149 | grok.name('setpassword') |
---|
| 150 | grok.require('waeup.Public') |
---|
| 151 | title = '' |
---|
| 152 | label = 'Set password for first-time login' |
---|
[6758] | 153 | ac_prefix = 'PWD' |
---|
[6715] | 154 | pnav = 0 |
---|
[6699] | 155 | |
---|
| 156 | def update(self, SUBMIT=None): |
---|
[6758] | 157 | self.reg_number = self.request.form.get('reg_number', None) |
---|
| 158 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 159 | self.ac_number = self.request.form.get('ac_number', None) |
---|
[6756] | 160 | |
---|
[6699] | 161 | if SUBMIT is None: |
---|
| 162 | return |
---|
| 163 | hitlist = search(query=self.reg_number, |
---|
| 164 | searchtype='reg_number', view=self) |
---|
| 165 | if not hitlist: |
---|
| 166 | self.flash('No student found.') |
---|
| 167 | return |
---|
| 168 | if len(hitlist) != 1: # Cannot happen but anyway |
---|
| 169 | self.flash('More than one student found.') |
---|
| 170 | return |
---|
[6704] | 171 | student = hitlist[0].context |
---|
| 172 | self.student_id = student.student_id |
---|
| 173 | student_pw = student.password |
---|
[6758] | 174 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
[6699] | 175 | code = get_access_code(pin) |
---|
| 176 | if not code: |
---|
| 177 | self.flash('Access code is invalid.') |
---|
| 178 | return |
---|
[6704] | 179 | if student_pw and pin == student.adm_code: |
---|
| 180 | self.flash('Password has already been set. Your Student Id is %s' |
---|
| 181 | % self.student_id) |
---|
| 182 | return |
---|
| 183 | elif student_pw: |
---|
| 184 | self.flash('Password has already been set.') |
---|
| 185 | return |
---|
[6699] | 186 | # Mark pin as used (this also fires a pin related transition) |
---|
| 187 | # and set student password |
---|
| 188 | if code.state == USED: |
---|
| 189 | self.flash('Access code has already been used.') |
---|
| 190 | return |
---|
| 191 | else: |
---|
[6704] | 192 | comment = u"AC invalidated for %s" % self.student_id |
---|
[6699] | 193 | # Here we know that the ac is in state initialized so we do not |
---|
| 194 | # expect an exception |
---|
| 195 | #import pdb; pdb.set_trace() |
---|
| 196 | invalidate_accesscode(pin,comment) |
---|
[6758] | 197 | IUserAccount(student).setPassword(self.ac_number) |
---|
[6704] | 198 | self.flash('Password has been set. Your Student Id is %s' |
---|
| 199 | % self.student_id) |
---|
[6699] | 200 | return |
---|
| 201 | |
---|
[6626] | 202 | class StudentsContainerManageActionButton(ManageActionButton): |
---|
[6622] | 203 | grok.order(1) |
---|
| 204 | grok.context(IStudentsContainer) |
---|
| 205 | grok.view(StudentsContainerPage) |
---|
| 206 | grok.require('waeup.manageStudents') |
---|
[6647] | 207 | text = 'Manage student section' |
---|
[6622] | 208 | |
---|
[6626] | 209 | |
---|
| 210 | class StudentsContainerManagePage(WAeUPPage): |
---|
| 211 | """The manage page for student containers. |
---|
[6622] | 212 | """ |
---|
| 213 | grok.context(IStudentsContainer) |
---|
| 214 | grok.name('manage') |
---|
| 215 | grok.require('waeup.manageStudents') |
---|
[6695] | 216 | grok.template('containermanagepage') |
---|
[6642] | 217 | pnav = 4 |
---|
[6647] | 218 | title = 'Manage student section' |
---|
[6622] | 219 | |
---|
| 220 | @property |
---|
| 221 | def label(self): |
---|
| 222 | return self.title |
---|
| 223 | |
---|
[6626] | 224 | def update(self, *args, **kw): |
---|
| 225 | datatable.need() |
---|
| 226 | form = self.request.form |
---|
| 227 | self.hitlist = [] |
---|
| 228 | if 'searchterm' in form and form['searchterm']: |
---|
| 229 | self.searchterm = form['searchterm'] |
---|
| 230 | self.searchtype = form['searchtype'] |
---|
| 231 | elif 'old_searchterm' in form: |
---|
| 232 | self.searchterm = form['old_searchterm'] |
---|
| 233 | self.searchtype = form['old_searchtype'] |
---|
| 234 | else: |
---|
| 235 | if 'search' in form: |
---|
| 236 | self.flash('Empty search string.') |
---|
| 237 | return |
---|
| 238 | if not 'entries' in form: |
---|
| 239 | self.hitlist = search(query=self.searchterm, |
---|
| 240 | searchtype=self.searchtype, view=self) |
---|
| 241 | if not self.hitlist: |
---|
| 242 | self.flash('No student found.') |
---|
| 243 | return |
---|
| 244 | entries = form['entries'] |
---|
| 245 | if isinstance(entries, basestring): |
---|
| 246 | entries = [entries] |
---|
| 247 | deleted = [] |
---|
| 248 | for entry in entries: |
---|
| 249 | if 'remove' in form: |
---|
| 250 | del self.context[entry] |
---|
| 251 | deleted.append(entry) |
---|
| 252 | self.hitlist = search(query=self.searchterm, |
---|
| 253 | searchtype=self.searchtype, view=self) |
---|
| 254 | if len(deleted): |
---|
| 255 | self.flash('Successfully removed: %s' % ', '.join(deleted)) |
---|
[6622] | 256 | return |
---|
| 257 | |
---|
[6626] | 258 | class StudentsContainerAddActionButton(AddActionButton): |
---|
| 259 | grok.order(1) |
---|
| 260 | grok.context(IStudentsContainer) |
---|
| 261 | grok.view(StudentsContainerManagePage) |
---|
| 262 | grok.require('waeup.manageStudents') |
---|
| 263 | text = 'Add student' |
---|
| 264 | target = 'addstudent' |
---|
| 265 | |
---|
[6622] | 266 | class StudentAddFormPage(WAeUPAddFormPage): |
---|
| 267 | """Add-form to add a student. |
---|
| 268 | """ |
---|
| 269 | grok.context(IStudentsContainer) |
---|
| 270 | grok.require('waeup.manageStudents') |
---|
| 271 | grok.name('addstudent') |
---|
| 272 | grok.template('studentaddpage') |
---|
| 273 | form_fields = grok.AutoFields(IStudent) |
---|
| 274 | title = 'Students' |
---|
| 275 | label = 'Add student' |
---|
[6642] | 276 | pnav = 4 |
---|
[6622] | 277 | |
---|
| 278 | @grok.action('Create student record') |
---|
| 279 | def addStudent(self, **data): |
---|
| 280 | student = createObject(u'waeup.Student') |
---|
| 281 | self.applyData(student, **data) |
---|
[6652] | 282 | self.context.addStudent(student) |
---|
[6626] | 283 | self.flash('Student record created.') |
---|
[6651] | 284 | self.redirect(self.url(self.context[student.student_id], 'index')) |
---|
[6622] | 285 | return |
---|
| 286 | |
---|
[6631] | 287 | class StudentBaseDisplayFormPage(WAeUPDisplayFormPage): |
---|
| 288 | """ Page to display student base data |
---|
| 289 | """ |
---|
[6622] | 290 | grok.context(IStudent) |
---|
| 291 | grok.name('index') |
---|
[6660] | 292 | grok.require('waeup.viewStudent') |
---|
[6695] | 293 | grok.template('basepage') |
---|
[6756] | 294 | form_fields = grok.AutoFields(IStudentBase).omit('password') |
---|
[6642] | 295 | pnav = 4 |
---|
| 296 | title = 'Base Data' |
---|
[6622] | 297 | |
---|
| 298 | @property |
---|
| 299 | def label(self): |
---|
[6631] | 300 | return '%s: Base Data' % self.context.name |
---|
| 301 | |
---|
[6699] | 302 | @property |
---|
| 303 | def hasPassword(self): |
---|
| 304 | if self.context.password: |
---|
| 305 | return 'set' |
---|
| 306 | return 'unset' |
---|
| 307 | |
---|
[6631] | 308 | class StudentBaseManageActionButton(ManageActionButton): |
---|
| 309 | grok.order(1) |
---|
| 310 | grok.context(IStudent) |
---|
| 311 | grok.view(StudentBaseDisplayFormPage) |
---|
| 312 | grok.require('waeup.manageStudents') |
---|
[6695] | 313 | text = 'Manage' |
---|
[6631] | 314 | target = 'edit_base' |
---|
| 315 | |
---|
| 316 | class StudentBaseManageFormPage(WAeUPEditFormPage): |
---|
| 317 | """ View to edit student base data |
---|
| 318 | """ |
---|
| 319 | grok.context(IStudent) |
---|
| 320 | grok.name('edit_base') |
---|
| 321 | grok.require('waeup.manageStudents') |
---|
| 322 | form_fields = grok.AutoFields(IStudentBase).omit('student_id') |
---|
[6695] | 323 | grok.template('basemanagepage') |
---|
| 324 | label = 'Manage base data' |
---|
[6642] | 325 | title = 'Base Data' |
---|
| 326 | pnav = 4 |
---|
[6631] | 327 | |
---|
[6638] | 328 | def update(self): |
---|
| 329 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
| 330 | super(StudentBaseManageFormPage, self).update() |
---|
| 331 | self.wf_info = IWorkflowInfo(self.context) |
---|
| 332 | return |
---|
| 333 | |
---|
| 334 | def getTransitions(self): |
---|
| 335 | """Return a list of dicts of allowed transition ids and titles. |
---|
| 336 | |
---|
| 337 | Each list entry provides keys ``name`` and ``title`` for |
---|
| 338 | internal name and (human readable) title of a single |
---|
| 339 | transition. |
---|
| 340 | """ |
---|
| 341 | allowed_transitions = self.wf_info.getManualTransitions() |
---|
| 342 | return [dict(name='', title='No transition')] +[ |
---|
| 343 | dict(name=x, title=y) for x, y in allowed_transitions] |
---|
| 344 | |
---|
| 345 | @grok.action('Save') |
---|
| 346 | def save(self, **data): |
---|
[6701] | 347 | form = self.request.form |
---|
| 348 | ob_class = self.__implemented__.__name__.replace('waeup.sirp.','') |
---|
| 349 | if form.has_key('password') and form['password']: |
---|
| 350 | if form['password'] != form['control_password']: |
---|
| 351 | self.flash('Passwords do not match.') |
---|
| 352 | return |
---|
| 353 | IUserAccount(self.context).setPassword(form['password']) |
---|
| 354 | self.context.loggerInfo(ob_class, 'password changed') |
---|
[6638] | 355 | changed_fields = self.applyData(self.context, **data) |
---|
| 356 | changed_fields = changed_fields.values() |
---|
| 357 | fields_string = '+'.join(' + '.join(str(i) for i in b) for b in changed_fields) |
---|
| 358 | self.context._p_changed = True |
---|
| 359 | if form.has_key('transition') and form['transition']: |
---|
| 360 | transition_id = form['transition'] |
---|
| 361 | self.wf_info.fireTransition(transition_id) |
---|
| 362 | self.flash('Form has been saved.') |
---|
[6644] | 363 | if fields_string: |
---|
| 364 | self.context.loggerInfo(ob_class, 'saved: % s' % fields_string) |
---|
[6638] | 365 | return |
---|
| 366 | |
---|
[6631] | 367 | class StudentClearanceDisplayFormPage(WAeUPDisplayFormPage): |
---|
| 368 | """ Page to display student clearance data |
---|
| 369 | """ |
---|
| 370 | grok.context(IStudent) |
---|
| 371 | grok.name('view_clearance') |
---|
[6660] | 372 | grok.require('waeup.viewStudent') |
---|
[6695] | 373 | form_fields = grok.AutoFields(IStudentClearance).omit('clearance_locked') |
---|
[6650] | 374 | form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
[6642] | 375 | title = 'Clearance Data' |
---|
| 376 | pnav = 4 |
---|
[6631] | 377 | |
---|
| 378 | @property |
---|
| 379 | def label(self): |
---|
| 380 | return '%s: Clearance Data' % self.context.name |
---|
| 381 | |
---|
| 382 | class StudentClearanceManageActionButton(ManageActionButton): |
---|
| 383 | grok.order(1) |
---|
| 384 | grok.context(IStudent) |
---|
| 385 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 386 | grok.require('waeup.manageStudents') |
---|
[6695] | 387 | text = 'Manage' |
---|
[6631] | 388 | target = 'edit_clearance' |
---|
| 389 | |
---|
| 390 | class StudentClearanceManageFormPage(WAeUPEditFormPage): |
---|
| 391 | """ Page to edit student clearance data |
---|
| 392 | """ |
---|
| 393 | grok.context(IStudent) |
---|
| 394 | grok.name('edit_clearance') |
---|
[6649] | 395 | grok.require('waeup.manageStudents') |
---|
[6631] | 396 | form_fields = grok.AutoFields(IStudentClearance) |
---|
[6695] | 397 | label = 'Manage clearance data' |
---|
[6642] | 398 | title = 'Clearance Data' |
---|
| 399 | pnav = 4 |
---|
[6631] | 400 | |
---|
[6650] | 401 | form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 402 | |
---|
| 403 | def update(self): |
---|
| 404 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
| 405 | return super(StudentClearanceManageFormPage, self).update() |
---|
| 406 | |
---|
[6695] | 407 | @grok.action('Save') |
---|
| 408 | def save(self, **data): |
---|
| 409 | changed_fields = self.applyData(self.context, **data) |
---|
| 410 | changed_fields = changed_fields.values() |
---|
| 411 | fields_string = '+'.join(' + '.join(str(i) for i in b) for b in changed_fields) |
---|
| 412 | self.context._p_changed = True |
---|
| 413 | form = self.request.form |
---|
| 414 | self.flash('Form has been saved.') |
---|
| 415 | ob_class = self.__implemented__.__name__.replace('waeup.sirp.','') |
---|
| 416 | if fields_string: |
---|
| 417 | self.context.loggerInfo(ob_class, 'saved: % s' % fields_string) |
---|
| 418 | return |
---|
| 419 | |
---|
[6631] | 420 | class StudentPersonalDisplayFormPage(WAeUPDisplayFormPage): |
---|
| 421 | """ Page to display student personal data |
---|
| 422 | """ |
---|
| 423 | grok.context(IStudent) |
---|
| 424 | grok.name('view_personal') |
---|
[6660] | 425 | grok.require('waeup.viewStudent') |
---|
[6631] | 426 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
[6642] | 427 | title = 'Personal Data' |
---|
| 428 | pnav = 4 |
---|
[6631] | 429 | |
---|
| 430 | @property |
---|
| 431 | def label(self): |
---|
| 432 | return '%s: Personal Data' % self.context.name |
---|
| 433 | |
---|
| 434 | class StudentPersonalManageActionButton(ManageActionButton): |
---|
| 435 | grok.order(1) |
---|
| 436 | grok.context(IStudent) |
---|
| 437 | grok.view(StudentPersonalDisplayFormPage) |
---|
| 438 | grok.require('waeup.manageStudents') |
---|
[6695] | 439 | text = 'Manage' |
---|
[6631] | 440 | target = 'edit_personal' |
---|
| 441 | |
---|
| 442 | class StudentPersonalManageFormPage(WAeUPEditFormPage): |
---|
| 443 | """ Page to edit student clearance data |
---|
| 444 | """ |
---|
| 445 | grok.context(IStudent) |
---|
| 446 | grok.name('edit_personal') |
---|
[6660] | 447 | grok.require('waeup.viewStudent') |
---|
[6631] | 448 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
[6695] | 449 | label = 'Manage personal data' |
---|
[6642] | 450 | title = 'Personal Data' |
---|
| 451 | pnav = 4 |
---|
[6631] | 452 | |
---|
[6635] | 453 | class StudyCourseDisplayFormPage(WAeUPDisplayFormPage): |
---|
| 454 | """ Page to display the student study course data |
---|
| 455 | """ |
---|
| 456 | grok.context(IStudentStudyCourse) |
---|
| 457 | grok.name('index') |
---|
[6660] | 458 | grok.require('waeup.viewStudent') |
---|
[6635] | 459 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 460 | #grok.template('studycoursepage') |
---|
[6642] | 461 | title = 'Study Course' |
---|
| 462 | pnav = 4 |
---|
[6635] | 463 | |
---|
| 464 | @property |
---|
| 465 | def label(self): |
---|
[6642] | 466 | return '%s: Study Course' % self.context.__parent__.name |
---|
[6635] | 467 | |
---|
[6649] | 468 | class StudyCourseManageActionButton(ManageActionButton): |
---|
| 469 | grok.order(1) |
---|
| 470 | grok.context(IStudentStudyCourse) |
---|
| 471 | grok.view(StudyCourseDisplayFormPage) |
---|
| 472 | grok.require('waeup.manageStudents') |
---|
[6695] | 473 | text = 'Manage' |
---|
[6649] | 474 | target = 'edit' |
---|
| 475 | |
---|
| 476 | class StudyCourseManageFormPage(WAeUPEditFormPage): |
---|
| 477 | """ Page to edit the student study course data |
---|
| 478 | """ |
---|
| 479 | grok.context(IStudentStudyCourse) |
---|
| 480 | grok.name('edit') |
---|
| 481 | grok.require('waeup.manageStudents') |
---|
| 482 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 483 | title = 'Study Course' |
---|
[6695] | 484 | label = 'Manage study course' |
---|
[6649] | 485 | pnav = 4 |
---|
| 486 | |
---|
[6635] | 487 | class PaymentsDisplayFormPage(WAeUPDisplayFormPage): |
---|
| 488 | """ Page to display the student payments |
---|
| 489 | """ |
---|
| 490 | grok.context(IStudentPayments) |
---|
| 491 | grok.name('index') |
---|
[6660] | 492 | grok.require('waeup.viewStudent') |
---|
[6635] | 493 | form_fields = grok.AutoFields(IStudentPayments) |
---|
| 494 | #grok.template('paymentspage') |
---|
[6642] | 495 | title = 'Payments' |
---|
| 496 | pnav = 4 |
---|
[6635] | 497 | |
---|
| 498 | @property |
---|
| 499 | def label(self): |
---|
| 500 | return '%s: Payments' % self.context.__parent__.name |
---|
| 501 | |
---|
| 502 | class AccommodationDisplayFormPage(WAeUPDisplayFormPage): |
---|
| 503 | """ Page to display the student accommodation data |
---|
| 504 | """ |
---|
| 505 | grok.context(IStudentAccommodation) |
---|
| 506 | grok.name('index') |
---|
[6660] | 507 | grok.require('waeup.viewStudent') |
---|
[6635] | 508 | form_fields = grok.AutoFields(IStudentAccommodation) |
---|
| 509 | #grok.template('accommodationpage') |
---|
[6642] | 510 | title = 'Accommodation' |
---|
| 511 | pnav = 4 |
---|
[6635] | 512 | |
---|
| 513 | @property |
---|
| 514 | def label(self): |
---|
| 515 | return '%s: Accommodation Data' % self.context.__parent__.name |
---|
[6637] | 516 | |
---|
| 517 | class StudentHistoryPage(WAeUPPage): |
---|
| 518 | """ Page to display student clearance data |
---|
| 519 | """ |
---|
| 520 | grok.context(IStudent) |
---|
| 521 | grok.name('history') |
---|
[6660] | 522 | grok.require('waeup.viewStudent') |
---|
[6637] | 523 | grok.template('studenthistory') |
---|
[6642] | 524 | title = 'History' |
---|
| 525 | pnav = 4 |
---|
[6637] | 526 | |
---|
| 527 | @property |
---|
| 528 | def label(self): |
---|
| 529 | return '%s: History' % self.context.name |
---|
[6694] | 530 | |
---|
| 531 | # Pages for students only |
---|
| 532 | |
---|
| 533 | class StudentBaseEditActionButton(ManageActionButton): |
---|
| 534 | grok.order(1) |
---|
| 535 | grok.context(IStudent) |
---|
| 536 | grok.view(StudentBaseDisplayFormPage) |
---|
| 537 | grok.require('waeup.handleStudent') |
---|
| 538 | text = 'Change password' |
---|
| 539 | target = 'bedit' |
---|
| 540 | |
---|
[6756] | 541 | class StudentPasswordSetting(grok.Adapter): |
---|
| 542 | """Adapt IStudent to data needed for password settings. |
---|
| 543 | |
---|
| 544 | We provide password getters/setters for the attached context (an |
---|
| 545 | IStudent object) that cooperate seamless with the usual |
---|
| 546 | formlib/form techniques. |
---|
| 547 | """ |
---|
| 548 | grok.context(IStudent) |
---|
| 549 | grok.provides(IStudentPasswordSetting) |
---|
| 550 | |
---|
| 551 | def __init__(self, context): |
---|
| 552 | self.name = context.name |
---|
| 553 | self.password_repeat = context.password |
---|
| 554 | self.context = context |
---|
| 555 | return |
---|
| 556 | |
---|
| 557 | def getPassword(self): |
---|
| 558 | return self.context.password |
---|
| 559 | |
---|
| 560 | def setPassword(self, password): |
---|
| 561 | IUserAccount(self.context).setPassword(password) |
---|
| 562 | return |
---|
| 563 | |
---|
| 564 | password = property(getPassword, setPassword) |
---|
| 565 | |
---|
[6694] | 566 | class StudentBaseEditFormPage(WAeUPEditFormPage): |
---|
| 567 | """ View to edit student base data by student |
---|
| 568 | """ |
---|
| 569 | grok.context(IStudent) |
---|
| 570 | grok.name('bedit') |
---|
| 571 | grok.require('waeup.handleStudent') |
---|
[6756] | 572 | #form_fields = grok.AutoFields(IStudentBaseEdit).omit( |
---|
| 573 | # 'student_id', 'reg_number', 'matric_number') |
---|
| 574 | form_fields = grok.AutoFields(IStudentPasswordSetting) |
---|
[6695] | 575 | grok.template('baseeditpage') |
---|
[6694] | 576 | label = 'Change password' |
---|
| 577 | title = 'Base Data' |
---|
| 578 | pnav = 4 |
---|
| 579 | |
---|
| 580 | def update(self): |
---|
| 581 | super(StudentBaseEditFormPage, self).update() |
---|
| 582 | self.wf_info = IWorkflowInfo(self.context) |
---|
| 583 | return |
---|
| 584 | |
---|
[6756] | 585 | def onFailure(self, action, data, errors): |
---|
| 586 | new_status = [] |
---|
| 587 | other_errors = False |
---|
| 588 | for error in errors: |
---|
| 589 | msg = getattr(error, 'message', '') |
---|
| 590 | if isinstance(msg, basestring) and msg != '': |
---|
| 591 | new_status.append(msg) |
---|
| 592 | else: |
---|
| 593 | other_errors = True |
---|
| 594 | if other_errors: |
---|
| 595 | if new_status: |
---|
| 596 | new_status.append('see below for further errors') |
---|
| 597 | else: |
---|
| 598 | new_status.append('See below for details.') |
---|
| 599 | if new_status: |
---|
| 600 | self.status = u'There were errors: %s' % ', '.join(new_status) |
---|
| 601 | return |
---|
| 602 | |
---|
| 603 | @grok.action('Save', failure=onFailure) |
---|
[6694] | 604 | def save(self, **data): |
---|
[6701] | 605 | form = self.request.form |
---|
| 606 | ob_class = self.__implemented__.__name__.replace('waeup.sirp.','') |
---|
[6756] | 607 | changed_fields = self.applyData(self.context, **data) |
---|
| 608 | # Turn list of lists into single list |
---|
| 609 | changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) |
---|
| 610 | changed_fields = [x for x in changed_fields |
---|
| 611 | if not x.startswith('password')] |
---|
| 612 | if form.get('form.password', u'') != u'': |
---|
[6701] | 613 | self.context.loggerInfo(ob_class, 'password changed') |
---|
[6756] | 614 | self.flash('Form has been saved.') |
---|
| 615 | fields_string = ' + '.join(changed_fields) |
---|
[6694] | 616 | if fields_string: |
---|
| 617 | self.context.loggerInfo(ob_class, 'saved: % s' % fields_string) |
---|
| 618 | return |
---|
[6695] | 619 | |
---|
[6719] | 620 | class StudentClearanceStartActionButton(ManageActionButton): |
---|
| 621 | grok.order(1) |
---|
| 622 | grok.context(IStudent) |
---|
| 623 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 624 | grok.require('waeup.handleStudent') |
---|
| 625 | icon = 'actionicon_start.png' |
---|
| 626 | text = 'Start clearance' |
---|
| 627 | target = 'start_clearance' |
---|
| 628 | |
---|
| 629 | @property |
---|
| 630 | def target_url(self): |
---|
| 631 | if self.context.state != 'admitted': |
---|
| 632 | return '' |
---|
| 633 | return self.view.url(self.view.context, self.target) |
---|
| 634 | |
---|
[6695] | 635 | class StudentClearanceEditActionButton(ManageActionButton): |
---|
| 636 | grok.order(1) |
---|
| 637 | grok.context(IStudent) |
---|
| 638 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 639 | grok.require('waeup.handleStudent') |
---|
[6722] | 640 | text = 'Edit' |
---|
[6695] | 641 | target = 'cedit' |
---|
| 642 | |
---|
[6717] | 643 | @property |
---|
| 644 | def target_url(self): |
---|
| 645 | if self.context.clearance_locked: |
---|
| 646 | return '' |
---|
| 647 | return self.view.url(self.view.context, self.target) |
---|
| 648 | |
---|
[6695] | 649 | class StudentClearanceEditFormPage(StudentClearanceManageFormPage): |
---|
| 650 | """ View to edit student clearance data by student |
---|
| 651 | """ |
---|
| 652 | grok.context(IStudent) |
---|
| 653 | grok.name('cedit') |
---|
| 654 | grok.require('waeup.handleStudent') |
---|
[6756] | 655 | form_fields = grok.AutoFields( |
---|
| 656 | IStudentClearanceEdit).omit('clearance_locked') |
---|
[6722] | 657 | label = 'Edit clearance data' |
---|
[6695] | 658 | title = 'Clearance Data' |
---|
| 659 | pnav = 4 |
---|
| 660 | form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year') |
---|
[6718] | 661 | |
---|
| 662 | def emitLockMessage(self): |
---|
| 663 | self.flash('The requested form is locked (read-only).') |
---|
| 664 | self.redirect(self.url(self.context)) |
---|
| 665 | return |
---|
| 666 | |
---|
| 667 | def update(self): |
---|
| 668 | if self.context.clearance_locked: |
---|
| 669 | self.emitLockMessage() |
---|
| 670 | return |
---|
| 671 | datepicker.need() |
---|
| 672 | return super(StudentClearanceEditFormPage, self).update() |
---|
[6719] | 673 | |
---|
[6722] | 674 | @grok.action('Save') |
---|
| 675 | def save(self, **data): |
---|
| 676 | self.applyData(self.context, **data) |
---|
| 677 | self.flash('Form has been saved.') |
---|
| 678 | return |
---|
| 679 | |
---|
| 680 | @grok.action('Save and request clearance') |
---|
| 681 | def requestclearance(self, **data): |
---|
| 682 | self.applyData(self.context, **data) |
---|
| 683 | self.context._p_changed = True |
---|
| 684 | #if self.dataNotComplete(): |
---|
| 685 | # self.flash(self.dataNotComplete()) |
---|
| 686 | # return |
---|
| 687 | state = IWorkflowState(self.context).getState() |
---|
| 688 | # This shouldn't happen, but the application officer |
---|
| 689 | # might have forgotten to lock the form after changing the state |
---|
| 690 | if state != CLEARANCE: |
---|
| 691 | self.flash('This form cannot be submitted. Wrong state!') |
---|
| 692 | return |
---|
| 693 | IWorkflowInfo(self.context).fireTransition('request_clearance') |
---|
| 694 | self.flash('Clearance has been requested.') |
---|
| 695 | self.redirect(self.url(self.context)) |
---|
| 696 | return |
---|
| 697 | |
---|
[6719] | 698 | class StartClearance(WAeUPPage): |
---|
| 699 | grok.context(IStudent) |
---|
| 700 | grok.name('start_clearance') |
---|
| 701 | grok.require('waeup.handleStudent') |
---|
| 702 | grok.template('enterpin') |
---|
| 703 | title = 'Start clearance' |
---|
| 704 | label = 'Start clearance' |
---|
[6759] | 705 | ac_prefix = 'CLR' |
---|
[6719] | 706 | pnav = 4 |
---|
| 707 | buttonname = 'Start' |
---|
| 708 | |
---|
| 709 | def update(self, SUBMIT=None): |
---|
[6759] | 710 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 711 | self.ac_number = self.request.form.get('ac_number', None) |
---|
[6719] | 712 | |
---|
| 713 | if SUBMIT is None: |
---|
| 714 | return |
---|
[6759] | 715 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
[6719] | 716 | code = get_access_code(pin) |
---|
| 717 | if not code: |
---|
| 718 | self.flash('Access code is invalid.') |
---|
| 719 | return |
---|
| 720 | # Mark pin as used (this also fires a pin related transition) |
---|
| 721 | # and fire transition start_clearance |
---|
| 722 | if code.state == USED: |
---|
| 723 | self.flash('Access code has already been used.') |
---|
| 724 | return |
---|
| 725 | else: |
---|
| 726 | comment = u"AC invalidated for %s" % self.context.student_id |
---|
| 727 | # Here we know that the ac is in state initialized so we do not |
---|
| 728 | # expect an exception |
---|
| 729 | invalidate_accesscode(pin,comment) |
---|
[6720] | 730 | IWorkflowInfo(self.context).fireTransition('start_clearance') |
---|
[6719] | 731 | self.flash('Clearance process is started.') |
---|
[6720] | 732 | self.redirect(self.url(self.context)) |
---|
[6756] | 733 | return |
---|