[7191] | 1 | ## $Id: browser.py 10256 2013-05-30 18:02:31Z henrik $ |
---|
| 2 | ## |
---|
[6621] | 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
| 18 | """UI components for students and related components. |
---|
| 19 | """ |
---|
[7006] | 20 | import sys |
---|
[6621] | 21 | import grok |
---|
[7275] | 22 | from urllib import urlencode |
---|
[7256] | 23 | from datetime import datetime |
---|
[7015] | 24 | from zope.event import notify |
---|
[7723] | 25 | from zope.i18n import translate |
---|
[6996] | 26 | from zope.catalog.interfaces import ICatalog |
---|
[7386] | 27 | from zope.component import queryUtility, getUtility, createObject |
---|
[9467] | 28 | from zope.schema.interfaces import ConstraintNotSatisfied, RequiredMissing |
---|
[7386] | 29 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[10080] | 30 | from zope.security import checkPermission |
---|
[6621] | 31 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
[7811] | 32 | from waeup.kofa.accesscodes import ( |
---|
[8420] | 33 | invalidate_accesscode, get_access_code) |
---|
[7811] | 34 | from waeup.kofa.accesscodes.workflow import USED |
---|
[9217] | 35 | from waeup.kofa.browser.layout import ( |
---|
[7819] | 36 | KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage, |
---|
[9217] | 37 | KofaForm, NullValidator) |
---|
[9797] | 38 | from waeup.kofa.browser.breadcrumbs import Breadcrumb |
---|
[9822] | 39 | from waeup.kofa.browser.pages import ContactAdminForm, ExportCSVView, doll_up |
---|
[9797] | 40 | from waeup.kofa.browser.resources import ( |
---|
| 41 | datepicker, datatable, tabs, warning, toggleall) |
---|
[7811] | 42 | from waeup.kofa.browser.layout import jsaction, action, UtilityView |
---|
[8779] | 43 | from waeup.kofa.browser.interfaces import ICaptchaManager |
---|
[9797] | 44 | from waeup.kofa.hostels.hostel import NOT_OCCUPIED |
---|
[7811] | 45 | from waeup.kofa.interfaces import ( |
---|
[7819] | 46 | IKofaObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm, |
---|
[9797] | 47 | IKofaUtils, IUniversity, IObjectHistory, academic_sessions, ICSVExporter, |
---|
[9833] | 48 | academic_sessions_vocab, IJobManager, IDataCenter) |
---|
[7811] | 49 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[8170] | 50 | from waeup.kofa.widgets.datewidget import ( |
---|
| 51 | FriendlyDateWidget, FriendlyDateDisplayWidget, |
---|
| 52 | FriendlyDatetimeDisplayWidget) |
---|
[9797] | 53 | from waeup.kofa.mandates.mandate import PasswordMandate |
---|
[9806] | 54 | from waeup.kofa.university.interfaces import ( |
---|
| 55 | IDepartment, ICertificate, ICourse) |
---|
[9797] | 56 | from waeup.kofa.university.department import ( |
---|
| 57 | VirtualDepartmentExportJobContainer,) |
---|
[10247] | 58 | from waeup.kofa.university.facultiescontainer import ( |
---|
| 59 | VirtualFacultiesExportJobContainer, FacultiesContainer) |
---|
[9842] | 60 | from waeup.kofa.university.certificate import ( |
---|
| 61 | VirtualCertificateExportJobContainer,) |
---|
[9843] | 62 | from waeup.kofa.university.course import ( |
---|
| 63 | VirtualCourseExportJobContainer,) |
---|
[9797] | 64 | from waeup.kofa.university.vocabularies import course_levels |
---|
[9813] | 65 | from waeup.kofa.utils.batching import VirtualExportJobContainer |
---|
[9797] | 66 | from waeup.kofa.utils.helpers import get_current_principal, to_timezone |
---|
[7868] | 67 | from waeup.kofa.widgets.restwidget import ReSTDisplayWidget |
---|
[7811] | 68 | from waeup.kofa.students.interfaces import ( |
---|
[7993] | 69 | IStudentsContainer, IStudent, |
---|
| 70 | IUGStudentClearance,IPGStudentClearance, |
---|
[9563] | 71 | IStudentPersonal, IStudentPersonalEdit, IStudentBase, IStudentStudyCourse, |
---|
[10250] | 72 | IStudentStudyCourseTransfer, IStudentStudyCourseTranscript, |
---|
[7538] | 73 | IStudentAccommodation, IStudentStudyLevel, |
---|
[6877] | 74 | ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer, |
---|
[9864] | 75 | IStudentOnlinePayment, IStudentPreviousPayment, IStudentBalancePayment, |
---|
[9148] | 76 | IBedTicket, IStudentsUtils, IStudentRequestPW |
---|
[6621] | 77 | ) |
---|
[9806] | 78 | from waeup.kofa.students.catalog import search, StudentQueryResultItem |
---|
[9804] | 79 | from waeup.kofa.students.export import EXPORTER_NAMES |
---|
[9797] | 80 | from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket |
---|
| 81 | from waeup.kofa.students.vocabularies import StudyLevelSource |
---|
[8779] | 82 | from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID, |
---|
[9028] | 83 | CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED, |
---|
| 84 | FORBIDDEN_POSTGRAD_TRANS) |
---|
[6621] | 85 | |
---|
[9797] | 86 | |
---|
[8779] | 87 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
| 88 | |
---|
[8737] | 89 | # Save function used for save methods in pages |
---|
| 90 | def msave(view, **data): |
---|
| 91 | changed_fields = view.applyData(view.context, **data) |
---|
| 92 | # Turn list of lists into single list |
---|
| 93 | if changed_fields: |
---|
| 94 | changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) |
---|
| 95 | # Inform catalog if certificate has changed |
---|
| 96 | # (applyData does this only for the context) |
---|
| 97 | if 'certificate' in changed_fields: |
---|
| 98 | notify(grok.ObjectModifiedEvent(view.context.student)) |
---|
| 99 | fields_string = ' + '.join(changed_fields) |
---|
| 100 | view.flash(_('Form has been saved.')) |
---|
| 101 | if fields_string: |
---|
| 102 | view.context.writeLogMessage(view, 'saved: %s' % fields_string) |
---|
| 103 | return |
---|
| 104 | |
---|
[7145] | 105 | def emit_lock_message(view): |
---|
[7642] | 106 | """Flash a lock message. |
---|
| 107 | """ |
---|
[7723] | 108 | view.flash(_('The requested form is locked (read-only).')) |
---|
[7133] | 109 | view.redirect(view.url(view.context)) |
---|
| 110 | return |
---|
| 111 | |
---|
[8921] | 112 | def translated_values(view): |
---|
[9685] | 113 | """Translate course ticket attribute values to be displayed on |
---|
| 114 | studylevel pages. |
---|
| 115 | """ |
---|
[8921] | 116 | lang = view.request.cookies.get('kofa.language') |
---|
| 117 | for value in view.context.values(): |
---|
[9328] | 118 | # We have to unghostify (according to Tres Seaver) the __dict__ |
---|
| 119 | # by activating the object, otherwise value_dict will be empty |
---|
| 120 | # when calling the first time. |
---|
[9330] | 121 | value._p_activate() |
---|
[8921] | 122 | value_dict = dict([i for i in value.__dict__.items()]) |
---|
[9698] | 123 | value_dict['removable_by_student'] = value.removable_by_student |
---|
[8921] | 124 | value_dict['mandatory'] = translate(str(value.mandatory), 'zope', |
---|
| 125 | target_language=lang) |
---|
| 126 | value_dict['carry_over'] = translate(str(value.carry_over), 'zope', |
---|
| 127 | target_language=lang) |
---|
| 128 | value_dict['automatic'] = translate(str(value.automatic), 'zope', |
---|
| 129 | target_language=lang) |
---|
[9685] | 130 | value_dict['grade'] = value.grade |
---|
| 131 | value_dict['weight'] = value.weight |
---|
[8921] | 132 | yield value_dict |
---|
| 133 | |
---|
[9814] | 134 | def clearance_disabled_message(student): |
---|
| 135 | try: |
---|
| 136 | session_config = grok.getSite()[ |
---|
| 137 | 'configuration'][str(student.current_session)] |
---|
| 138 | except KeyError: |
---|
| 139 | return _('Session configuration object is not available.') |
---|
| 140 | if not session_config.clearance_enabled: |
---|
| 141 | return _('Clearance is disabled for this session.') |
---|
| 142 | return None |
---|
| 143 | |
---|
[9895] | 144 | |
---|
| 145 | def addCourseTicket(view, course=None): |
---|
| 146 | students_utils = getUtility(IStudentsUtils) |
---|
| 147 | ticket = createObject(u'waeup.CourseTicket') |
---|
| 148 | ticket.automatic = False |
---|
| 149 | ticket.carry_over = False |
---|
| 150 | max_credits = students_utils.maxCreditsExceeded(view.context, course) |
---|
| 151 | if max_credits: |
---|
| 152 | view.flash(_( |
---|
| 153 | 'Total credits exceed ${a}.', |
---|
| 154 | mapping = {'a': max_credits})) |
---|
| 155 | return False |
---|
| 156 | try: |
---|
| 157 | view.context.addCourseTicket(ticket, course) |
---|
| 158 | except KeyError: |
---|
| 159 | view.flash(_('The ticket exists.')) |
---|
| 160 | return False |
---|
| 161 | view.flash(_('Successfully added ${a}.', |
---|
| 162 | mapping = {'a':ticket.code})) |
---|
[9924] | 163 | view.context.writeLogMessage( |
---|
| 164 | view,'added: %s|%s|%s' % ( |
---|
[9925] | 165 | ticket.code, ticket.level, ticket.level_session)) |
---|
[9895] | 166 | return True |
---|
| 167 | |
---|
[6629] | 168 | class StudentsBreadcrumb(Breadcrumb): |
---|
| 169 | """A breadcrumb for the students container. |
---|
| 170 | """ |
---|
| 171 | grok.context(IStudentsContainer) |
---|
[7723] | 172 | title = _('Students') |
---|
[6629] | 173 | |
---|
[7459] | 174 | @property |
---|
| 175 | def target(self): |
---|
| 176 | user = get_current_principal() |
---|
| 177 | if getattr(user, 'user_type', None) == 'student': |
---|
| 178 | return None |
---|
| 179 | return self.viewname |
---|
| 180 | |
---|
[6818] | 181 | class StudentBreadcrumb(Breadcrumb): |
---|
| 182 | """A breadcrumb for the student container. |
---|
| 183 | """ |
---|
| 184 | grok.context(IStudent) |
---|
| 185 | |
---|
| 186 | def title(self): |
---|
[7364] | 187 | return self.context.display_fullname |
---|
[6818] | 188 | |
---|
[6635] | 189 | class SudyCourseBreadcrumb(Breadcrumb): |
---|
| 190 | """A breadcrumb for the student study course. |
---|
| 191 | """ |
---|
| 192 | grok.context(IStudentStudyCourse) |
---|
| 193 | |
---|
[9140] | 194 | def title(self): |
---|
| 195 | if self.context.is_current: |
---|
| 196 | return _('Study Course') |
---|
| 197 | else: |
---|
| 198 | return _('Previous Study Course') |
---|
| 199 | |
---|
[6635] | 200 | class PaymentsBreadcrumb(Breadcrumb): |
---|
| 201 | """A breadcrumb for the student payments folder. |
---|
| 202 | """ |
---|
[6859] | 203 | grok.context(IStudentPaymentsContainer) |
---|
[7723] | 204 | title = _('Payments') |
---|
[6635] | 205 | |
---|
[6870] | 206 | class OnlinePaymentBreadcrumb(Breadcrumb): |
---|
[7251] | 207 | """A breadcrumb for payments. |
---|
[6870] | 208 | """ |
---|
[6877] | 209 | grok.context(IStudentOnlinePayment) |
---|
[6870] | 210 | |
---|
| 211 | @property |
---|
| 212 | def title(self): |
---|
| 213 | return self.context.p_id |
---|
| 214 | |
---|
[6635] | 215 | class AccommodationBreadcrumb(Breadcrumb): |
---|
| 216 | """A breadcrumb for the student accommodation folder. |
---|
| 217 | """ |
---|
| 218 | grok.context(IStudentAccommodation) |
---|
[7723] | 219 | title = _('Accommodation') |
---|
[6635] | 220 | |
---|
[6994] | 221 | class BedTicketBreadcrumb(Breadcrumb): |
---|
| 222 | """A breadcrumb for bed tickets. |
---|
| 223 | """ |
---|
| 224 | grok.context(IBedTicket) |
---|
[7009] | 225 | |
---|
[6994] | 226 | @property |
---|
| 227 | def title(self): |
---|
[7723] | 228 | return _('Bed Ticket ${a}', |
---|
| 229 | mapping = {'a':self.context.getSessionString()}) |
---|
[6994] | 230 | |
---|
[6776] | 231 | class StudyLevelBreadcrumb(Breadcrumb): |
---|
| 232 | """A breadcrumb for course lists. |
---|
| 233 | """ |
---|
| 234 | grok.context(IStudentStudyLevel) |
---|
| 235 | |
---|
| 236 | @property |
---|
| 237 | def title(self): |
---|
[7834] | 238 | return self.context.level_title |
---|
[6776] | 239 | |
---|
[7819] | 240 | class StudentsContainerPage(KofaPage): |
---|
[6626] | 241 | """The standard view for student containers. |
---|
[6621] | 242 | """ |
---|
| 243 | grok.context(IStudentsContainer) |
---|
| 244 | grok.name('index') |
---|
[7240] | 245 | grok.require('waeup.viewStudentsContainer') |
---|
[6695] | 246 | grok.template('containerpage') |
---|
[7723] | 247 | label = _('Student Section') |
---|
[7735] | 248 | search_button = _('Search') |
---|
[6642] | 249 | pnav = 4 |
---|
[6621] | 250 | |
---|
[6626] | 251 | def update(self, *args, **kw): |
---|
| 252 | datatable.need() |
---|
| 253 | form = self.request.form |
---|
| 254 | self.hitlist = [] |
---|
[9795] | 255 | if form.get('searchtype', None) == 'suspended': |
---|
| 256 | self.searchtype = form['searchtype'] |
---|
| 257 | self.searchterm = None |
---|
| 258 | elif 'searchterm' in form and form['searchterm']: |
---|
[6626] | 259 | self.searchterm = form['searchterm'] |
---|
| 260 | self.searchtype = form['searchtype'] |
---|
| 261 | elif 'old_searchterm' in form: |
---|
| 262 | self.searchterm = form['old_searchterm'] |
---|
| 263 | self.searchtype = form['old_searchtype'] |
---|
| 264 | else: |
---|
| 265 | if 'search' in form: |
---|
[7745] | 266 | self.flash(_('Empty search string')) |
---|
[6626] | 267 | return |
---|
[7068] | 268 | if self.searchtype == 'current_session': |
---|
[8081] | 269 | try: |
---|
| 270 | self.searchterm = int(self.searchterm) |
---|
| 271 | except ValueError: |
---|
[8404] | 272 | self.flash(_('Only year dates allowed (e.g. 2011).')) |
---|
[8081] | 273 | return |
---|
[6626] | 274 | self.hitlist = search(query=self.searchterm, |
---|
| 275 | searchtype=self.searchtype, view=self) |
---|
| 276 | if not self.hitlist: |
---|
[8404] | 277 | self.flash(_('No student found.')) |
---|
[6626] | 278 | return |
---|
| 279 | |
---|
[7819] | 280 | class StudentsContainerManagePage(KofaPage): |
---|
[6626] | 281 | """The manage page for student containers. |
---|
[6622] | 282 | """ |
---|
| 283 | grok.context(IStudentsContainer) |
---|
| 284 | grok.name('manage') |
---|
[7136] | 285 | grok.require('waeup.manageStudent') |
---|
[6695] | 286 | grok.template('containermanagepage') |
---|
[6642] | 287 | pnav = 4 |
---|
[7723] | 288 | label = _('Manage student section') |
---|
[7735] | 289 | search_button = _('Search') |
---|
| 290 | remove_button = _('Remove selected') |
---|
[6622] | 291 | |
---|
[6626] | 292 | def update(self, *args, **kw): |
---|
| 293 | datatable.need() |
---|
[6820] | 294 | toggleall.need() |
---|
[7329] | 295 | warning.need() |
---|
[6626] | 296 | form = self.request.form |
---|
| 297 | self.hitlist = [] |
---|
[9795] | 298 | if form.get('searchtype', None) == 'suspended': |
---|
| 299 | self.searchtype = form['searchtype'] |
---|
| 300 | self.searchterm = None |
---|
| 301 | elif 'searchterm' in form and form['searchterm']: |
---|
[6626] | 302 | self.searchterm = form['searchterm'] |
---|
| 303 | self.searchtype = form['searchtype'] |
---|
| 304 | elif 'old_searchterm' in form: |
---|
| 305 | self.searchterm = form['old_searchterm'] |
---|
| 306 | self.searchtype = form['old_searchtype'] |
---|
| 307 | else: |
---|
| 308 | if 'search' in form: |
---|
[7745] | 309 | self.flash(_('Empty search string')) |
---|
[6626] | 310 | return |
---|
[8082] | 311 | if self.searchtype == 'current_session': |
---|
| 312 | try: |
---|
| 313 | self.searchterm = int(self.searchterm) |
---|
| 314 | except ValueError: |
---|
| 315 | self.flash('Only year dates allowed (e.g. 2011).') |
---|
| 316 | return |
---|
[6626] | 317 | if not 'entries' in form: |
---|
| 318 | self.hitlist = search(query=self.searchterm, |
---|
| 319 | searchtype=self.searchtype, view=self) |
---|
| 320 | if not self.hitlist: |
---|
[7723] | 321 | self.flash(_('No student found.')) |
---|
[7459] | 322 | if 'remove' in form: |
---|
[7723] | 323 | self.flash(_('No item selected.')) |
---|
[6626] | 324 | return |
---|
| 325 | entries = form['entries'] |
---|
| 326 | if isinstance(entries, basestring): |
---|
| 327 | entries = [entries] |
---|
| 328 | deleted = [] |
---|
| 329 | for entry in entries: |
---|
| 330 | if 'remove' in form: |
---|
| 331 | del self.context[entry] |
---|
| 332 | deleted.append(entry) |
---|
| 333 | self.hitlist = search(query=self.searchterm, |
---|
| 334 | searchtype=self.searchtype, view=self) |
---|
| 335 | if len(deleted): |
---|
[7723] | 336 | self.flash(_('Successfully removed: ${a}', |
---|
| 337 | mapping = {'a':', '.join(deleted)})) |
---|
[6622] | 338 | return |
---|
| 339 | |
---|
[7819] | 340 | class StudentAddFormPage(KofaAddFormPage): |
---|
[6622] | 341 | """Add-form to add a student. |
---|
| 342 | """ |
---|
| 343 | grok.context(IStudentsContainer) |
---|
[7136] | 344 | grok.require('waeup.manageStudent') |
---|
[6622] | 345 | grok.name('addstudent') |
---|
[7357] | 346 | form_fields = grok.AutoFields(IStudent).select( |
---|
[7520] | 347 | 'firstname', 'middlename', 'lastname', 'reg_number') |
---|
[7723] | 348 | label = _('Add student') |
---|
[6642] | 349 | pnav = 4 |
---|
[6622] | 350 | |
---|
[7723] | 351 | @action(_('Create student record'), style='primary') |
---|
[6622] | 352 | def addStudent(self, **data): |
---|
| 353 | student = createObject(u'waeup.Student') |
---|
| 354 | self.applyData(student, **data) |
---|
[6652] | 355 | self.context.addStudent(student) |
---|
[7723] | 356 | self.flash(_('Student record created.')) |
---|
[6651] | 357 | self.redirect(self.url(self.context[student.student_id], 'index')) |
---|
[6622] | 358 | return |
---|
| 359 | |
---|
[9338] | 360 | class LoginAsStudentStep1(KofaEditFormPage): |
---|
| 361 | """ View to temporarily set a student password. |
---|
| 362 | """ |
---|
| 363 | grok.context(IStudent) |
---|
| 364 | grok.name('loginasstep1') |
---|
| 365 | grok.require('waeup.loginAsStudent') |
---|
| 366 | grok.template('loginasstep1') |
---|
| 367 | pnav = 4 |
---|
| 368 | |
---|
| 369 | def label(self): |
---|
| 370 | return _(u'Set temporary password for ${a}', |
---|
| 371 | mapping = {'a':self.context.display_fullname}) |
---|
| 372 | |
---|
| 373 | @action('Set password now', style='primary') |
---|
| 374 | def setPassword(self, *args, **data): |
---|
| 375 | kofa_utils = getUtility(IKofaUtils) |
---|
| 376 | password = kofa_utils.genPassword() |
---|
| 377 | self.context.setTempPassword(self.request.principal.id, password) |
---|
| 378 | self.context.writeLogMessage( |
---|
| 379 | self, 'temp_password generated: %s' % password) |
---|
| 380 | args = {'password':password} |
---|
| 381 | self.redirect(self.url(self.context) + |
---|
| 382 | '/loginasstep2?%s' % urlencode(args)) |
---|
| 383 | return |
---|
| 384 | |
---|
| 385 | class LoginAsStudentStep2(KofaPage): |
---|
| 386 | """ View to temporarily login as student with a temporary password. |
---|
| 387 | """ |
---|
| 388 | grok.context(IStudent) |
---|
| 389 | grok.name('loginasstep2') |
---|
| 390 | grok.require('waeup.Public') |
---|
| 391 | grok.template('loginasstep2') |
---|
| 392 | login_button = _('Login now') |
---|
| 393 | pnav = 4 |
---|
| 394 | |
---|
| 395 | def label(self): |
---|
| 396 | return _(u'Login as ${a}', |
---|
| 397 | mapping = {'a':self.context.student_id}) |
---|
| 398 | |
---|
| 399 | def update(self, SUBMIT=None, password=None): |
---|
| 400 | self.password = password |
---|
| 401 | if SUBMIT is not None: |
---|
| 402 | self.flash(_('You successfully logged in as student.')) |
---|
| 403 | self.redirect(self.url(self.context)) |
---|
| 404 | return |
---|
| 405 | |
---|
[7819] | 406 | class StudentBaseDisplayFormPage(KofaDisplayFormPage): |
---|
[6631] | 407 | """ Page to display student base data |
---|
| 408 | """ |
---|
[6622] | 409 | grok.context(IStudent) |
---|
| 410 | grok.name('index') |
---|
[6660] | 411 | grok.require('waeup.viewStudent') |
---|
[6695] | 412 | grok.template('basepage') |
---|
[9702] | 413 | form_fields = grok.AutoFields(IStudentBase).omit( |
---|
| 414 | 'password', 'suspended', 'suspended_comment') |
---|
[6642] | 415 | pnav = 4 |
---|
[6622] | 416 | |
---|
| 417 | @property |
---|
| 418 | def label(self): |
---|
[8983] | 419 | if self.context.suspended: |
---|
[9124] | 420 | return _('${a}: Base Data (account deactivated)', |
---|
[8983] | 421 | mapping = {'a':self.context.display_fullname}) |
---|
| 422 | return _('${a}: Base Data', |
---|
[7723] | 423 | mapping = {'a':self.context.display_fullname}) |
---|
[6631] | 424 | |
---|
[6699] | 425 | @property |
---|
| 426 | def hasPassword(self): |
---|
| 427 | if self.context.password: |
---|
[7723] | 428 | return _('set') |
---|
| 429 | return _('unset') |
---|
[6699] | 430 | |
---|
[9141] | 431 | class StudentBasePDFFormPage(KofaDisplayFormPage): |
---|
| 432 | """ Page to display student base data in pdf files. |
---|
| 433 | """ |
---|
| 434 | |
---|
[10250] | 435 | def __init__(self, context, request, omit_fields=()): |
---|
[9374] | 436 | self.omit_fields = omit_fields |
---|
| 437 | super(StudentBasePDFFormPage, self).__init__(context, request) |
---|
| 438 | |
---|
| 439 | @property |
---|
| 440 | def form_fields(self): |
---|
| 441 | form_fields = grok.AutoFields(IStudentBase) |
---|
| 442 | for field in self.omit_fields: |
---|
| 443 | form_fields = form_fields.omit(field) |
---|
| 444 | return form_fields |
---|
| 445 | |
---|
[7229] | 446 | class ContactStudentForm(ContactAdminForm): |
---|
| 447 | grok.context(IStudent) |
---|
[7230] | 448 | grok.name('contactstudent') |
---|
[7275] | 449 | grok.require('waeup.viewStudent') |
---|
[7229] | 450 | pnav = 4 |
---|
| 451 | form_fields = grok.AutoFields(IContactForm).select('subject', 'body') |
---|
| 452 | |
---|
[9484] | 453 | def update(self, subject=u'', body=u''): |
---|
[9857] | 454 | super(ContactStudentForm, self).update() |
---|
[7275] | 455 | self.form_fields.get('subject').field.default = subject |
---|
[9484] | 456 | self.form_fields.get('body').field.default = body |
---|
[9857] | 457 | return |
---|
[7275] | 458 | |
---|
[7229] | 459 | def label(self): |
---|
[7723] | 460 | return _(u'Send message to ${a}', |
---|
| 461 | mapping = {'a':self.context.display_fullname}) |
---|
[7229] | 462 | |
---|
[7459] | 463 | @action('Send message now', style='primary') |
---|
[7229] | 464 | def send(self, *args, **data): |
---|
[7234] | 465 | try: |
---|
[7403] | 466 | email = self.request.principal.email |
---|
[7234] | 467 | except AttributeError: |
---|
[7403] | 468 | email = self.config.email_admin |
---|
| 469 | usertype = getattr(self.request.principal, |
---|
| 470 | 'user_type', 'system').title() |
---|
[7819] | 471 | kofa_utils = getUtility(IKofaUtils) |
---|
[7811] | 472 | success = kofa_utils.sendContactForm( |
---|
[7403] | 473 | self.request.principal.title,email, |
---|
| 474 | self.context.display_fullname,self.context.email, |
---|
| 475 | self.request.principal.id,usertype, |
---|
| 476 | self.config.name, |
---|
| 477 | data['body'],data['subject']) |
---|
[7229] | 478 | if success: |
---|
[7723] | 479 | self.flash(_('Your message has been sent.')) |
---|
[7229] | 480 | else: |
---|
[7723] | 481 | self.flash(_('An smtp server error occurred.')) |
---|
[7229] | 482 | return |
---|
| 483 | |
---|
[9191] | 484 | class ExportPDFAdmissionSlipPage(UtilityView, grok.View): |
---|
| 485 | """Deliver a PDF Admission slip. |
---|
| 486 | """ |
---|
| 487 | grok.context(IStudent) |
---|
| 488 | grok.name('admission_slip.pdf') |
---|
| 489 | grok.require('waeup.viewStudent') |
---|
| 490 | prefix = 'form' |
---|
| 491 | |
---|
| 492 | form_fields = grok.AutoFields(IStudentBase).select('student_id', 'reg_number') |
---|
| 493 | |
---|
| 494 | @property |
---|
| 495 | def label(self): |
---|
| 496 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 497 | return translate(_('Admission Letter of'), |
---|
| 498 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 499 | + ' %s' % self.context.display_fullname |
---|
| 500 | |
---|
| 501 | def render(self): |
---|
| 502 | students_utils = getUtility(IStudentsUtils) |
---|
| 503 | return students_utils.renderPDFAdmissionLetter(self, |
---|
| 504 | self.context.student) |
---|
| 505 | |
---|
[7819] | 506 | class StudentBaseManageFormPage(KofaEditFormPage): |
---|
[7133] | 507 | """ View to manage student base data |
---|
[6631] | 508 | """ |
---|
| 509 | grok.context(IStudent) |
---|
[7133] | 510 | grok.name('manage_base') |
---|
[7136] | 511 | grok.require('waeup.manageStudent') |
---|
[9124] | 512 | form_fields = grok.AutoFields(IStudentBase).omit( |
---|
| 513 | 'student_id', 'adm_code', 'suspended') |
---|
[6695] | 514 | grok.template('basemanagepage') |
---|
[7723] | 515 | label = _('Manage base data') |
---|
[6642] | 516 | pnav = 4 |
---|
[6631] | 517 | |
---|
[6638] | 518 | def update(self): |
---|
| 519 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
[7134] | 520 | tabs.need() |
---|
[7490] | 521 | self.tab1 = self.tab2 = '' |
---|
| 522 | qs = self.request.get('QUERY_STRING', '') |
---|
| 523 | if not qs: |
---|
| 524 | qs = 'tab1' |
---|
| 525 | setattr(self, qs, 'active') |
---|
[6638] | 526 | super(StudentBaseManageFormPage, self).update() |
---|
| 527 | self.wf_info = IWorkflowInfo(self.context) |
---|
| 528 | return |
---|
| 529 | |
---|
[7723] | 530 | @action(_('Save'), style='primary') |
---|
[6638] | 531 | def save(self, **data): |
---|
[6701] | 532 | form = self.request.form |
---|
[6790] | 533 | password = form.get('password', None) |
---|
| 534 | password_ctl = form.get('control_password', None) |
---|
| 535 | if password: |
---|
[7147] | 536 | validator = getUtility(IPasswordValidator) |
---|
| 537 | errors = validator.validate_password(password, password_ctl) |
---|
| 538 | if errors: |
---|
| 539 | self.flash( ' '.join(errors)) |
---|
| 540 | return |
---|
| 541 | changed_fields = self.applyData(self.context, **data) |
---|
[6771] | 542 | # Turn list of lists into single list |
---|
| 543 | if changed_fields: |
---|
| 544 | changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) |
---|
[7147] | 545 | else: |
---|
| 546 | changed_fields = [] |
---|
| 547 | if password: |
---|
[9273] | 548 | # Now we know that the form has no errors and can set password |
---|
[7147] | 549 | IUserAccount(self.context).setPassword(password) |
---|
| 550 | changed_fields.append('password') |
---|
| 551 | fields_string = ' + '.join(changed_fields) |
---|
[7723] | 552 | self.flash(_('Form has been saved.')) |
---|
[6644] | 553 | if fields_string: |
---|
[8735] | 554 | self.context.writeLogMessage(self, 'saved: % s' % fields_string) |
---|
[6638] | 555 | return |
---|
| 556 | |
---|
[9273] | 557 | class StudentTriggerTransitionFormPage(KofaEditFormPage): |
---|
| 558 | """ View to manage student base data |
---|
| 559 | """ |
---|
| 560 | grok.context(IStudent) |
---|
| 561 | grok.name('trigtrans') |
---|
| 562 | grok.require('waeup.triggerTransition') |
---|
| 563 | grok.template('trigtrans') |
---|
| 564 | label = _('Trigger registration transition') |
---|
| 565 | pnav = 4 |
---|
| 566 | |
---|
| 567 | def getTransitions(self): |
---|
| 568 | """Return a list of dicts of allowed transition ids and titles. |
---|
| 569 | |
---|
| 570 | Each list entry provides keys ``name`` and ``title`` for |
---|
| 571 | internal name and (human readable) title of a single |
---|
| 572 | transition. |
---|
| 573 | """ |
---|
| 574 | wf_info = IWorkflowInfo(self.context) |
---|
| 575 | allowed_transitions = [t for t in wf_info.getManualTransitions() |
---|
| 576 | if not t[0].startswith('pay')] |
---|
[10155] | 577 | if self.context.is_postgrad and not self.context.is_special_postgrad: |
---|
[9273] | 578 | allowed_transitions = [t for t in allowed_transitions |
---|
| 579 | if not t[0] in FORBIDDEN_POSTGRAD_TRANS] |
---|
| 580 | return [dict(name='', title=_('No transition'))] +[ |
---|
| 581 | dict(name=x, title=y) for x, y in allowed_transitions] |
---|
| 582 | |
---|
| 583 | @action(_('Save'), style='primary') |
---|
| 584 | def save(self, **data): |
---|
| 585 | form = self.request.form |
---|
[9701] | 586 | if 'transition' in form and form['transition']: |
---|
[9273] | 587 | transition_id = form['transition'] |
---|
| 588 | wf_info = IWorkflowInfo(self.context) |
---|
| 589 | wf_info.fireTransition(transition_id) |
---|
| 590 | return |
---|
| 591 | |
---|
[9124] | 592 | class StudentActivatePage(UtilityView, grok.View): |
---|
| 593 | """ Activate student account |
---|
| 594 | """ |
---|
| 595 | grok.context(IStudent) |
---|
| 596 | grok.name('activate') |
---|
| 597 | grok.require('waeup.manageStudent') |
---|
| 598 | |
---|
| 599 | def update(self): |
---|
| 600 | self.context.suspended = False |
---|
| 601 | self.context.writeLogMessage(self, 'account activated') |
---|
| 602 | history = IObjectHistory(self.context) |
---|
| 603 | history.addMessage('Student account activated') |
---|
| 604 | self.flash(_('Student account has been activated.')) |
---|
| 605 | self.redirect(self.url(self.context)) |
---|
| 606 | return |
---|
| 607 | |
---|
| 608 | def render(self): |
---|
| 609 | return |
---|
| 610 | |
---|
| 611 | class StudentDeactivatePage(UtilityView, grok.View): |
---|
| 612 | """ Deactivate student account |
---|
| 613 | """ |
---|
| 614 | grok.context(IStudent) |
---|
| 615 | grok.name('deactivate') |
---|
| 616 | grok.require('waeup.manageStudent') |
---|
| 617 | |
---|
| 618 | def update(self): |
---|
| 619 | self.context.suspended = True |
---|
| 620 | self.context.writeLogMessage(self, 'account deactivated') |
---|
| 621 | history = IObjectHistory(self.context) |
---|
| 622 | history.addMessage('Student account deactivated') |
---|
| 623 | self.flash(_('Student account has been deactivated.')) |
---|
| 624 | self.redirect(self.url(self.context)) |
---|
| 625 | return |
---|
| 626 | |
---|
| 627 | def render(self): |
---|
| 628 | return |
---|
| 629 | |
---|
[7819] | 630 | class StudentClearanceDisplayFormPage(KofaDisplayFormPage): |
---|
[6631] | 631 | """ Page to display student clearance data |
---|
| 632 | """ |
---|
| 633 | grok.context(IStudent) |
---|
| 634 | grok.name('view_clearance') |
---|
[6660] | 635 | grok.require('waeup.viewStudent') |
---|
[6642] | 636 | pnav = 4 |
---|
[6631] | 637 | |
---|
| 638 | @property |
---|
[8099] | 639 | def separators(self): |
---|
| 640 | return getUtility(IStudentsUtils).SEPARATORS_DICT |
---|
| 641 | |
---|
| 642 | @property |
---|
[7993] | 643 | def form_fields(self): |
---|
[8472] | 644 | if self.context.is_postgrad: |
---|
[8977] | 645 | form_fields = grok.AutoFields( |
---|
| 646 | IPGStudentClearance).omit('clearance_locked') |
---|
[7993] | 647 | else: |
---|
[8977] | 648 | form_fields = grok.AutoFields( |
---|
| 649 | IUGStudentClearance).omit('clearance_locked') |
---|
[9486] | 650 | if not getattr(self.context, 'officer_comment'): |
---|
| 651 | form_fields = form_fields.omit('officer_comment') |
---|
[9484] | 652 | else: |
---|
[9486] | 653 | form_fields['officer_comment'].custom_widget = BytesDisplayWidget |
---|
[7993] | 654 | return form_fields |
---|
| 655 | |
---|
| 656 | @property |
---|
[6631] | 657 | def label(self): |
---|
[7723] | 658 | return _('${a}: Clearance Data', |
---|
| 659 | mapping = {'a':self.context.display_fullname}) |
---|
[6631] | 660 | |
---|
[7277] | 661 | class ExportPDFClearanceSlipPage(grok.View): |
---|
| 662 | """Deliver a PDF slip of the context. |
---|
| 663 | """ |
---|
| 664 | grok.context(IStudent) |
---|
[9452] | 665 | grok.name('clearance_slip.pdf') |
---|
[7277] | 666 | grok.require('waeup.viewStudent') |
---|
| 667 | prefix = 'form' |
---|
[9702] | 668 | omit_fields = ( |
---|
| 669 | 'password', 'suspended', 'phone', |
---|
[10256] | 670 | 'adm_code', 'suspended_comment', |
---|
| 671 | 'date_of_birth') |
---|
[7277] | 672 | |
---|
| 673 | @property |
---|
[7993] | 674 | def form_fields(self): |
---|
[8472] | 675 | if self.context.is_postgrad: |
---|
[8977] | 676 | form_fields = grok.AutoFields( |
---|
| 677 | IPGStudentClearance).omit('clearance_locked') |
---|
[7993] | 678 | else: |
---|
[8977] | 679 | form_fields = grok.AutoFields( |
---|
| 680 | IUGStudentClearance).omit('clearance_locked') |
---|
[9486] | 681 | if not getattr(self.context, 'officer_comment'): |
---|
| 682 | form_fields = form_fields.omit('officer_comment') |
---|
[7993] | 683 | return form_fields |
---|
| 684 | |
---|
| 685 | @property |
---|
[7723] | 686 | def title(self): |
---|
[7819] | 687 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 688 | return translate(_('Clearance Data'), 'waeup.kofa', |
---|
[7723] | 689 | target_language=portal_language) |
---|
| 690 | |
---|
| 691 | @property |
---|
[7277] | 692 | def label(self): |
---|
[7819] | 693 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9026] | 694 | return translate(_('Clearance Slip of'), |
---|
[7811] | 695 | 'waeup.kofa', target_language=portal_language) \ |
---|
[7723] | 696 | + ' %s' % self.context.display_fullname |
---|
[7277] | 697 | |
---|
[9969] | 698 | # XXX: not used in waeup.kofa and thus not tested |
---|
[9010] | 699 | def _signatures(self): |
---|
[9548] | 700 | isStudent = getattr( |
---|
| 701 | self.request.principal, 'user_type', None) == 'student' |
---|
| 702 | if not isStudent and self.context.state in (CLEARED, ): |
---|
[9969] | 703 | return ([_('Student Signature')], |
---|
| 704 | [_('Clearance Officer Signature')]) |
---|
[9010] | 705 | return |
---|
| 706 | |
---|
[9555] | 707 | def _sigsInFooter(self): |
---|
[9548] | 708 | isStudent = getattr( |
---|
| 709 | self.request.principal, 'user_type', None) == 'student' |
---|
| 710 | if not isStudent and self.context.state in (CLEARED, ): |
---|
[9555] | 711 | return (_('Date, Student Signature'), |
---|
| 712 | _('Date, Clearance Officer Signature'), |
---|
| 713 | ) |
---|
[9557] | 714 | return () |
---|
[9548] | 715 | |
---|
[7277] | 716 | def render(self): |
---|
[9141] | 717 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[9375] | 718 | self.request, self.omit_fields) |
---|
[7277] | 719 | students_utils = getUtility(IStudentsUtils) |
---|
| 720 | return students_utils.renderPDF( |
---|
[9452] | 721 | self, 'clearance_slip.pdf', |
---|
[9548] | 722 | self.context.student, studentview, signatures=self._signatures(), |
---|
[10250] | 723 | sigs_in_footer=self._sigsInFooter(), |
---|
| 724 | omit_fields=self.omit_fields) |
---|
[7277] | 725 | |
---|
[7819] | 726 | class StudentClearanceManageFormPage(KofaEditFormPage): |
---|
[8120] | 727 | """ Page to manage student clearance data |
---|
[6631] | 728 | """ |
---|
| 729 | grok.context(IStudent) |
---|
[8119] | 730 | grok.name('manage_clearance') |
---|
[7136] | 731 | grok.require('waeup.manageStudent') |
---|
[7134] | 732 | grok.template('clearanceeditpage') |
---|
[7723] | 733 | label = _('Manage clearance data') |
---|
[6642] | 734 | pnav = 4 |
---|
[6650] | 735 | |
---|
[7993] | 736 | @property |
---|
[8099] | 737 | def separators(self): |
---|
| 738 | return getUtility(IStudentsUtils).SEPARATORS_DICT |
---|
| 739 | |
---|
| 740 | @property |
---|
[7993] | 741 | def form_fields(self): |
---|
[8472] | 742 | if self.context.is_postgrad: |
---|
[8977] | 743 | form_fields = grok.AutoFields(IPGStudentClearance).omit('clr_code') |
---|
[7993] | 744 | else: |
---|
[8977] | 745 | form_fields = grok.AutoFields(IUGStudentClearance).omit('clr_code') |
---|
[7993] | 746 | return form_fields |
---|
| 747 | |
---|
[6650] | 748 | def update(self): |
---|
| 749 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
[7134] | 750 | tabs.need() |
---|
[7490] | 751 | self.tab1 = self.tab2 = '' |
---|
| 752 | qs = self.request.get('QUERY_STRING', '') |
---|
| 753 | if not qs: |
---|
| 754 | qs = 'tab1' |
---|
| 755 | setattr(self, qs, 'active') |
---|
[6650] | 756 | return super(StudentClearanceManageFormPage, self).update() |
---|
| 757 | |
---|
[7723] | 758 | @action(_('Save'), style='primary') |
---|
[6695] | 759 | def save(self, **data): |
---|
[6762] | 760 | msave(self, **data) |
---|
[6695] | 761 | return |
---|
| 762 | |
---|
[7459] | 763 | class StudentClearPage(UtilityView, grok.View): |
---|
[7158] | 764 | """ Clear student by clearance officer |
---|
| 765 | """ |
---|
| 766 | grok.context(IStudent) |
---|
| 767 | grok.name('clear') |
---|
| 768 | grok.require('waeup.clearStudent') |
---|
| 769 | |
---|
| 770 | def update(self): |
---|
[9814] | 771 | if clearance_disabled_message(self.context): |
---|
| 772 | self.flash(clearance_disabled_message(self.context)) |
---|
| 773 | self.redirect(self.url(self.context,'view_clearance')) |
---|
| 774 | return |
---|
[7158] | 775 | if self.context.state == REQUESTED: |
---|
| 776 | IWorkflowInfo(self.context).fireTransition('clear') |
---|
[7723] | 777 | self.flash(_('Student has been cleared.')) |
---|
[7158] | 778 | else: |
---|
[7723] | 779 | self.flash(_('Student is in wrong state.')) |
---|
[7158] | 780 | self.redirect(self.url(self.context,'view_clearance')) |
---|
| 781 | return |
---|
| 782 | |
---|
| 783 | def render(self): |
---|
| 784 | return |
---|
| 785 | |
---|
[9484] | 786 | class StudentRejectClearancePage(KofaEditFormPage): |
---|
[7158] | 787 | """ Reject clearance by clearance officers |
---|
| 788 | """ |
---|
| 789 | grok.context(IStudent) |
---|
| 790 | grok.name('reject_clearance') |
---|
[9484] | 791 | label = _('Reject clearance') |
---|
[7158] | 792 | grok.require('waeup.clearStudent') |
---|
[9484] | 793 | form_fields = grok.AutoFields( |
---|
[9486] | 794 | IUGStudentClearance).select('officer_comment') |
---|
[7158] | 795 | |
---|
[9814] | 796 | def update(self): |
---|
| 797 | if clearance_disabled_message(self.context): |
---|
| 798 | self.flash(clearance_disabled_message(self.context)) |
---|
| 799 | self.redirect(self.url(self.context,'view_clearance')) |
---|
| 800 | return |
---|
| 801 | return super(StudentRejectClearancePage, self).update() |
---|
| 802 | |
---|
[9484] | 803 | @action(_('Save comment and reject clearance now'), style='primary') |
---|
| 804 | def reject(self, **data): |
---|
[7158] | 805 | if self.context.state == CLEARED: |
---|
| 806 | IWorkflowInfo(self.context).fireTransition('reset4') |
---|
[7723] | 807 | message = _('Clearance has been annulled.') |
---|
[7275] | 808 | self.flash(message) |
---|
[7158] | 809 | elif self.context.state == REQUESTED: |
---|
| 810 | IWorkflowInfo(self.context).fireTransition('reset3') |
---|
[7723] | 811 | message = _('Clearance request has been rejected.') |
---|
[7275] | 812 | self.flash(message) |
---|
[7158] | 813 | else: |
---|
[7723] | 814 | self.flash(_('Student is in wrong state.')) |
---|
[7334] | 815 | self.redirect(self.url(self.context,'view_clearance')) |
---|
[7275] | 816 | return |
---|
[9484] | 817 | self.applyData(self.context, **data) |
---|
[9486] | 818 | comment = data['officer_comment'] |
---|
[9556] | 819 | if comment: |
---|
| 820 | self.context.writeLogMessage( |
---|
| 821 | self, 'comment: %s' % comment.replace('\n', '<br>')) |
---|
| 822 | args = {'subject':message, 'body':comment} |
---|
| 823 | else: |
---|
| 824 | args = {'subject':message,} |
---|
[7275] | 825 | self.redirect(self.url(self.context) + |
---|
| 826 | '/contactstudent?%s' % urlencode(args)) |
---|
[7158] | 827 | return |
---|
| 828 | |
---|
| 829 | |
---|
[7819] | 830 | class StudentPersonalDisplayFormPage(KofaDisplayFormPage): |
---|
[6631] | 831 | """ Page to display student personal data |
---|
| 832 | """ |
---|
| 833 | grok.context(IStudent) |
---|
| 834 | grok.name('view_personal') |
---|
[6660] | 835 | grok.require('waeup.viewStudent') |
---|
[6631] | 836 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
[7386] | 837 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
[9543] | 838 | form_fields[ |
---|
| 839 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[6642] | 840 | pnav = 4 |
---|
[6631] | 841 | |
---|
| 842 | @property |
---|
| 843 | def label(self): |
---|
[7723] | 844 | return _('${a}: Personal Data', |
---|
| 845 | mapping = {'a':self.context.display_fullname}) |
---|
[6631] | 846 | |
---|
[8903] | 847 | class StudentPersonalManageFormPage(KofaEditFormPage): |
---|
| 848 | """ Page to manage personal data |
---|
[6631] | 849 | """ |
---|
| 850 | grok.context(IStudent) |
---|
[8903] | 851 | grok.name('manage_personal') |
---|
| 852 | grok.require('waeup.manageStudent') |
---|
[9553] | 853 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
| 854 | form_fields['personal_updated'].for_display = True |
---|
[9571] | 855 | form_fields[ |
---|
| 856 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[8903] | 857 | label = _('Manage personal data') |
---|
[6642] | 858 | pnav = 4 |
---|
[6631] | 859 | |
---|
[7723] | 860 | @action(_('Save'), style='primary') |
---|
[6762] | 861 | def save(self, **data): |
---|
| 862 | msave(self, **data) |
---|
| 863 | return |
---|
| 864 | |
---|
[9543] | 865 | class StudentPersonalEditFormPage(KofaEditFormPage): |
---|
[8903] | 866 | """ Page to edit personal data |
---|
| 867 | """ |
---|
[9543] | 868 | grok.context(IStudent) |
---|
[8903] | 869 | grok.name('edit_personal') |
---|
| 870 | grok.require('waeup.handleStudent') |
---|
[9563] | 871 | form_fields = grok.AutoFields(IStudentPersonalEdit).omit('personal_updated') |
---|
[8903] | 872 | label = _('Edit personal data') |
---|
| 873 | pnav = 4 |
---|
| 874 | |
---|
[9543] | 875 | @action(_('Save/Confirm'), style='primary') |
---|
| 876 | def save(self, **data): |
---|
| 877 | msave(self, **data) |
---|
[9569] | 878 | self.context.personal_updated = datetime.utcnow() |
---|
[9543] | 879 | return |
---|
| 880 | |
---|
[7819] | 881 | class StudyCourseDisplayFormPage(KofaDisplayFormPage): |
---|
[6635] | 882 | """ Page to display the student study course data |
---|
| 883 | """ |
---|
| 884 | grok.context(IStudentStudyCourse) |
---|
| 885 | grok.name('index') |
---|
[6660] | 886 | grok.require('waeup.viewStudent') |
---|
[6775] | 887 | grok.template('studycoursepage') |
---|
[6642] | 888 | pnav = 4 |
---|
[6635] | 889 | |
---|
| 890 | @property |
---|
[8972] | 891 | def form_fields(self): |
---|
| 892 | if self.context.is_postgrad: |
---|
| 893 | form_fields = grok.AutoFields(IStudentStudyCourse).omit( |
---|
[9723] | 894 | 'previous_verdict') |
---|
[8972] | 895 | else: |
---|
| 896 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 897 | return form_fields |
---|
| 898 | |
---|
| 899 | @property |
---|
[6635] | 900 | def label(self): |
---|
[9140] | 901 | if self.context.is_current: |
---|
| 902 | return _('${a}: Study Course', |
---|
| 903 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
| 904 | else: |
---|
| 905 | return _('${a}: Previous Study Course', |
---|
| 906 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
[6635] | 907 | |
---|
[6912] | 908 | @property |
---|
| 909 | def current_mode(self): |
---|
[7641] | 910 | if self.context.certificate is not None: |
---|
[7841] | 911 | studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
---|
[7681] | 912 | return studymodes_dict[self.context.certificate.study_mode] |
---|
[7171] | 913 | return |
---|
[7642] | 914 | |
---|
[7171] | 915 | @property |
---|
| 916 | def department(self): |
---|
[7205] | 917 | if self.context.certificate is not None: |
---|
[7171] | 918 | return self.context.certificate.__parent__.__parent__ |
---|
| 919 | return |
---|
[6912] | 920 | |
---|
[7171] | 921 | @property |
---|
| 922 | def faculty(self): |
---|
[7205] | 923 | if self.context.certificate is not None: |
---|
[7171] | 924 | return self.context.certificate.__parent__.__parent__.__parent__ |
---|
| 925 | return |
---|
| 926 | |
---|
[9140] | 927 | @property |
---|
| 928 | def prev_studycourses(self): |
---|
| 929 | if self.context.is_current: |
---|
| 930 | if self.context.__parent__.get('studycourse_2', None) is not None: |
---|
| 931 | return ( |
---|
| 932 | {'href':self.url(self.context.student) + '/studycourse_1', |
---|
| 933 | 'title':_('First Study Course, ')}, |
---|
| 934 | {'href':self.url(self.context.student) + '/studycourse_2', |
---|
| 935 | 'title':_('Second Study Course')} |
---|
| 936 | ) |
---|
| 937 | if self.context.__parent__.get('studycourse_1', None) is not None: |
---|
| 938 | return ( |
---|
| 939 | {'href':self.url(self.context.student) + '/studycourse_1', |
---|
| 940 | 'title':_('First Study Course')}, |
---|
| 941 | ) |
---|
| 942 | return |
---|
| 943 | |
---|
[7819] | 944 | class StudyCourseManageFormPage(KofaEditFormPage): |
---|
[6649] | 945 | """ Page to edit the student study course data |
---|
| 946 | """ |
---|
| 947 | grok.context(IStudentStudyCourse) |
---|
[6775] | 948 | grok.name('manage') |
---|
[7136] | 949 | grok.require('waeup.manageStudent') |
---|
[6775] | 950 | grok.template('studycoursemanagepage') |
---|
[7723] | 951 | label = _('Manage study course') |
---|
[6649] | 952 | pnav = 4 |
---|
[7723] | 953 | taboneactions = [_('Save'),_('Cancel')] |
---|
| 954 | tabtwoactions = [_('Remove selected levels'),_('Cancel')] |
---|
| 955 | tabthreeactions = [_('Add study level')] |
---|
[6649] | 956 | |
---|
[8972] | 957 | @property |
---|
| 958 | def form_fields(self): |
---|
| 959 | if self.context.is_postgrad: |
---|
| 960 | form_fields = grok.AutoFields(IStudentStudyCourse).omit( |
---|
[9723] | 961 | 'previous_verdict') |
---|
[8972] | 962 | else: |
---|
| 963 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 964 | return form_fields |
---|
| 965 | |
---|
[6775] | 966 | def update(self): |
---|
[9139] | 967 | if not self.context.is_current: |
---|
| 968 | emit_lock_message(self) |
---|
| 969 | return |
---|
[6775] | 970 | super(StudyCourseManageFormPage, self).update() |
---|
| 971 | tabs.need() |
---|
[7484] | 972 | self.tab1 = self.tab2 = '' |
---|
| 973 | qs = self.request.get('QUERY_STRING', '') |
---|
| 974 | if not qs: |
---|
| 975 | qs = 'tab1' |
---|
| 976 | setattr(self, qs, 'active') |
---|
[7490] | 977 | warning.need() |
---|
| 978 | datatable.need() |
---|
| 979 | return |
---|
[6775] | 980 | |
---|
[7723] | 981 | @action(_('Save'), style='primary') |
---|
[6761] | 982 | def save(self, **data): |
---|
[8099] | 983 | try: |
---|
| 984 | msave(self, **data) |
---|
| 985 | except ConstraintNotSatisfied: |
---|
| 986 | # The selected level might not exist in certificate |
---|
| 987 | self.flash(_('Current level not available for certificate.')) |
---|
| 988 | return |
---|
[8081] | 989 | notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
---|
[6761] | 990 | return |
---|
| 991 | |
---|
[6775] | 992 | @property |
---|
| 993 | def level_dict(self): |
---|
| 994 | studylevelsource = StudyLevelSource().factory |
---|
| 995 | for code in studylevelsource.getValues(self.context): |
---|
| 996 | title = studylevelsource.getTitle(self.context, code) |
---|
| 997 | yield(dict(code=code, title=title)) |
---|
| 998 | |
---|
[9437] | 999 | @property |
---|
| 1000 | def session_dict(self): |
---|
| 1001 | yield(dict(code='', title='--')) |
---|
| 1002 | for item in academic_sessions(): |
---|
| 1003 | code = item[1] |
---|
| 1004 | title = item[0] |
---|
| 1005 | yield(dict(code=code, title=title)) |
---|
| 1006 | |
---|
[7723] | 1007 | @action(_('Add study level')) |
---|
[6774] | 1008 | def addStudyLevel(self, **data): |
---|
[6775] | 1009 | level_code = self.request.form.get('addlevel', None) |
---|
[9437] | 1010 | level_session = self.request.form.get('level_session', None) |
---|
| 1011 | if not level_session: |
---|
| 1012 | self.flash(_('You must select a session for the level.')) |
---|
| 1013 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
| 1014 | return |
---|
[8323] | 1015 | studylevel = createObject(u'waeup.StudentStudyLevel') |
---|
[6775] | 1016 | studylevel.level = int(level_code) |
---|
[9437] | 1017 | studylevel.level_session = int(level_session) |
---|
[6775] | 1018 | try: |
---|
[6782] | 1019 | self.context.addStudentStudyLevel( |
---|
| 1020 | self.context.certificate,studylevel) |
---|
[7723] | 1021 | self.flash(_('Study level has been added.')) |
---|
[6775] | 1022 | except KeyError: |
---|
[7723] | 1023 | self.flash(_('This level exists.')) |
---|
[7484] | 1024 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6774] | 1025 | return |
---|
| 1026 | |
---|
[7723] | 1027 | @jsaction(_('Remove selected levels')) |
---|
[6775] | 1028 | def delStudyLevels(self, **data): |
---|
| 1029 | form = self.request.form |
---|
[9701] | 1030 | if 'val_id' in form: |
---|
[6775] | 1031 | child_id = form['val_id'] |
---|
| 1032 | else: |
---|
[7723] | 1033 | self.flash(_('No study level selected.')) |
---|
[7484] | 1034 | self.redirect(self.url(self.context, '@@manage')+'?tab2') |
---|
[6775] | 1035 | return |
---|
| 1036 | if not isinstance(child_id, list): |
---|
| 1037 | child_id = [child_id] |
---|
| 1038 | deleted = [] |
---|
| 1039 | for id in child_id: |
---|
[7723] | 1040 | del self.context[id] |
---|
| 1041 | deleted.append(id) |
---|
[6775] | 1042 | if len(deleted): |
---|
[7723] | 1043 | self.flash(_('Successfully removed: ${a}', |
---|
| 1044 | mapping = {'a':', '.join(deleted)})) |
---|
[9332] | 1045 | self.context.writeLogMessage( |
---|
| 1046 | self,'removed: %s' % ', '.join(deleted)) |
---|
[7484] | 1047 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6775] | 1048 | return |
---|
[6774] | 1049 | |
---|
[10178] | 1050 | class StudyCourseTranscriptPage(KofaDisplayFormPage): |
---|
| 1051 | """ Page to display the student's transcript. |
---|
| 1052 | """ |
---|
[10250] | 1053 | grok.context(IStudentStudyCourseTranscript) |
---|
[10178] | 1054 | grok.name('transcript') |
---|
| 1055 | grok.require('waeup.viewStudent') |
---|
| 1056 | grok.template('transcript') |
---|
| 1057 | pnav = 4 |
---|
| 1058 | |
---|
| 1059 | def update(self): |
---|
| 1060 | super(StudyCourseTranscriptPage, self).update() |
---|
| 1061 | self.semester_dict = getUtility(IKofaUtils).SEMESTER_DICT |
---|
| 1062 | self.session_dict = dict( |
---|
| 1063 | [(item[1], item[0]) for item in academic_sessions()]) |
---|
[10179] | 1064 | self.course_levels = course_levels |
---|
[10178] | 1065 | self.studymode_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
---|
| 1066 | return |
---|
| 1067 | |
---|
| 1068 | @property |
---|
| 1069 | def label(self): |
---|
| 1070 | # Here we know that the cookie has been set |
---|
| 1071 | lang = self.request.cookies.get('kofa.language') |
---|
| 1072 | return _('${a}: Transcript Data', mapping = { |
---|
| 1073 | 'a':self.context.student.display_fullname}) |
---|
| 1074 | |
---|
[10250] | 1075 | class ExportPDFTranscriptPage(UtilityView, grok.View): |
---|
| 1076 | """Deliver a PDF slip of the context. |
---|
| 1077 | """ |
---|
| 1078 | grok.context(IStudentStudyCourse) |
---|
| 1079 | grok.name('transcript.pdf') |
---|
| 1080 | grok.require('waeup.viewStudent') |
---|
| 1081 | form_fields = grok.AutoFields(IStudentStudyCourseTranscript) |
---|
| 1082 | prefix = 'form' |
---|
| 1083 | omit_fields = ( |
---|
| 1084 | 'department', 'faculty', 'entry_session', 'certificate', |
---|
| 1085 | 'password', 'suspended', 'phone', 'email', |
---|
| 1086 | 'adm_code', 'sex', 'suspended_comment') |
---|
| 1087 | |
---|
| 1088 | def update(self): |
---|
| 1089 | super(ExportPDFTranscriptPage, self).update() |
---|
| 1090 | self.semester_dict = getUtility(IKofaUtils).SEMESTER_DICT |
---|
| 1091 | self.session_dict = dict( |
---|
| 1092 | [(item[1], item[0]) for item in academic_sessions()]) |
---|
| 1093 | self.course_levels = course_levels |
---|
| 1094 | self.studymode_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
---|
| 1095 | return |
---|
| 1096 | |
---|
| 1097 | @property |
---|
| 1098 | def label(self): |
---|
| 1099 | # Here we know that the cookie has been set |
---|
| 1100 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 1101 | return translate(_('Academic Transcript'), |
---|
| 1102 | 'waeup.kofa', target_language=portal_language) |
---|
| 1103 | |
---|
| 1104 | def render(self): |
---|
| 1105 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 1106 | Sem = translate(_('Sem.'), 'waeup.kofa', target_language=portal_language) |
---|
| 1107 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
| 1108 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
| 1109 | Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language) |
---|
| 1110 | Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
| 1111 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
---|
| 1112 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 1113 | self.request, self.omit_fields) |
---|
| 1114 | students_utils = getUtility(IStudentsUtils) |
---|
| 1115 | |
---|
| 1116 | tableheader = [(Code,'code', 2.5), |
---|
| 1117 | (Title,'title', 7), |
---|
| 1118 | (Sem, 'semester', 1.5), |
---|
| 1119 | (Cred, 'credits', 1.5), |
---|
| 1120 | (Score, 'score', 1.5), |
---|
| 1121 | (Grade, 'grade', 1.5), |
---|
| 1122 | ] |
---|
| 1123 | |
---|
| 1124 | return students_utils.renderPDFTranscript( |
---|
| 1125 | self, 'transcript.pdf', |
---|
| 1126 | self.context.student, studentview, |
---|
| 1127 | omit_fields=self.omit_fields, |
---|
| 1128 | tableheader=tableheader |
---|
| 1129 | ) |
---|
| 1130 | |
---|
[9138] | 1131 | class StudentTransferFormPage(KofaAddFormPage): |
---|
| 1132 | """Page to transfer the student. |
---|
| 1133 | """ |
---|
| 1134 | grok.context(IStudent) |
---|
| 1135 | grok.name('transfer') |
---|
| 1136 | grok.require('waeup.manageStudent') |
---|
| 1137 | label = _('Transfer student') |
---|
| 1138 | form_fields = grok.AutoFields(IStudentStudyCourseTransfer).omit( |
---|
| 1139 | 'entry_mode', 'entry_session') |
---|
| 1140 | pnav = 4 |
---|
| 1141 | |
---|
| 1142 | def update(self): |
---|
| 1143 | super(StudentTransferFormPage, self).update() |
---|
| 1144 | warning.need() |
---|
| 1145 | return |
---|
| 1146 | |
---|
| 1147 | @jsaction(_('Transfer')) |
---|
| 1148 | def transferStudent(self, **data): |
---|
| 1149 | error = self.context.transfer(**data) |
---|
| 1150 | if error == -1: |
---|
| 1151 | self.flash(_('Current level does not match certificate levels.')) |
---|
| 1152 | elif error == -2: |
---|
| 1153 | self.flash(_('Former study course record incomplete.')) |
---|
| 1154 | elif error == -3: |
---|
| 1155 | self.flash(_('Maximum number of transfers exceeded.')) |
---|
| 1156 | else: |
---|
| 1157 | self.flash(_('Successfully transferred.')) |
---|
| 1158 | return |
---|
| 1159 | |
---|
[10060] | 1160 | class RevertTransferFormPage(KofaEditFormPage): |
---|
| 1161 | """View that reverts the previous transfer. |
---|
| 1162 | """ |
---|
| 1163 | grok.context(IStudent) |
---|
| 1164 | grok.name('revert_transfer') |
---|
| 1165 | grok.require('waeup.manageStudent') |
---|
| 1166 | grok.template('reverttransfer') |
---|
| 1167 | label = _('Revert previous transfer') |
---|
| 1168 | |
---|
| 1169 | def update(self): |
---|
| 1170 | warning.need() |
---|
| 1171 | if not self.context.has_key('studycourse_1'): |
---|
| 1172 | self.flash(_('No previous transfer.')) |
---|
| 1173 | self.redirect(self.url(self.context)) |
---|
| 1174 | return |
---|
| 1175 | return |
---|
| 1176 | |
---|
| 1177 | @jsaction(_('Revert now')) |
---|
| 1178 | def transferStudent(self, **data): |
---|
| 1179 | self.context.revert_transfer() |
---|
| 1180 | self.flash(_('Previous transfer reverted.')) |
---|
| 1181 | self.redirect(self.url(self.context, 'studycourse')) |
---|
| 1182 | return |
---|
| 1183 | |
---|
[7819] | 1184 | class StudyLevelDisplayFormPage(KofaDisplayFormPage): |
---|
[6774] | 1185 | """ Page to display student study levels |
---|
| 1186 | """ |
---|
| 1187 | grok.context(IStudentStudyLevel) |
---|
| 1188 | grok.name('index') |
---|
| 1189 | grok.require('waeup.viewStudent') |
---|
[6775] | 1190 | form_fields = grok.AutoFields(IStudentStudyLevel) |
---|
[9161] | 1191 | form_fields[ |
---|
| 1192 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[6783] | 1193 | grok.template('studylevelpage') |
---|
[6774] | 1194 | pnav = 4 |
---|
| 1195 | |
---|
[7310] | 1196 | def update(self): |
---|
| 1197 | super(StudyLevelDisplayFormPage, self).update() |
---|
| 1198 | datatable.need() |
---|
| 1199 | return |
---|
| 1200 | |
---|
[6774] | 1201 | @property |
---|
[8141] | 1202 | def translated_values(self): |
---|
[8921] | 1203 | return translated_values(self) |
---|
[8141] | 1204 | |
---|
| 1205 | @property |
---|
[6774] | 1206 | def label(self): |
---|
[7833] | 1207 | # Here we know that the cookie has been set |
---|
| 1208 | lang = self.request.cookies.get('kofa.language') |
---|
[7811] | 1209 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 1210 | target_language=lang) |
---|
| 1211 | return _('${a}: Study Level ${b}', mapping = { |
---|
[8736] | 1212 | 'a':self.context.student.display_fullname, |
---|
[7723] | 1213 | 'b':level_title}) |
---|
[6774] | 1214 | |
---|
[7459] | 1215 | class ExportPDFCourseRegistrationSlipPage(UtilityView, grok.View): |
---|
[7028] | 1216 | """Deliver a PDF slip of the context. |
---|
| 1217 | """ |
---|
| 1218 | grok.context(IStudentStudyLevel) |
---|
[9452] | 1219 | grok.name('course_registration_slip.pdf') |
---|
[7028] | 1220 | grok.require('waeup.viewStudent') |
---|
| 1221 | form_fields = grok.AutoFields(IStudentStudyLevel) |
---|
[9683] | 1222 | form_fields[ |
---|
| 1223 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[7028] | 1224 | prefix = 'form' |
---|
[9702] | 1225 | omit_fields = ( |
---|
[10256] | 1226 | 'password', 'suspended', 'phone', 'date_of_birth', |
---|
[9702] | 1227 | 'adm_code', 'sex', 'suspended_comment') |
---|
[7028] | 1228 | |
---|
| 1229 | @property |
---|
[7723] | 1230 | def title(self): |
---|
[7819] | 1231 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 1232 | return translate(_('Level Data'), 'waeup.kofa', |
---|
[7723] | 1233 | target_language=portal_language) |
---|
| 1234 | |
---|
| 1235 | @property |
---|
[9906] | 1236 | def content_title_1(self): |
---|
[7819] | 1237 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9906] | 1238 | return translate(_('1st Semester Courses'), 'waeup.kofa', |
---|
[7723] | 1239 | target_language=portal_language) |
---|
| 1240 | |
---|
| 1241 | @property |
---|
[9906] | 1242 | def content_title_2(self): |
---|
| 1243 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 1244 | return translate(_('2nd Semester Courses'), 'waeup.kofa', |
---|
| 1245 | target_language=portal_language) |
---|
| 1246 | |
---|
| 1247 | @property |
---|
[9957] | 1248 | def content_title_3(self): |
---|
| 1249 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 1250 | return translate(_('Level Courses'), 'waeup.kofa', |
---|
| 1251 | target_language=portal_language) |
---|
| 1252 | |
---|
| 1253 | @property |
---|
[7028] | 1254 | def label(self): |
---|
[7819] | 1255 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 1256 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
| 1257 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 1258 | target_language=lang) |
---|
[8141] | 1259 | return translate(_('Course Registration Slip'), |
---|
[7811] | 1260 | 'waeup.kofa', target_language=portal_language) \ |
---|
[7723] | 1261 | + ' %s' % level_title |
---|
[7028] | 1262 | |
---|
| 1263 | def render(self): |
---|
[7819] | 1264 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 1265 | Sem = translate(_('Sem.'), 'waeup.kofa', target_language=portal_language) |
---|
| 1266 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
| 1267 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
| 1268 | Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language) |
---|
| 1269 | Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language) |
---|
| 1270 | Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language) |
---|
[9906] | 1271 | #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language) |
---|
[7811] | 1272 | Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
[9810] | 1273 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
---|
[9141] | 1274 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[9375] | 1275 | self.request, self.omit_fields) |
---|
[7150] | 1276 | students_utils = getUtility(IStudentsUtils) |
---|
[9906] | 1277 | tabledata_1 = sorted( |
---|
| 1278 | [value for value in self.context.values() if value.semester == 1], |
---|
[7318] | 1279 | key=lambda value: str(value.semester) + value.code) |
---|
[9906] | 1280 | tabledata_2 = sorted( |
---|
| 1281 | [value for value in self.context.values() if value.semester == 2], |
---|
| 1282 | key=lambda value: str(value.semester) + value.code) |
---|
[9957] | 1283 | tabledata_3 = sorted( |
---|
| 1284 | [value for value in self.context.values() if value.semester == 3], |
---|
| 1285 | key=lambda value: str(value.semester) + value.code) |
---|
[9906] | 1286 | tableheader = [(Code,'code', 2.5), |
---|
[7723] | 1287 | (Title,'title', 5), |
---|
| 1288 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
| 1289 | (Cred, 'credits', 1.5), |
---|
[9906] | 1290 | #(Mand, 'mandatory', 1.5), |
---|
[8141] | 1291 | (Score, 'score', 1.5), |
---|
[9810] | 1292 | (Grade, 'grade', 1.5), |
---|
[8141] | 1293 | #('Auto', 'automatic', 1.5) |
---|
[9906] | 1294 | ] |
---|
| 1295 | return students_utils.renderPDF( |
---|
| 1296 | self, 'course_registration_slip.pdf', |
---|
| 1297 | self.context.student, studentview, |
---|
| 1298 | tableheader_1=tableheader, |
---|
| 1299 | tabledata_1=tabledata_1, |
---|
| 1300 | tableheader_2=tableheader, |
---|
[9957] | 1301 | tabledata_2=tabledata_2, |
---|
| 1302 | tableheader_3=tableheader, |
---|
[10250] | 1303 | tabledata_3=tabledata_3, |
---|
| 1304 | omit_fields=self.omit_fields |
---|
[9906] | 1305 | ) |
---|
[7028] | 1306 | |
---|
[7819] | 1307 | class StudyLevelManageFormPage(KofaEditFormPage): |
---|
[6792] | 1308 | """ Page to edit the student study level data |
---|
| 1309 | """ |
---|
| 1310 | grok.context(IStudentStudyLevel) |
---|
| 1311 | grok.name('manage') |
---|
[7136] | 1312 | grok.require('waeup.manageStudent') |
---|
[6792] | 1313 | grok.template('studylevelmanagepage') |
---|
[9161] | 1314 | form_fields = grok.AutoFields(IStudentStudyLevel).omit( |
---|
[9690] | 1315 | 'validation_date', 'validated_by', 'total_credits', 'gpa') |
---|
[6792] | 1316 | pnav = 4 |
---|
[7723] | 1317 | taboneactions = [_('Save'),_('Cancel')] |
---|
| 1318 | tabtwoactions = [_('Add course ticket'), |
---|
| 1319 | _('Remove selected tickets'),_('Cancel')] |
---|
[6792] | 1320 | |
---|
[9895] | 1321 | def update(self, ADD=None, course=None): |
---|
[9139] | 1322 | if not self.context.__parent__.is_current: |
---|
| 1323 | emit_lock_message(self) |
---|
| 1324 | return |
---|
[6792] | 1325 | super(StudyLevelManageFormPage, self).update() |
---|
| 1326 | tabs.need() |
---|
[7484] | 1327 | self.tab1 = self.tab2 = '' |
---|
| 1328 | qs = self.request.get('QUERY_STRING', '') |
---|
| 1329 | if not qs: |
---|
| 1330 | qs = 'tab1' |
---|
| 1331 | setattr(self, qs, 'active') |
---|
[7490] | 1332 | warning.need() |
---|
| 1333 | datatable.need() |
---|
[9895] | 1334 | if ADD is not None: |
---|
| 1335 | if not course: |
---|
| 1336 | self.flash(_('No valid course code entered.')) |
---|
| 1337 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
| 1338 | return |
---|
| 1339 | cat = queryUtility(ICatalog, name='courses_catalog') |
---|
| 1340 | result = cat.searchResults(code=(course, course)) |
---|
| 1341 | if len(result) != 1: |
---|
| 1342 | self.flash(_('Course not found.')) |
---|
| 1343 | else: |
---|
| 1344 | course = list(result)[0] |
---|
| 1345 | addCourseTicket(self, course) |
---|
| 1346 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6792] | 1347 | return |
---|
| 1348 | |
---|
| 1349 | @property |
---|
[8921] | 1350 | def translated_values(self): |
---|
| 1351 | return translated_values(self) |
---|
| 1352 | |
---|
| 1353 | @property |
---|
[6792] | 1354 | def label(self): |
---|
[7833] | 1355 | # Here we know that the cookie has been set |
---|
| 1356 | lang = self.request.cookies.get('kofa.language') |
---|
[7811] | 1357 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 1358 | target_language=lang) |
---|
| 1359 | return _('Manage study level ${a}', |
---|
| 1360 | mapping = {'a':level_title}) |
---|
[6792] | 1361 | |
---|
[7723] | 1362 | @action(_('Save'), style='primary') |
---|
[6792] | 1363 | def save(self, **data): |
---|
| 1364 | msave(self, **data) |
---|
| 1365 | return |
---|
| 1366 | |
---|
[7723] | 1367 | @jsaction(_('Remove selected tickets')) |
---|
[6792] | 1368 | def delCourseTicket(self, **data): |
---|
| 1369 | form = self.request.form |
---|
[9701] | 1370 | if 'val_id' in form: |
---|
[6792] | 1371 | child_id = form['val_id'] |
---|
| 1372 | else: |
---|
[7723] | 1373 | self.flash(_('No ticket selected.')) |
---|
[7484] | 1374 | self.redirect(self.url(self.context, '@@manage')+'?tab2') |
---|
[6792] | 1375 | return |
---|
| 1376 | if not isinstance(child_id, list): |
---|
| 1377 | child_id = [child_id] |
---|
| 1378 | deleted = [] |
---|
| 1379 | for id in child_id: |
---|
[7723] | 1380 | del self.context[id] |
---|
| 1381 | deleted.append(id) |
---|
[6792] | 1382 | if len(deleted): |
---|
[7723] | 1383 | self.flash(_('Successfully removed: ${a}', |
---|
| 1384 | mapping = {'a':', '.join(deleted)})) |
---|
[9332] | 1385 | self.context.writeLogMessage( |
---|
[9924] | 1386 | self,'removed: %s at %s' % |
---|
| 1387 | (', '.join(deleted), self.context.level)) |
---|
[7484] | 1388 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6792] | 1389 | return |
---|
| 1390 | |
---|
[7459] | 1391 | class ValidateCoursesPage(UtilityView, grok.View): |
---|
[7334] | 1392 | """ Validate course list by course adviser |
---|
| 1393 | """ |
---|
| 1394 | grok.context(IStudentStudyLevel) |
---|
| 1395 | grok.name('validate_courses') |
---|
| 1396 | grok.require('waeup.validateStudent') |
---|
| 1397 | |
---|
| 1398 | def update(self): |
---|
[9139] | 1399 | if not self.context.__parent__.is_current: |
---|
| 1400 | emit_lock_message(self) |
---|
| 1401 | return |
---|
[7334] | 1402 | if str(self.context.__parent__.current_level) != self.context.__name__: |
---|
[7723] | 1403 | self.flash(_('This level does not correspond current level.')) |
---|
[8736] | 1404 | elif self.context.student.state == REGISTERED: |
---|
| 1405 | IWorkflowInfo(self.context.student).fireTransition( |
---|
[7642] | 1406 | 'validate_courses') |
---|
[7723] | 1407 | self.flash(_('Course list has been validated.')) |
---|
[7334] | 1408 | else: |
---|
[7723] | 1409 | self.flash(_('Student is in the wrong state.')) |
---|
[7334] | 1410 | self.redirect(self.url(self.context)) |
---|
| 1411 | return |
---|
| 1412 | |
---|
| 1413 | def render(self): |
---|
| 1414 | return |
---|
| 1415 | |
---|
[7459] | 1416 | class RejectCoursesPage(UtilityView, grok.View): |
---|
[7334] | 1417 | """ Reject course list by course adviser |
---|
| 1418 | """ |
---|
| 1419 | grok.context(IStudentStudyLevel) |
---|
| 1420 | grok.name('reject_courses') |
---|
| 1421 | grok.require('waeup.validateStudent') |
---|
| 1422 | |
---|
| 1423 | def update(self): |
---|
[9139] | 1424 | if not self.context.__parent__.is_current: |
---|
| 1425 | emit_lock_message(self) |
---|
| 1426 | return |
---|
[7334] | 1427 | if str(self.context.__parent__.current_level) != self.context.__name__: |
---|
[7723] | 1428 | self.flash(_('This level does not correspond current level.')) |
---|
[7334] | 1429 | self.redirect(self.url(self.context)) |
---|
| 1430 | return |
---|
[8736] | 1431 | elif self.context.student.state == VALIDATED: |
---|
| 1432 | IWorkflowInfo(self.context.student).fireTransition('reset8') |
---|
[7723] | 1433 | message = _('Course list request has been annulled.') |
---|
[7334] | 1434 | self.flash(message) |
---|
[8736] | 1435 | elif self.context.student.state == REGISTERED: |
---|
| 1436 | IWorkflowInfo(self.context.student).fireTransition('reset7') |
---|
[7723] | 1437 | message = _('Course list request has been rejected:') |
---|
[7334] | 1438 | self.flash(message) |
---|
| 1439 | else: |
---|
[7723] | 1440 | self.flash(_('Student is in the wrong state.')) |
---|
[7334] | 1441 | self.redirect(self.url(self.context)) |
---|
| 1442 | return |
---|
| 1443 | args = {'subject':message} |
---|
[8736] | 1444 | self.redirect(self.url(self.context.student) + |
---|
[7334] | 1445 | '/contactstudent?%s' % urlencode(args)) |
---|
| 1446 | return |
---|
| 1447 | |
---|
| 1448 | def render(self): |
---|
| 1449 | return |
---|
| 1450 | |
---|
[7819] | 1451 | class CourseTicketAddFormPage(KofaAddFormPage): |
---|
[6808] | 1452 | """Add a course ticket. |
---|
[6795] | 1453 | """ |
---|
| 1454 | grok.context(IStudentStudyLevel) |
---|
| 1455 | grok.name('add') |
---|
[7136] | 1456 | grok.require('waeup.manageStudent') |
---|
[7723] | 1457 | label = _('Add course ticket') |
---|
[9420] | 1458 | form_fields = grok.AutoFields(ICourseTicketAdd) |
---|
[6795] | 1459 | pnav = 4 |
---|
| 1460 | |
---|
[9139] | 1461 | def update(self): |
---|
| 1462 | if not self.context.__parent__.is_current: |
---|
| 1463 | emit_lock_message(self) |
---|
| 1464 | return |
---|
| 1465 | super(CourseTicketAddFormPage, self).update() |
---|
| 1466 | return |
---|
| 1467 | |
---|
[7723] | 1468 | @action(_('Add course ticket')) |
---|
[6795] | 1469 | def addCourseTicket(self, **data): |
---|
| 1470 | course = data['course'] |
---|
[9895] | 1471 | success = addCourseTicket(self, course) |
---|
| 1472 | if success: |
---|
| 1473 | self.redirect(self.url(self.context, u'@@manage')+'?tab2') |
---|
[6795] | 1474 | return |
---|
| 1475 | |
---|
[7834] | 1476 | @action(_('Cancel'), validator=NullValidator) |
---|
[6795] | 1477 | def cancel(self, **data): |
---|
| 1478 | self.redirect(self.url(self.context)) |
---|
| 1479 | |
---|
[7819] | 1480 | class CourseTicketDisplayFormPage(KofaDisplayFormPage): |
---|
[6796] | 1481 | """ Page to display course tickets |
---|
| 1482 | """ |
---|
| 1483 | grok.context(ICourseTicket) |
---|
| 1484 | grok.name('index') |
---|
| 1485 | grok.require('waeup.viewStudent') |
---|
| 1486 | form_fields = grok.AutoFields(ICourseTicket) |
---|
[9684] | 1487 | grok.template('courseticketpage') |
---|
[6796] | 1488 | pnav = 4 |
---|
| 1489 | |
---|
| 1490 | @property |
---|
| 1491 | def label(self): |
---|
[7723] | 1492 | return _('${a}: Course Ticket ${b}', mapping = { |
---|
[8736] | 1493 | 'a':self.context.student.display_fullname, |
---|
[7723] | 1494 | 'b':self.context.code}) |
---|
[6796] | 1495 | |
---|
[7819] | 1496 | class CourseTicketManageFormPage(KofaEditFormPage): |
---|
[6796] | 1497 | """ Page to manage course tickets |
---|
| 1498 | """ |
---|
| 1499 | grok.context(ICourseTicket) |
---|
| 1500 | grok.name('manage') |
---|
[7136] | 1501 | grok.require('waeup.manageStudent') |
---|
[9420] | 1502 | form_fields = grok.AutoFields(ICourseTicket) |
---|
| 1503 | form_fields['title'].for_display = True |
---|
| 1504 | form_fields['fcode'].for_display = True |
---|
| 1505 | form_fields['dcode'].for_display = True |
---|
| 1506 | form_fields['semester'].for_display = True |
---|
| 1507 | form_fields['passmark'].for_display = True |
---|
| 1508 | form_fields['credits'].for_display = True |
---|
[9698] | 1509 | form_fields['mandatory'].for_display = False |
---|
[9420] | 1510 | form_fields['automatic'].for_display = True |
---|
[9422] | 1511 | form_fields['carry_over'].for_display = True |
---|
[6796] | 1512 | pnav = 4 |
---|
[9697] | 1513 | grok.template('courseticketmanagepage') |
---|
[6796] | 1514 | |
---|
| 1515 | @property |
---|
| 1516 | def label(self): |
---|
[7723] | 1517 | return _('Manage course ticket ${a}', mapping = {'a':self.context.code}) |
---|
[6796] | 1518 | |
---|
[7459] | 1519 | @action('Save', style='primary') |
---|
[6796] | 1520 | def save(self, **data): |
---|
| 1521 | msave(self, **data) |
---|
| 1522 | return |
---|
| 1523 | |
---|
[7819] | 1524 | class PaymentsManageFormPage(KofaEditFormPage): |
---|
[6869] | 1525 | """ Page to manage the student payments |
---|
[7642] | 1526 | |
---|
| 1527 | This manage form page is for both students and students officers. |
---|
[6869] | 1528 | """ |
---|
| 1529 | grok.context(IStudentPaymentsContainer) |
---|
[6940] | 1530 | grok.name('index') |
---|
[10080] | 1531 | grok.require('waeup.viewStudent') |
---|
[6869] | 1532 | form_fields = grok.AutoFields(IStudentPaymentsContainer) |
---|
| 1533 | grok.template('paymentsmanagepage') |
---|
| 1534 | pnav = 4 |
---|
| 1535 | |
---|
[10080] | 1536 | @property |
---|
| 1537 | def manage_payments_allowed(self): |
---|
| 1538 | return checkPermission('waeup.payStudent', self.context) |
---|
| 1539 | |
---|
[6940] | 1540 | def unremovable(self, ticket): |
---|
[7251] | 1541 | usertype = getattr(self.request.principal, 'user_type', None) |
---|
| 1542 | if not usertype: |
---|
| 1543 | return False |
---|
[10080] | 1544 | if not self.manage_payments_allowed: |
---|
| 1545 | return True |
---|
[7251] | 1546 | return (self.request.principal.user_type == 'student' and ticket.r_code) |
---|
[6940] | 1547 | |
---|
[6869] | 1548 | @property |
---|
| 1549 | def label(self): |
---|
[7723] | 1550 | return _('${a}: Payments', |
---|
| 1551 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
[6869] | 1552 | |
---|
| 1553 | def update(self): |
---|
| 1554 | super(PaymentsManageFormPage, self).update() |
---|
| 1555 | datatable.need() |
---|
[7329] | 1556 | warning.need() |
---|
[6869] | 1557 | return |
---|
| 1558 | |
---|
[7723] | 1559 | @jsaction(_('Remove selected tickets')) |
---|
[6869] | 1560 | def delPaymentTicket(self, **data): |
---|
| 1561 | form = self.request.form |
---|
[9701] | 1562 | if 'val_id' in form: |
---|
[6869] | 1563 | child_id = form['val_id'] |
---|
| 1564 | else: |
---|
[7723] | 1565 | self.flash(_('No payment selected.')) |
---|
[6940] | 1566 | self.redirect(self.url(self.context)) |
---|
[6869] | 1567 | return |
---|
| 1568 | if not isinstance(child_id, list): |
---|
| 1569 | child_id = [child_id] |
---|
| 1570 | deleted = [] |
---|
| 1571 | for id in child_id: |
---|
[6992] | 1572 | # Students are not allowed to remove used payment tickets |
---|
[10001] | 1573 | ticket = self.context.get(id, None) |
---|
| 1574 | if ticket is not None and not self.unremovable(ticket): |
---|
[7723] | 1575 | del self.context[id] |
---|
| 1576 | deleted.append(id) |
---|
[6869] | 1577 | if len(deleted): |
---|
[7723] | 1578 | self.flash(_('Successfully removed: ${a}', |
---|
| 1579 | mapping = {'a': ', '.join(deleted)})) |
---|
[8735] | 1580 | self.context.writeLogMessage( |
---|
[8885] | 1581 | self,'removed: %s' % ', '.join(deleted)) |
---|
[6940] | 1582 | self.redirect(self.url(self.context)) |
---|
[6869] | 1583 | return |
---|
| 1584 | |
---|
[9517] | 1585 | #@action(_('Add online payment ticket')) |
---|
| 1586 | #def addPaymentTicket(self, **data): |
---|
| 1587 | # self.redirect(self.url(self.context, '@@addop')) |
---|
[6869] | 1588 | |
---|
[7819] | 1589 | class OnlinePaymentAddFormPage(KofaAddFormPage): |
---|
[6869] | 1590 | """ Page to add an online payment ticket |
---|
| 1591 | """ |
---|
| 1592 | grok.context(IStudentPaymentsContainer) |
---|
| 1593 | grok.name('addop') |
---|
[9729] | 1594 | grok.template('onlinepaymentaddform') |
---|
[7181] | 1595 | grok.require('waeup.payStudent') |
---|
[6877] | 1596 | form_fields = grok.AutoFields(IStudentOnlinePayment).select( |
---|
[6869] | 1597 | 'p_category') |
---|
[7723] | 1598 | label = _('Add online payment') |
---|
[6869] | 1599 | pnav = 4 |
---|
[7642] | 1600 | |
---|
[9729] | 1601 | @property |
---|
| 1602 | def selectable_categories(self): |
---|
| 1603 | categories = getUtility(IKofaUtils).SELECTABLE_PAYMENT_CATEGORIES |
---|
| 1604 | return sorted(categories.items()) |
---|
| 1605 | |
---|
[7723] | 1606 | @action(_('Create ticket'), style='primary') |
---|
[6869] | 1607 | def createTicket(self, **data): |
---|
[7024] | 1608 | p_category = data['p_category'] |
---|
[9148] | 1609 | previous_session = data.get('p_session', None) |
---|
| 1610 | previous_level = data.get('p_level', None) |
---|
[7024] | 1611 | student = self.context.__parent__ |
---|
| 1612 | if p_category == 'bed_allocation' and student[ |
---|
| 1613 | 'studycourse'].current_session != grok.getSite()[ |
---|
[8685] | 1614 | 'hostels'].accommodation_session: |
---|
[7024] | 1615 | self.flash( |
---|
[7723] | 1616 | _('Your current session does not match ' + \ |
---|
| 1617 | 'accommodation session.')) |
---|
[7024] | 1618 | return |
---|
[9423] | 1619 | if 'maintenance' in p_category: |
---|
| 1620 | current_session = str(student['studycourse'].current_session) |
---|
[9701] | 1621 | if not current_session in student['accommodation']: |
---|
[9424] | 1622 | self.flash(_('You have not yet booked accommodation.')) |
---|
[9423] | 1623 | return |
---|
[7150] | 1624 | students_utils = getUtility(IStudentsUtils) |
---|
[9148] | 1625 | error, payment = students_utils.setPaymentDetails( |
---|
| 1626 | p_category, student, previous_session, previous_level) |
---|
[8595] | 1627 | if error is not None: |
---|
| 1628 | self.flash(error) |
---|
[8081] | 1629 | return |
---|
[6869] | 1630 | self.context[payment.p_id] = payment |
---|
[7723] | 1631 | self.flash(_('Payment ticket created.')) |
---|
[6940] | 1632 | self.redirect(self.url(self.context)) |
---|
[6869] | 1633 | return |
---|
| 1634 | |
---|
[9383] | 1635 | @action(_('Cancel'), validator=NullValidator) |
---|
| 1636 | def cancel(self, **data): |
---|
| 1637 | self.redirect(self.url(self.context)) |
---|
| 1638 | |
---|
[9862] | 1639 | class PreviousPaymentAddFormPage(KofaAddFormPage): |
---|
[9148] | 1640 | """ Page to add an online payment ticket for previous sessions |
---|
| 1641 | """ |
---|
| 1642 | grok.context(IStudentPaymentsContainer) |
---|
| 1643 | grok.name('addpp') |
---|
| 1644 | grok.require('waeup.payStudent') |
---|
[9864] | 1645 | form_fields = grok.AutoFields(IStudentPreviousPayment) |
---|
[9148] | 1646 | label = _('Add previous session online payment') |
---|
| 1647 | pnav = 4 |
---|
| 1648 | |
---|
[9517] | 1649 | def update(self): |
---|
[9521] | 1650 | if self.context.student.before_payment: |
---|
| 1651 | self.flash(_("No previous payment to be made.")) |
---|
[9517] | 1652 | self.redirect(self.url(self.context)) |
---|
| 1653 | super(PreviousPaymentAddFormPage, self).update() |
---|
| 1654 | return |
---|
| 1655 | |
---|
[9862] | 1656 | @action(_('Create ticket'), style='primary') |
---|
| 1657 | def createTicket(self, **data): |
---|
| 1658 | p_category = data['p_category'] |
---|
| 1659 | previous_session = data.get('p_session', None) |
---|
| 1660 | previous_level = data.get('p_level', None) |
---|
| 1661 | student = self.context.__parent__ |
---|
| 1662 | students_utils = getUtility(IStudentsUtils) |
---|
| 1663 | error, payment = students_utils.setPaymentDetails( |
---|
| 1664 | p_category, student, previous_session, previous_level) |
---|
| 1665 | if error is not None: |
---|
| 1666 | self.flash(error) |
---|
| 1667 | return |
---|
| 1668 | self.context[payment.p_id] = payment |
---|
| 1669 | self.flash(_('Payment ticket created.')) |
---|
| 1670 | self.redirect(self.url(self.context)) |
---|
| 1671 | return |
---|
| 1672 | |
---|
| 1673 | @action(_('Cancel'), validator=NullValidator) |
---|
| 1674 | def cancel(self, **data): |
---|
| 1675 | self.redirect(self.url(self.context)) |
---|
| 1676 | |
---|
[9864] | 1677 | class BalancePaymentAddFormPage(KofaAddFormPage): |
---|
| 1678 | """ Page to add an online payment ticket for balance sessions |
---|
| 1679 | """ |
---|
| 1680 | grok.context(IStudentPaymentsContainer) |
---|
| 1681 | grok.name('addbp') |
---|
[9938] | 1682 | grok.require('waeup.manageStudent') |
---|
[9864] | 1683 | form_fields = grok.AutoFields(IStudentBalancePayment) |
---|
| 1684 | label = _('Add balance') |
---|
| 1685 | pnav = 4 |
---|
| 1686 | |
---|
| 1687 | @action(_('Create ticket'), style='primary') |
---|
| 1688 | def createTicket(self, **data): |
---|
[9868] | 1689 | p_category = data['p_category'] |
---|
[9864] | 1690 | balance_session = data.get('balance_session', None) |
---|
| 1691 | balance_level = data.get('balance_level', None) |
---|
| 1692 | balance_amount = data.get('balance_amount', None) |
---|
| 1693 | student = self.context.__parent__ |
---|
| 1694 | students_utils = getUtility(IStudentsUtils) |
---|
| 1695 | error, payment = students_utils.setBalanceDetails( |
---|
[9868] | 1696 | p_category, student, balance_session, |
---|
[9864] | 1697 | balance_level, balance_amount) |
---|
| 1698 | if error is not None: |
---|
| 1699 | self.flash(error) |
---|
| 1700 | return |
---|
| 1701 | self.context[payment.p_id] = payment |
---|
| 1702 | self.flash(_('Payment ticket created.')) |
---|
| 1703 | self.redirect(self.url(self.context)) |
---|
| 1704 | return |
---|
| 1705 | |
---|
| 1706 | @action(_('Cancel'), validator=NullValidator) |
---|
| 1707 | def cancel(self, **data): |
---|
| 1708 | self.redirect(self.url(self.context)) |
---|
| 1709 | |
---|
[7819] | 1710 | class OnlinePaymentDisplayFormPage(KofaDisplayFormPage): |
---|
[6869] | 1711 | """ Page to view an online payment ticket |
---|
| 1712 | """ |
---|
[6877] | 1713 | grok.context(IStudentOnlinePayment) |
---|
[6869] | 1714 | grok.name('index') |
---|
| 1715 | grok.require('waeup.viewStudent') |
---|
[9984] | 1716 | form_fields = grok.AutoFields(IStudentOnlinePayment).omit('p_item') |
---|
[8170] | 1717 | form_fields[ |
---|
| 1718 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 1719 | form_fields[ |
---|
| 1720 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[6869] | 1721 | pnav = 4 |
---|
| 1722 | |
---|
| 1723 | @property |
---|
| 1724 | def label(self): |
---|
[7723] | 1725 | return _('${a}: Online Payment Ticket ${b}', mapping = { |
---|
[8736] | 1726 | 'a':self.context.student.display_fullname, |
---|
[7723] | 1727 | 'b':self.context.p_id}) |
---|
[6869] | 1728 | |
---|
[8420] | 1729 | class OnlinePaymentApprovePage(UtilityView, grok.View): |
---|
[6930] | 1730 | """ Callback view |
---|
| 1731 | """ |
---|
| 1732 | grok.context(IStudentOnlinePayment) |
---|
[8420] | 1733 | grok.name('approve') |
---|
| 1734 | grok.require('waeup.managePortal') |
---|
[6930] | 1735 | |
---|
| 1736 | def update(self): |
---|
[8428] | 1737 | success, msg, log = self.context.approveStudentPayment() |
---|
| 1738 | if log is not None: |
---|
[9770] | 1739 | # Add log message to students.log |
---|
[8735] | 1740 | self.context.writeLogMessage(self,log) |
---|
[9770] | 1741 | # Add log message to payments.log |
---|
| 1742 | self.context.logger.info( |
---|
[9779] | 1743 | '%s,%s,%s,%s,%s,,,,,,' % ( |
---|
[9770] | 1744 | self.context.student.student_id, |
---|
| 1745 | self.context.p_id, self.context.p_category, |
---|
| 1746 | self.context.amount_auth, self.context.r_code)) |
---|
[8420] | 1747 | self.flash(msg) |
---|
[6940] | 1748 | return |
---|
[6930] | 1749 | |
---|
| 1750 | def render(self): |
---|
[6940] | 1751 | self.redirect(self.url(self.context, '@@index')) |
---|
[6930] | 1752 | return |
---|
| 1753 | |
---|
[8420] | 1754 | class OnlinePaymentFakeApprovePage(OnlinePaymentApprovePage): |
---|
| 1755 | """ Approval view for students. |
---|
| 1756 | |
---|
| 1757 | This view is used for browser tests only and |
---|
| 1758 | must be neutralized in custom pages! |
---|
| 1759 | """ |
---|
| 1760 | |
---|
| 1761 | grok.name('fake_approve') |
---|
| 1762 | grok.require('waeup.payStudent') |
---|
| 1763 | |
---|
[7459] | 1764 | class ExportPDFPaymentSlipPage(UtilityView, grok.View): |
---|
[7019] | 1765 | """Deliver a PDF slip of the context. |
---|
| 1766 | """ |
---|
| 1767 | grok.context(IStudentOnlinePayment) |
---|
[8262] | 1768 | grok.name('payment_slip.pdf') |
---|
[7019] | 1769 | grok.require('waeup.viewStudent') |
---|
[9984] | 1770 | form_fields = grok.AutoFields(IStudentOnlinePayment).omit('p_item') |
---|
[8173] | 1771 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 1772 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[7019] | 1773 | prefix = 'form' |
---|
[8258] | 1774 | note = None |
---|
[9702] | 1775 | omit_fields = ( |
---|
[10256] | 1776 | 'password', 'suspended', 'phone', 'date_of_birth', |
---|
[9702] | 1777 | 'adm_code', 'sex', 'suspended_comment') |
---|
[7019] | 1778 | |
---|
| 1779 | @property |
---|
[8262] | 1780 | def title(self): |
---|
| 1781 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 1782 | return translate(_('Payment Data'), 'waeup.kofa', |
---|
| 1783 | target_language=portal_language) |
---|
| 1784 | |
---|
| 1785 | @property |
---|
[7019] | 1786 | def label(self): |
---|
[8262] | 1787 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 1788 | return translate(_('Online Payment Slip'), |
---|
| 1789 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 1790 | + ' %s' % self.context.p_id |
---|
[7019] | 1791 | |
---|
| 1792 | def render(self): |
---|
[8262] | 1793 | #if self.context.p_state != 'paid': |
---|
| 1794 | # self.flash('Ticket not yet paid.') |
---|
| 1795 | # self.redirect(self.url(self.context)) |
---|
| 1796 | # return |
---|
[9141] | 1797 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[9375] | 1798 | self.request, self.omit_fields) |
---|
[7150] | 1799 | students_utils = getUtility(IStudentsUtils) |
---|
[8262] | 1800 | return students_utils.renderPDF(self, 'payment_slip.pdf', |
---|
[10250] | 1801 | self.context.student, studentview, note=self.note, |
---|
| 1802 | omit_fields=self.omit_fields) |
---|
[7019] | 1803 | |
---|
[6992] | 1804 | |
---|
[7819] | 1805 | class AccommodationManageFormPage(KofaEditFormPage): |
---|
[7009] | 1806 | """ Page to manage bed tickets. |
---|
[7642] | 1807 | |
---|
| 1808 | This manage form page is for both students and students officers. |
---|
[6635] | 1809 | """ |
---|
| 1810 | grok.context(IStudentAccommodation) |
---|
| 1811 | grok.name('index') |
---|
[7181] | 1812 | grok.require('waeup.handleAccommodation') |
---|
[6635] | 1813 | form_fields = grok.AutoFields(IStudentAccommodation) |
---|
[6992] | 1814 | grok.template('accommodationmanagepage') |
---|
[6642] | 1815 | pnav = 4 |
---|
[7723] | 1816 | officers_only_actions = [_('Remove selected')] |
---|
[6635] | 1817 | |
---|
| 1818 | @property |
---|
| 1819 | def label(self): |
---|
[7723] | 1820 | return _('${a}: Accommodation', |
---|
| 1821 | mapping = {'a':self.context.__parent__.display_fullname}) |
---|
[6637] | 1822 | |
---|
[6992] | 1823 | def update(self): |
---|
| 1824 | super(AccommodationManageFormPage, self).update() |
---|
| 1825 | datatable.need() |
---|
[7329] | 1826 | warning.need() |
---|
[6992] | 1827 | return |
---|
| 1828 | |
---|
[7723] | 1829 | @jsaction(_('Remove selected')) |
---|
[7009] | 1830 | def delBedTickets(self, **data): |
---|
[7240] | 1831 | if getattr(self.request.principal, 'user_type', None) == 'student': |
---|
[7723] | 1832 | self.flash(_('You are not allowed to remove bed tickets.')) |
---|
[7017] | 1833 | self.redirect(self.url(self.context)) |
---|
| 1834 | return |
---|
[6992] | 1835 | form = self.request.form |
---|
[9701] | 1836 | if 'val_id' in form: |
---|
[6992] | 1837 | child_id = form['val_id'] |
---|
| 1838 | else: |
---|
[7723] | 1839 | self.flash(_('No bed ticket selected.')) |
---|
[6992] | 1840 | self.redirect(self.url(self.context)) |
---|
| 1841 | return |
---|
| 1842 | if not isinstance(child_id, list): |
---|
| 1843 | child_id = [child_id] |
---|
| 1844 | deleted = [] |
---|
| 1845 | for id in child_id: |
---|
[7068] | 1846 | del self.context[id] |
---|
| 1847 | deleted.append(id) |
---|
[6992] | 1848 | if len(deleted): |
---|
[7723] | 1849 | self.flash(_('Successfully removed: ${a}', |
---|
| 1850 | mapping = {'a':', '.join(deleted)})) |
---|
[8735] | 1851 | self.context.writeLogMessage( |
---|
| 1852 | self,'removed: % s' % ', '.join(deleted)) |
---|
[6992] | 1853 | self.redirect(self.url(self.context)) |
---|
| 1854 | return |
---|
| 1855 | |
---|
[7009] | 1856 | @property |
---|
| 1857 | def selected_actions(self): |
---|
[7240] | 1858 | if getattr(self.request.principal, 'user_type', None) == 'student': |
---|
[7642] | 1859 | return [action for action in self.actions |
---|
| 1860 | if not action.label in self.officers_only_actions] |
---|
| 1861 | return self.actions |
---|
[7009] | 1862 | |
---|
[7819] | 1863 | class BedTicketAddPage(KofaPage): |
---|
[6992] | 1864 | """ Page to add an online payment ticket |
---|
| 1865 | """ |
---|
| 1866 | grok.context(IStudentAccommodation) |
---|
| 1867 | grok.name('add') |
---|
[7181] | 1868 | grok.require('waeup.handleAccommodation') |
---|
[6992] | 1869 | grok.template('enterpin') |
---|
[6993] | 1870 | ac_prefix = 'HOS' |
---|
[7723] | 1871 | label = _('Add bed ticket') |
---|
[6992] | 1872 | pnav = 4 |
---|
[7723] | 1873 | buttonname = _('Create bed ticket') |
---|
[6993] | 1874 | notice = '' |
---|
[9188] | 1875 | with_ac = True |
---|
[6992] | 1876 | |
---|
| 1877 | def update(self, SUBMIT=None): |
---|
[8736] | 1878 | student = self.context.student |
---|
[7150] | 1879 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1880 | acc_details = students_utils.getAccommodationDetails(student) |
---|
[8688] | 1881 | if acc_details.get('expired', False): |
---|
| 1882 | startdate = acc_details.get('startdate') |
---|
| 1883 | enddate = acc_details.get('enddate') |
---|
| 1884 | if startdate and enddate: |
---|
| 1885 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 1886 | startdate = to_timezone( |
---|
| 1887 | startdate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 1888 | enddate = to_timezone( |
---|
| 1889 | enddate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 1890 | self.flash(_("Outside booking period: ${a} - ${b}", |
---|
| 1891 | mapping = {'a': startdate, 'b': enddate})) |
---|
| 1892 | else: |
---|
| 1893 | self.flash(_("Outside booking period.")) |
---|
| 1894 | self.redirect(self.url(self.context)) |
---|
| 1895 | return |
---|
[7369] | 1896 | if not acc_details: |
---|
[7723] | 1897 | self.flash(_("Your data are incomplete.")) |
---|
[7369] | 1898 | self.redirect(self.url(self.context)) |
---|
| 1899 | return |
---|
[6996] | 1900 | if not student.state in acc_details['allowed_states']: |
---|
[7723] | 1901 | self.flash(_("You are in the wrong registration state.")) |
---|
[6992] | 1902 | self.redirect(self.url(self.context)) |
---|
| 1903 | return |
---|
[7642] | 1904 | if student['studycourse'].current_session != acc_details[ |
---|
| 1905 | 'booking_session']: |
---|
[7061] | 1906 | self.flash( |
---|
[7723] | 1907 | _('Your current session does not match accommodation session.')) |
---|
[7061] | 1908 | self.redirect(self.url(self.context)) |
---|
| 1909 | return |
---|
| 1910 | if str(acc_details['booking_session']) in self.context.keys(): |
---|
[7642] | 1911 | self.flash( |
---|
[7723] | 1912 | _('You already booked a bed space in current ' \ |
---|
| 1913 | + 'accommodation session.')) |
---|
[7004] | 1914 | self.redirect(self.url(self.context)) |
---|
| 1915 | return |
---|
[9188] | 1916 | if self.with_ac: |
---|
| 1917 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 1918 | self.ac_number = self.request.form.get('ac_number', None) |
---|
[6992] | 1919 | if SUBMIT is None: |
---|
| 1920 | return |
---|
[9188] | 1921 | if self.with_ac: |
---|
| 1922 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 1923 | code = get_access_code(pin) |
---|
| 1924 | if not code: |
---|
| 1925 | self.flash(_('Activation code is invalid.')) |
---|
| 1926 | return |
---|
[7060] | 1927 | # Search and book bed |
---|
[6997] | 1928 | cat = queryUtility(ICatalog, name='beds_catalog', default=None) |
---|
| 1929 | entries = cat.searchResults( |
---|
[7003] | 1930 | owner=(student.student_id,student.student_id)) |
---|
| 1931 | if len(entries): |
---|
[9188] | 1932 | # If bed space has been manually allocated use this bed |
---|
[7003] | 1933 | bed = [entry for entry in entries][0] |
---|
[9424] | 1934 | # Safety belt for paranoids: Does this bed really exist on portal? |
---|
| 1935 | # XXX: Can be remove if nobody complains. |
---|
| 1936 | if bed.__parent__.__parent__ is None: |
---|
| 1937 | self.flash(_('System error: Please contact the adminsitrator.')) |
---|
[9428] | 1938 | self.context.writeLogMessage(self, 'fatal error: %s' % bed.bed_id) |
---|
[9424] | 1939 | return |
---|
[7060] | 1940 | else: |
---|
| 1941 | # else search for other available beds |
---|
| 1942 | entries = cat.searchResults( |
---|
| 1943 | bed_type=(acc_details['bt'],acc_details['bt'])) |
---|
| 1944 | available_beds = [ |
---|
| 1945 | entry for entry in entries if entry.owner == NOT_OCCUPIED] |
---|
| 1946 | if available_beds: |
---|
[7150] | 1947 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 1948 | bed = students_utils.selectBed(available_beds) |
---|
[9424] | 1949 | # Safety belt for paranoids: Does this bed really exist in portal? |
---|
| 1950 | # XXX: Can be remove if nobody complains. |
---|
| 1951 | if bed.__parent__.__parent__ is None: |
---|
| 1952 | self.flash(_('System error: Please contact the adminsitrator.')) |
---|
[9428] | 1953 | self.context.writeLogMessage(self, 'fatal error: %s' % bed.bed_id) |
---|
[9424] | 1954 | return |
---|
[7060] | 1955 | bed.bookBed(student.student_id) |
---|
| 1956 | else: |
---|
[7723] | 1957 | self.flash(_('There is no free bed in your category ${a}.', |
---|
| 1958 | mapping = {'a':acc_details['bt']})) |
---|
[7060] | 1959 | return |
---|
[9188] | 1960 | if self.with_ac: |
---|
| 1961 | # Mark pin as used (this also fires a pin related transition) |
---|
| 1962 | if code.state == USED: |
---|
| 1963 | self.flash(_('Activation code has already been used.')) |
---|
[6992] | 1964 | return |
---|
[9188] | 1965 | else: |
---|
| 1966 | comment = _(u'invalidated') |
---|
| 1967 | # Here we know that the ac is in state initialized so we do not |
---|
| 1968 | # expect an exception, but the owner might be different |
---|
| 1969 | if not invalidate_accesscode( |
---|
| 1970 | pin,comment,self.context.student.student_id): |
---|
| 1971 | self.flash(_('You are not the owner of this access code.')) |
---|
| 1972 | return |
---|
[7060] | 1973 | # Create bed ticket |
---|
[6992] | 1974 | bedticket = createObject(u'waeup.BedTicket') |
---|
[9189] | 1975 | if self.with_ac: |
---|
| 1976 | bedticket.booking_code = pin |
---|
[6994] | 1977 | bedticket.booking_session = acc_details['booking_session'] |
---|
[6996] | 1978 | bedticket.bed_type = acc_details['bt'] |
---|
[7006] | 1979 | bedticket.bed = bed |
---|
[6996] | 1980 | hall_title = bed.__parent__.hostel_name |
---|
[9199] | 1981 | coordinates = bed.coordinates[1:] |
---|
[6996] | 1982 | block, room_nr, bed_nr = coordinates |
---|
[7723] | 1983 | bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = { |
---|
| 1984 | 'a':hall_title, 'b':block, |
---|
| 1985 | 'c':room_nr, 'd':bed_nr, |
---|
| 1986 | 'e':bed.bed_type}) |
---|
[7819] | 1987 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7723] | 1988 | bedticket.bed_coordinates = translate( |
---|
[7811] | 1989 | bc, 'waeup.kofa',target_language=portal_language) |
---|
[9423] | 1990 | self.context.addBedTicket(bedticket) |
---|
[9411] | 1991 | self.context.writeLogMessage(self, 'booked: %s' % bed.bed_id) |
---|
[7723] | 1992 | self.flash(_('Bed ticket created and bed booked: ${a}', |
---|
[9984] | 1993 | mapping = {'a':bedticket.display_coordinates})) |
---|
[6992] | 1994 | self.redirect(self.url(self.context)) |
---|
| 1995 | return |
---|
| 1996 | |
---|
[7819] | 1997 | class BedTicketDisplayFormPage(KofaDisplayFormPage): |
---|
[6994] | 1998 | """ Page to display bed tickets |
---|
| 1999 | """ |
---|
| 2000 | grok.context(IBedTicket) |
---|
| 2001 | grok.name('index') |
---|
[7181] | 2002 | grok.require('waeup.handleAccommodation') |
---|
[9984] | 2003 | form_fields = grok.AutoFields(IBedTicket).omit('bed_coordinates') |
---|
[9201] | 2004 | form_fields['booking_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[6994] | 2005 | pnav = 4 |
---|
| 2006 | |
---|
| 2007 | @property |
---|
| 2008 | def label(self): |
---|
[7723] | 2009 | return _('Bed Ticket for Session ${a}', |
---|
| 2010 | mapping = {'a':self.context.getSessionString()}) |
---|
[6994] | 2011 | |
---|
[7459] | 2012 | class ExportPDFBedTicketSlipPage(UtilityView, grok.View): |
---|
[7027] | 2013 | """Deliver a PDF slip of the context. |
---|
| 2014 | """ |
---|
| 2015 | grok.context(IBedTicket) |
---|
[9452] | 2016 | grok.name('bed_allocation_slip.pdf') |
---|
[7181] | 2017 | grok.require('waeup.handleAccommodation') |
---|
[9984] | 2018 | form_fields = grok.AutoFields(IBedTicket).omit('bed_coordinates') |
---|
[8173] | 2019 | form_fields['booking_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[7027] | 2020 | prefix = 'form' |
---|
[9702] | 2021 | omit_fields = ( |
---|
[10256] | 2022 | 'password', 'suspended', 'phone', 'adm_code', |
---|
| 2023 | 'suspended_comment', 'date_of_birth') |
---|
[7027] | 2024 | |
---|
| 2025 | @property |
---|
[7723] | 2026 | def title(self): |
---|
[7819] | 2027 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 2028 | return translate(_('Bed Allocation Data'), 'waeup.kofa', |
---|
[7723] | 2029 | target_language=portal_language) |
---|
| 2030 | |
---|
| 2031 | @property |
---|
[7027] | 2032 | def label(self): |
---|
[7819] | 2033 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9201] | 2034 | #return translate(_('Bed Allocation: '), |
---|
| 2035 | # 'waeup.kofa', target_language=portal_language) \ |
---|
| 2036 | # + ' %s' % self.context.bed_coordinates |
---|
| 2037 | return translate(_('Bed Allocation Slip'), |
---|
[7811] | 2038 | 'waeup.kofa', target_language=portal_language) \ |
---|
[9201] | 2039 | + ' %s' % self.context.getSessionString() |
---|
[7027] | 2040 | |
---|
| 2041 | def render(self): |
---|
[9141] | 2042 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
[9375] | 2043 | self.request, self.omit_fields) |
---|
[7150] | 2044 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 2045 | return students_utils.renderPDF( |
---|
[9452] | 2046 | self, 'bed_allocation_slip.pdf', |
---|
[10250] | 2047 | self.context.student, studentview, |
---|
| 2048 | omit_fields=self.omit_fields) |
---|
[7027] | 2049 | |
---|
[7459] | 2050 | class BedTicketRelocationPage(UtilityView, grok.View): |
---|
[7015] | 2051 | """ Callback view |
---|
| 2052 | """ |
---|
| 2053 | grok.context(IBedTicket) |
---|
| 2054 | grok.name('relocate') |
---|
| 2055 | grok.require('waeup.manageHostels') |
---|
| 2056 | |
---|
[7059] | 2057 | # Relocate student if student parameters have changed or the bed_type |
---|
| 2058 | # of the bed has changed |
---|
[7015] | 2059 | def update(self): |
---|
[8736] | 2060 | student = self.context.student |
---|
[7150] | 2061 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 2062 | acc_details = students_utils.getAccommodationDetails(student) |
---|
[7068] | 2063 | if self.context.bed != None and \ |
---|
| 2064 | 'reserved' in self.context.bed.bed_type: |
---|
[7723] | 2065 | self.flash(_("Students in reserved beds can't be relocated.")) |
---|
[7068] | 2066 | self.redirect(self.url(self.context)) |
---|
| 2067 | return |
---|
[7059] | 2068 | if acc_details['bt'] == self.context.bed_type and \ |
---|
[7068] | 2069 | self.context.bed != None and \ |
---|
[7059] | 2070 | self.context.bed.bed_type == self.context.bed_type: |
---|
[7723] | 2071 | self.flash(_("Student can't be relocated.")) |
---|
[7068] | 2072 | self.redirect(self.url(self.context)) |
---|
[7015] | 2073 | return |
---|
[7068] | 2074 | # Search a bed |
---|
[7015] | 2075 | cat = queryUtility(ICatalog, name='beds_catalog', default=None) |
---|
| 2076 | entries = cat.searchResults( |
---|
[7068] | 2077 | owner=(student.student_id,student.student_id)) |
---|
| 2078 | if len(entries) and self.context.bed == None: |
---|
| 2079 | # If booking has been cancelled but other bed space has been |
---|
| 2080 | # manually allocated after cancellation use this bed |
---|
| 2081 | new_bed = [entry for entry in entries][0] |
---|
| 2082 | else: |
---|
| 2083 | # Search for other available beds |
---|
| 2084 | entries = cat.searchResults( |
---|
| 2085 | bed_type=(acc_details['bt'],acc_details['bt'])) |
---|
| 2086 | available_beds = [ |
---|
| 2087 | entry for entry in entries if entry.owner == NOT_OCCUPIED] |
---|
| 2088 | if available_beds: |
---|
[7150] | 2089 | students_utils = getUtility(IStudentsUtils) |
---|
[7186] | 2090 | new_bed = students_utils.selectBed(available_beds) |
---|
[7068] | 2091 | new_bed.bookBed(student.student_id) |
---|
| 2092 | else: |
---|
[7723] | 2093 | self.flash(_('There is no free bed in your category ${a}.', |
---|
| 2094 | mapping = {'a':acc_details['bt']})) |
---|
[7068] | 2095 | self.redirect(self.url(self.context)) |
---|
| 2096 | return |
---|
[7642] | 2097 | # Release old bed if exists |
---|
[7068] | 2098 | if self.context.bed != None: |
---|
| 2099 | self.context.bed.owner = NOT_OCCUPIED |
---|
| 2100 | notify(grok.ObjectModifiedEvent(self.context.bed)) |
---|
[7015] | 2101 | # Alocate new bed |
---|
| 2102 | self.context.bed_type = acc_details['bt'] |
---|
[7068] | 2103 | self.context.bed = new_bed |
---|
| 2104 | hall_title = new_bed.__parent__.hostel_name |
---|
[9199] | 2105 | coordinates = new_bed.coordinates[1:] |
---|
[7015] | 2106 | block, room_nr, bed_nr = coordinates |
---|
[7723] | 2107 | bc = _('${a}, Block ${b}, Room ${c}, Bed ${d} (${e})', mapping = { |
---|
| 2108 | 'a':hall_title, 'b':block, |
---|
| 2109 | 'c':room_nr, 'd':bed_nr, |
---|
| 2110 | 'e':new_bed.bed_type}) |
---|
[7819] | 2111 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7723] | 2112 | self.context.bed_coordinates = translate( |
---|
[7811] | 2113 | bc, 'waeup.kofa',target_language=portal_language) |
---|
[9411] | 2114 | self.context.writeLogMessage(self, 'relocated: %s' % new_bed.bed_id) |
---|
[7723] | 2115 | self.flash(_('Student relocated: ${a}', |
---|
[9984] | 2116 | mapping = {'a':self.context.display_coordinates})) |
---|
[7015] | 2117 | self.redirect(self.url(self.context)) |
---|
| 2118 | return |
---|
| 2119 | |
---|
| 2120 | def render(self): |
---|
| 2121 | return |
---|
| 2122 | |
---|
[7819] | 2123 | class StudentHistoryPage(KofaPage): |
---|
[6637] | 2124 | """ Page to display student clearance data |
---|
| 2125 | """ |
---|
| 2126 | grok.context(IStudent) |
---|
| 2127 | grok.name('history') |
---|
[6660] | 2128 | grok.require('waeup.viewStudent') |
---|
[6637] | 2129 | grok.template('studenthistory') |
---|
[6642] | 2130 | pnav = 4 |
---|
[6637] | 2131 | |
---|
| 2132 | @property |
---|
| 2133 | def label(self): |
---|
[7723] | 2134 | return _('${a}: History', mapping = {'a':self.context.display_fullname}) |
---|
[6694] | 2135 | |
---|
| 2136 | # Pages for students only |
---|
| 2137 | |
---|
[7819] | 2138 | class StudentBaseEditFormPage(KofaEditFormPage): |
---|
[7133] | 2139 | """ View to edit student base data |
---|
| 2140 | """ |
---|
| 2141 | grok.context(IStudent) |
---|
| 2142 | grok.name('edit_base') |
---|
| 2143 | grok.require('waeup.handleStudent') |
---|
| 2144 | form_fields = grok.AutoFields(IStudentBase).select( |
---|
| 2145 | 'email', 'phone') |
---|
[7723] | 2146 | label = _('Edit base data') |
---|
[7133] | 2147 | pnav = 4 |
---|
| 2148 | |
---|
[7723] | 2149 | @action(_('Save'), style='primary') |
---|
[7133] | 2150 | def save(self, **data): |
---|
| 2151 | msave(self, **data) |
---|
| 2152 | return |
---|
| 2153 | |
---|
[7819] | 2154 | class StudentChangePasswordPage(KofaEditFormPage): |
---|
[7144] | 2155 | """ View to manage student base data |
---|
[6756] | 2156 | """ |
---|
| 2157 | grok.context(IStudent) |
---|
[7114] | 2158 | grok.name('change_password') |
---|
[6694] | 2159 | grok.require('waeup.handleStudent') |
---|
[7144] | 2160 | grok.template('change_password') |
---|
[7723] | 2161 | label = _('Change password') |
---|
[6694] | 2162 | pnav = 4 |
---|
| 2163 | |
---|
[7723] | 2164 | @action(_('Save'), style='primary') |
---|
[7144] | 2165 | def save(self, **data): |
---|
| 2166 | form = self.request.form |
---|
| 2167 | password = form.get('change_password', None) |
---|
| 2168 | password_ctl = form.get('change_password_repeat', None) |
---|
| 2169 | if password: |
---|
[7147] | 2170 | validator = getUtility(IPasswordValidator) |
---|
| 2171 | errors = validator.validate_password(password, password_ctl) |
---|
| 2172 | if not errors: |
---|
| 2173 | IUserAccount(self.context).setPassword(password) |
---|
[8735] | 2174 | self.context.writeLogMessage(self, 'saved: password') |
---|
[7723] | 2175 | self.flash(_('Password changed.')) |
---|
[6756] | 2176 | else: |
---|
[7147] | 2177 | self.flash( ' '.join(errors)) |
---|
[6756] | 2178 | return |
---|
| 2179 | |
---|
[7819] | 2180 | class StudentFilesUploadPage(KofaPage): |
---|
[7114] | 2181 | """ View to upload files by student |
---|
| 2182 | """ |
---|
| 2183 | grok.context(IStudent) |
---|
| 2184 | grok.name('change_portrait') |
---|
[7127] | 2185 | grok.require('waeup.uploadStudentFile') |
---|
[7114] | 2186 | grok.template('filesuploadpage') |
---|
[7723] | 2187 | label = _('Upload portrait') |
---|
[7114] | 2188 | pnav = 4 |
---|
| 2189 | |
---|
[7133] | 2190 | def update(self): |
---|
[8736] | 2191 | if self.context.student.state != ADMITTED: |
---|
[7145] | 2192 | emit_lock_message(self) |
---|
[7133] | 2193 | return |
---|
| 2194 | super(StudentFilesUploadPage, self).update() |
---|
| 2195 | return |
---|
| 2196 | |
---|
[7819] | 2197 | class StartClearancePage(KofaPage): |
---|
[6770] | 2198 | grok.context(IStudent) |
---|
| 2199 | grok.name('start_clearance') |
---|
| 2200 | grok.require('waeup.handleStudent') |
---|
| 2201 | grok.template('enterpin') |
---|
[7723] | 2202 | label = _('Start clearance') |
---|
[6770] | 2203 | ac_prefix = 'CLR' |
---|
| 2204 | notice = '' |
---|
| 2205 | pnav = 4 |
---|
[7723] | 2206 | buttonname = _('Start clearance now') |
---|
[9952] | 2207 | with_ac = True |
---|
[6770] | 2208 | |
---|
[7133] | 2209 | @property |
---|
| 2210 | def all_required_fields_filled(self): |
---|
| 2211 | if self.context.email and self.context.phone: |
---|
| 2212 | return True |
---|
| 2213 | return False |
---|
| 2214 | |
---|
| 2215 | @property |
---|
| 2216 | def portrait_uploaded(self): |
---|
| 2217 | store = getUtility(IExtFileStore) |
---|
| 2218 | if store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
| 2219 | return True |
---|
| 2220 | return False |
---|
| 2221 | |
---|
[6770] | 2222 | def update(self, SUBMIT=None): |
---|
[7671] | 2223 | if not self.context.state == ADMITTED: |
---|
[7745] | 2224 | self.flash(_("Wrong state")) |
---|
[6936] | 2225 | self.redirect(self.url(self.context)) |
---|
| 2226 | return |
---|
[7133] | 2227 | if not self.portrait_uploaded: |
---|
[7723] | 2228 | self.flash(_("No portrait uploaded.")) |
---|
[7133] | 2229 | self.redirect(self.url(self.context, 'change_portrait')) |
---|
| 2230 | return |
---|
| 2231 | if not self.all_required_fields_filled: |
---|
[7723] | 2232 | self.flash(_("Not all required fields filled.")) |
---|
[7133] | 2233 | self.redirect(self.url(self.context, 'edit_base')) |
---|
| 2234 | return |
---|
[9952] | 2235 | if self.with_ac: |
---|
| 2236 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 2237 | self.ac_number = self.request.form.get('ac_number', None) |
---|
[6770] | 2238 | if SUBMIT is None: |
---|
| 2239 | return |
---|
[9952] | 2240 | if self.with_ac: |
---|
| 2241 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 2242 | code = get_access_code(pin) |
---|
| 2243 | if not code: |
---|
| 2244 | self.flash(_('Activation code is invalid.')) |
---|
| 2245 | return |
---|
| 2246 | if code.state == USED: |
---|
| 2247 | self.flash(_('Activation code has already been used.')) |
---|
| 2248 | return |
---|
| 2249 | # Mark pin as used (this also fires a pin related transition) |
---|
| 2250 | # and fire transition start_clearance |
---|
| 2251 | comment = _(u"invalidated") |
---|
| 2252 | # Here we know that the ac is in state initialized so we do not |
---|
| 2253 | # expect an exception, but the owner might be different |
---|
| 2254 | if not invalidate_accesscode(pin, comment, self.context.student_id): |
---|
| 2255 | self.flash(_('You are not the owner of this access code.')) |
---|
| 2256 | return |
---|
| 2257 | self.context.clr_code = pin |
---|
[6770] | 2258 | IWorkflowInfo(self.context).fireTransition('start_clearance') |
---|
[7723] | 2259 | self.flash(_('Clearance process has been started.')) |
---|
[6770] | 2260 | self.redirect(self.url(self.context,'cedit')) |
---|
| 2261 | return |
---|
| 2262 | |
---|
[6695] | 2263 | class StudentClearanceEditFormPage(StudentClearanceManageFormPage): |
---|
| 2264 | """ View to edit student clearance data by student |
---|
| 2265 | """ |
---|
| 2266 | grok.context(IStudent) |
---|
| 2267 | grok.name('cedit') |
---|
| 2268 | grok.require('waeup.handleStudent') |
---|
[7723] | 2269 | label = _('Edit clearance data') |
---|
[6718] | 2270 | |
---|
[7993] | 2271 | @property |
---|
| 2272 | def form_fields(self): |
---|
[8472] | 2273 | if self.context.is_postgrad: |
---|
[8974] | 2274 | form_fields = grok.AutoFields(IPGStudentClearance).omit( |
---|
[9486] | 2275 | 'clearance_locked', 'clr_code', 'officer_comment') |
---|
[7993] | 2276 | else: |
---|
[8974] | 2277 | form_fields = grok.AutoFields(IUGStudentClearance).omit( |
---|
[9486] | 2278 | 'clearance_locked', 'clr_code', 'officer_comment') |
---|
[7993] | 2279 | return form_fields |
---|
| 2280 | |
---|
[6718] | 2281 | def update(self): |
---|
| 2282 | if self.context.clearance_locked: |
---|
[7145] | 2283 | emit_lock_message(self) |
---|
[6718] | 2284 | return |
---|
| 2285 | return super(StudentClearanceEditFormPage, self).update() |
---|
[6719] | 2286 | |
---|
[7723] | 2287 | @action(_('Save'), style='primary') |
---|
[6722] | 2288 | def save(self, **data): |
---|
| 2289 | self.applyData(self.context, **data) |
---|
[7723] | 2290 | self.flash(_('Clearance form has been saved.')) |
---|
[6722] | 2291 | return |
---|
| 2292 | |
---|
[7253] | 2293 | def dataNotComplete(self): |
---|
[7642] | 2294 | """To be implemented in the customization package. |
---|
| 2295 | """ |
---|
[7253] | 2296 | return False |
---|
| 2297 | |
---|
[7723] | 2298 | @action(_('Save and request clearance'), style='primary') |
---|
[7186] | 2299 | def requestClearance(self, **data): |
---|
[6722] | 2300 | self.applyData(self.context, **data) |
---|
[7253] | 2301 | if self.dataNotComplete(): |
---|
| 2302 | self.flash(self.dataNotComplete()) |
---|
| 2303 | return |
---|
[7723] | 2304 | self.flash(_('Clearance form has been saved.')) |
---|
[9021] | 2305 | if self.context.clr_code: |
---|
| 2306 | self.redirect(self.url(self.context, 'request_clearance')) |
---|
| 2307 | else: |
---|
| 2308 | # We bypass the request_clearance page if student |
---|
| 2309 | # has been imported in state 'clearance started' and |
---|
| 2310 | # no clr_code was entered before. |
---|
| 2311 | state = IWorkflowState(self.context).getState() |
---|
| 2312 | if state != CLEARANCE: |
---|
| 2313 | # This shouldn't happen, but the application officer |
---|
| 2314 | # might have forgotten to lock the form after changing the state |
---|
| 2315 | self.flash(_('This form cannot be submitted. Wrong state!')) |
---|
| 2316 | return |
---|
| 2317 | IWorkflowInfo(self.context).fireTransition('request_clearance') |
---|
| 2318 | self.flash(_('Clearance has been requested.')) |
---|
| 2319 | self.redirect(self.url(self.context)) |
---|
[6722] | 2320 | return |
---|
| 2321 | |
---|
[7819] | 2322 | class RequestClearancePage(KofaPage): |
---|
[6769] | 2323 | grok.context(IStudent) |
---|
| 2324 | grok.name('request_clearance') |
---|
| 2325 | grok.require('waeup.handleStudent') |
---|
| 2326 | grok.template('enterpin') |
---|
[7723] | 2327 | label = _('Request clearance') |
---|
| 2328 | notice = _('Enter the CLR access code used for starting clearance.') |
---|
[6769] | 2329 | ac_prefix = 'CLR' |
---|
| 2330 | pnav = 4 |
---|
[7723] | 2331 | buttonname = _('Request clearance now') |
---|
[9952] | 2332 | with_ac = True |
---|
[6769] | 2333 | |
---|
| 2334 | def update(self, SUBMIT=None): |
---|
[9952] | 2335 | if self.with_ac: |
---|
| 2336 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 2337 | self.ac_number = self.request.form.get('ac_number', None) |
---|
[6769] | 2338 | if SUBMIT is None: |
---|
| 2339 | return |
---|
[9952] | 2340 | if self.with_ac: |
---|
| 2341 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 2342 | if self.context.clr_code and self.context.clr_code != pin: |
---|
| 2343 | self.flash(_("This isn't your CLR access code.")) |
---|
| 2344 | return |
---|
[6769] | 2345 | state = IWorkflowState(self.context).getState() |
---|
| 2346 | if state != CLEARANCE: |
---|
[9021] | 2347 | # This shouldn't happen, but the application officer |
---|
| 2348 | # might have forgotten to lock the form after changing the state |
---|
[7723] | 2349 | self.flash(_('This form cannot be submitted. Wrong state!')) |
---|
[6769] | 2350 | return |
---|
| 2351 | IWorkflowInfo(self.context).fireTransition('request_clearance') |
---|
[7723] | 2352 | self.flash(_('Clearance has been requested.')) |
---|
[6769] | 2353 | self.redirect(self.url(self.context)) |
---|
[6789] | 2354 | return |
---|
[6806] | 2355 | |
---|
[8471] | 2356 | class StartSessionPage(KofaPage): |
---|
[6944] | 2357 | grok.context(IStudentStudyCourse) |
---|
[8471] | 2358 | grok.name('start_session') |
---|
[6944] | 2359 | grok.require('waeup.handleStudent') |
---|
| 2360 | grok.template('enterpin') |
---|
[8471] | 2361 | label = _('Start session') |
---|
[6944] | 2362 | ac_prefix = 'SFE' |
---|
| 2363 | notice = '' |
---|
| 2364 | pnav = 4 |
---|
[8471] | 2365 | buttonname = _('Start now') |
---|
[9952] | 2366 | with_ac = True |
---|
[6944] | 2367 | |
---|
| 2368 | def update(self, SUBMIT=None): |
---|
[9139] | 2369 | if not self.context.is_current: |
---|
| 2370 | emit_lock_message(self) |
---|
| 2371 | return |
---|
| 2372 | super(StartSessionPage, self).update() |
---|
[8471] | 2373 | if not self.context.next_session_allowed: |
---|
| 2374 | self.flash(_("You are not entitled to start session.")) |
---|
[6944] | 2375 | self.redirect(self.url(self.context)) |
---|
| 2376 | return |
---|
[9952] | 2377 | if self.with_ac: |
---|
| 2378 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 2379 | self.ac_number = self.request.form.get('ac_number', None) |
---|
[6944] | 2380 | if SUBMIT is None: |
---|
| 2381 | return |
---|
[9952] | 2382 | if self.with_ac: |
---|
| 2383 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 2384 | code = get_access_code(pin) |
---|
| 2385 | if not code: |
---|
| 2386 | self.flash(_('Activation code is invalid.')) |
---|
[6944] | 2387 | return |
---|
[9952] | 2388 | # Mark pin as used (this also fires a pin related transition) |
---|
| 2389 | if code.state == USED: |
---|
| 2390 | self.flash(_('Activation code has already been used.')) |
---|
| 2391 | return |
---|
| 2392 | else: |
---|
| 2393 | comment = _(u"invalidated") |
---|
| 2394 | # Here we know that the ac is in state initialized so we do not |
---|
| 2395 | # expect an error, but the owner might be different |
---|
| 2396 | if not invalidate_accesscode( |
---|
| 2397 | pin,comment,self.context.student.student_id): |
---|
| 2398 | self.flash(_('You are not the owner of this access code.')) |
---|
| 2399 | return |
---|
[9637] | 2400 | try: |
---|
| 2401 | if self.context.student.state == CLEARED: |
---|
| 2402 | IWorkflowInfo(self.context.student).fireTransition( |
---|
| 2403 | 'pay_first_school_fee') |
---|
| 2404 | elif self.context.student.state == RETURNING: |
---|
| 2405 | IWorkflowInfo(self.context.student).fireTransition( |
---|
| 2406 | 'pay_school_fee') |
---|
| 2407 | elif self.context.student.state == PAID: |
---|
| 2408 | IWorkflowInfo(self.context.student).fireTransition( |
---|
| 2409 | 'pay_pg_fee') |
---|
| 2410 | except ConstraintNotSatisfied: |
---|
| 2411 | self.flash(_('An error occurred, please contact the system administrator.')) |
---|
| 2412 | return |
---|
[8471] | 2413 | self.flash(_('Session started.')) |
---|
[6944] | 2414 | self.redirect(self.url(self.context)) |
---|
| 2415 | return |
---|
| 2416 | |
---|
[7819] | 2417 | class AddStudyLevelFormPage(KofaEditFormPage): |
---|
[6806] | 2418 | """ Page for students to add current study levels |
---|
| 2419 | """ |
---|
| 2420 | grok.context(IStudentStudyCourse) |
---|
| 2421 | grok.name('add') |
---|
| 2422 | grok.require('waeup.handleStudent') |
---|
| 2423 | grok.template('studyleveladdpage') |
---|
| 2424 | form_fields = grok.AutoFields(IStudentStudyCourse) |
---|
| 2425 | pnav = 4 |
---|
| 2426 | |
---|
| 2427 | @property |
---|
| 2428 | def label(self): |
---|
| 2429 | studylevelsource = StudyLevelSource().factory |
---|
| 2430 | code = self.context.current_level |
---|
| 2431 | title = studylevelsource.getTitle(self.context, code) |
---|
[7723] | 2432 | return _('Add current level ${a}', mapping = {'a':title}) |
---|
[6806] | 2433 | |
---|
| 2434 | def update(self): |
---|
[9139] | 2435 | if not self.context.is_current: |
---|
| 2436 | emit_lock_message(self) |
---|
| 2437 | return |
---|
[8736] | 2438 | if self.context.student.state != PAID: |
---|
[7145] | 2439 | emit_lock_message(self) |
---|
[6806] | 2440 | return |
---|
| 2441 | super(AddStudyLevelFormPage, self).update() |
---|
| 2442 | return |
---|
| 2443 | |
---|
[7723] | 2444 | @action(_('Create course list now'), style='primary') |
---|
[6806] | 2445 | def addStudyLevel(self, **data): |
---|
[8323] | 2446 | studylevel = createObject(u'waeup.StudentStudyLevel') |
---|
[6806] | 2447 | studylevel.level = self.context.current_level |
---|
| 2448 | studylevel.level_session = self.context.current_session |
---|
| 2449 | try: |
---|
| 2450 | self.context.addStudentStudyLevel( |
---|
| 2451 | self.context.certificate,studylevel) |
---|
| 2452 | except KeyError: |
---|
[7723] | 2453 | self.flash(_('This level exists.')) |
---|
[9467] | 2454 | except RequiredMissing: |
---|
| 2455 | self.flash(_('Your data are incomplete')) |
---|
[6806] | 2456 | self.redirect(self.url(self.context)) |
---|
| 2457 | return |
---|
[6808] | 2458 | |
---|
[7819] | 2459 | class StudyLevelEditFormPage(KofaEditFormPage): |
---|
[6808] | 2460 | """ Page to edit the student study level data by students |
---|
| 2461 | """ |
---|
| 2462 | grok.context(IStudentStudyLevel) |
---|
| 2463 | grok.name('edit') |
---|
[9924] | 2464 | grok.require('waeup.editStudyLevel') |
---|
[6808] | 2465 | grok.template('studyleveleditpage') |
---|
| 2466 | form_fields = grok.AutoFields(IStudentStudyLevel).omit( |
---|
| 2467 | 'level_session', 'level_verdict') |
---|
| 2468 | pnav = 4 |
---|
| 2469 | |
---|
[9895] | 2470 | def update(self, ADD=None, course=None): |
---|
[9139] | 2471 | if not self.context.__parent__.is_current: |
---|
| 2472 | emit_lock_message(self) |
---|
| 2473 | return |
---|
[9257] | 2474 | if self.context.student.state != PAID or \ |
---|
| 2475 | not self.context.is_current_level: |
---|
[7539] | 2476 | emit_lock_message(self) |
---|
| 2477 | return |
---|
[6808] | 2478 | super(StudyLevelEditFormPage, self).update() |
---|
| 2479 | datatable.need() |
---|
[7329] | 2480 | warning.need() |
---|
[9895] | 2481 | if ADD is not None: |
---|
| 2482 | if not course: |
---|
| 2483 | self.flash(_('No valid course code entered.')) |
---|
| 2484 | return |
---|
| 2485 | cat = queryUtility(ICatalog, name='courses_catalog') |
---|
| 2486 | result = cat.searchResults(code=(course, course)) |
---|
| 2487 | if len(result) != 1: |
---|
| 2488 | self.flash(_('Course not found.')) |
---|
| 2489 | return |
---|
| 2490 | course = list(result)[0] |
---|
| 2491 | addCourseTicket(self, course) |
---|
[6808] | 2492 | return |
---|
| 2493 | |
---|
| 2494 | @property |
---|
| 2495 | def label(self): |
---|
[7833] | 2496 | # Here we know that the cookie has been set |
---|
| 2497 | lang = self.request.cookies.get('kofa.language') |
---|
[7811] | 2498 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
[7723] | 2499 | target_language=lang) |
---|
[8920] | 2500 | return _('Edit course list of ${a}', |
---|
[7723] | 2501 | mapping = {'a':level_title}) |
---|
[6808] | 2502 | |
---|
| 2503 | @property |
---|
[8921] | 2504 | def translated_values(self): |
---|
| 2505 | return translated_values(self) |
---|
| 2506 | |
---|
[9280] | 2507 | def _delCourseTicket(self, **data): |
---|
[6808] | 2508 | form = self.request.form |
---|
[9701] | 2509 | if 'val_id' in form: |
---|
[6808] | 2510 | child_id = form['val_id'] |
---|
| 2511 | else: |
---|
[7723] | 2512 | self.flash(_('No ticket selected.')) |
---|
[6808] | 2513 | self.redirect(self.url(self.context, '@@edit')) |
---|
| 2514 | return |
---|
| 2515 | if not isinstance(child_id, list): |
---|
| 2516 | child_id = [child_id] |
---|
| 2517 | deleted = [] |
---|
| 2518 | for id in child_id: |
---|
[6940] | 2519 | # Students are not allowed to remove core tickets |
---|
[9700] | 2520 | if id in self.context and \ |
---|
| 2521 | self.context[id].removable_by_student: |
---|
[7723] | 2522 | del self.context[id] |
---|
| 2523 | deleted.append(id) |
---|
[6808] | 2524 | if len(deleted): |
---|
[7723] | 2525 | self.flash(_('Successfully removed: ${a}', |
---|
| 2526 | mapping = {'a':', '.join(deleted)})) |
---|
[9332] | 2527 | self.context.writeLogMessage( |
---|
[9924] | 2528 | self,'removed: %s at %s' % |
---|
| 2529 | (', '.join(deleted), self.context.level)) |
---|
[6808] | 2530 | self.redirect(self.url(self.context, u'@@edit')) |
---|
| 2531 | return |
---|
| 2532 | |
---|
[9280] | 2533 | @jsaction(_('Remove selected tickets')) |
---|
| 2534 | def delCourseTicket(self, **data): |
---|
| 2535 | self._delCourseTicket(**data) |
---|
| 2536 | return |
---|
| 2537 | |
---|
| 2538 | def _registerCourses(self, **data): |
---|
[10155] | 2539 | if self.context.student.is_postgrad and \ |
---|
| 2540 | not self.context.student.is_special_postgrad: |
---|
[9252] | 2541 | self.flash(_( |
---|
| 2542 | "You are a postgraduate student, " |
---|
| 2543 | "your course list can't bee registered.")) |
---|
| 2544 | self.redirect(self.url(self.context)) |
---|
| 2545 | return |
---|
[9830] | 2546 | students_utils = getUtility(IStudentsUtils) |
---|
| 2547 | max_credits = students_utils.maxCredits(self.context) |
---|
| 2548 | if self.context.total_credits > max_credits: |
---|
[8642] | 2549 | self.flash(_('Maximum credits of ${a} exceeded.', |
---|
[9830] | 2550 | mapping = {'a':max_credits})) |
---|
[8642] | 2551 | return |
---|
[8736] | 2552 | IWorkflowInfo(self.context.student).fireTransition( |
---|
[7642] | 2553 | 'register_courses') |
---|
[7723] | 2554 | self.flash(_('Course list has been registered.')) |
---|
[6810] | 2555 | self.redirect(self.url(self.context)) |
---|
| 2556 | return |
---|
| 2557 | |
---|
[9895] | 2558 | @action(_('Register course list')) |
---|
[9280] | 2559 | def registerCourses(self, **data): |
---|
| 2560 | self._registerCourses(**data) |
---|
| 2561 | return |
---|
| 2562 | |
---|
[6808] | 2563 | class CourseTicketAddFormPage2(CourseTicketAddFormPage): |
---|
| 2564 | """Add a course ticket by student. |
---|
| 2565 | """ |
---|
| 2566 | grok.name('ctadd') |
---|
| 2567 | grok.require('waeup.handleStudent') |
---|
[9420] | 2568 | form_fields = grok.AutoFields(ICourseTicketAdd) |
---|
[6808] | 2569 | |
---|
[7539] | 2570 | def update(self): |
---|
[9257] | 2571 | if self.context.student.state != PAID or \ |
---|
| 2572 | not self.context.is_current_level: |
---|
[7539] | 2573 | emit_lock_message(self) |
---|
| 2574 | return |
---|
| 2575 | super(CourseTicketAddFormPage2, self).update() |
---|
| 2576 | return |
---|
| 2577 | |
---|
[7723] | 2578 | @action(_('Add course ticket')) |
---|
[6808] | 2579 | def addCourseTicket(self, **data): |
---|
[7642] | 2580 | # Safety belt |
---|
[8736] | 2581 | if self.context.student.state != PAID: |
---|
[7539] | 2582 | return |
---|
[6808] | 2583 | course = data['course'] |
---|
[9895] | 2584 | success = addCourseTicket(self, course) |
---|
| 2585 | if success: |
---|
| 2586 | self.redirect(self.url(self.context, u'@@edit')) |
---|
[6808] | 2587 | return |
---|
[7369] | 2588 | |
---|
[7819] | 2589 | class SetPasswordPage(KofaPage): |
---|
| 2590 | grok.context(IKofaObject) |
---|
[7660] | 2591 | grok.name('setpassword') |
---|
| 2592 | grok.require('waeup.Anonymous') |
---|
| 2593 | grok.template('setpassword') |
---|
[7723] | 2594 | label = _('Set password for first-time login') |
---|
[7660] | 2595 | ac_prefix = 'PWD' |
---|
| 2596 | pnav = 0 |
---|
[7738] | 2597 | set_button = _('Set') |
---|
[7660] | 2598 | |
---|
| 2599 | def update(self, SUBMIT=None): |
---|
| 2600 | self.reg_number = self.request.form.get('reg_number', None) |
---|
| 2601 | self.ac_series = self.request.form.get('ac_series', None) |
---|
| 2602 | self.ac_number = self.request.form.get('ac_number', None) |
---|
| 2603 | |
---|
| 2604 | if SUBMIT is None: |
---|
| 2605 | return |
---|
| 2606 | hitlist = search(query=self.reg_number, |
---|
| 2607 | searchtype='reg_number', view=self) |
---|
| 2608 | if not hitlist: |
---|
[7723] | 2609 | self.flash(_('No student found.')) |
---|
[7660] | 2610 | return |
---|
| 2611 | if len(hitlist) != 1: # Cannot happen but anyway |
---|
[7723] | 2612 | self.flash(_('More than one student found.')) |
---|
[7660] | 2613 | return |
---|
| 2614 | student = hitlist[0].context |
---|
| 2615 | self.student_id = student.student_id |
---|
| 2616 | student_pw = student.password |
---|
| 2617 | pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) |
---|
| 2618 | code = get_access_code(pin) |
---|
| 2619 | if not code: |
---|
[7723] | 2620 | self.flash(_('Access code is invalid.')) |
---|
[7660] | 2621 | return |
---|
| 2622 | if student_pw and pin == student.adm_code: |
---|
[7723] | 2623 | self.flash(_( |
---|
| 2624 | 'Password has already been set. Your Student Id is ${a}', |
---|
| 2625 | mapping = {'a':self.student_id})) |
---|
[7660] | 2626 | return |
---|
| 2627 | elif student_pw: |
---|
| 2628 | self.flash( |
---|
[7723] | 2629 | _('Password has already been set. You are using the ' + |
---|
| 2630 | 'wrong Access Code.')) |
---|
[7660] | 2631 | return |
---|
| 2632 | # Mark pin as used (this also fires a pin related transition) |
---|
| 2633 | # and set student password |
---|
| 2634 | if code.state == USED: |
---|
[7723] | 2635 | self.flash(_('Access code has already been used.')) |
---|
[7660] | 2636 | return |
---|
| 2637 | else: |
---|
[7723] | 2638 | comment = _(u"invalidated") |
---|
[7660] | 2639 | # Here we know that the ac is in state initialized so we do not |
---|
| 2640 | # expect an exception |
---|
| 2641 | invalidate_accesscode(pin,comment) |
---|
| 2642 | IUserAccount(student).setPassword(self.ac_number) |
---|
| 2643 | student.adm_code = pin |
---|
[7723] | 2644 | self.flash(_('Password has been set. Your Student Id is ${a}', |
---|
| 2645 | mapping = {'a':self.student_id})) |
---|
[7811] | 2646 | return |
---|
[8779] | 2647 | |
---|
| 2648 | class StudentRequestPasswordPage(KofaAddFormPage): |
---|
| 2649 | """Captcha'd registration page for applicants. |
---|
| 2650 | """ |
---|
| 2651 | grok.name('requestpw') |
---|
| 2652 | grok.require('waeup.Anonymous') |
---|
| 2653 | grok.template('requestpw') |
---|
| 2654 | form_fields = grok.AutoFields(IStudentRequestPW).select( |
---|
[8854] | 2655 | 'firstname','number','email') |
---|
[8779] | 2656 | label = _('Request password for first-time login') |
---|
| 2657 | |
---|
| 2658 | def update(self): |
---|
| 2659 | # Handle captcha |
---|
| 2660 | self.captcha = getUtility(ICaptchaManager).getCaptcha() |
---|
| 2661 | self.captcha_result = self.captcha.verify(self.request) |
---|
| 2662 | self.captcha_code = self.captcha.display(self.captcha_result.error_code) |
---|
| 2663 | return |
---|
| 2664 | |
---|
| 2665 | def _redirect(self, email, password, student_id): |
---|
| 2666 | # Forward only email to landing page in base package. |
---|
| 2667 | self.redirect(self.url(self.context, 'requestpw_complete', |
---|
| 2668 | data = dict(email=email))) |
---|
| 2669 | return |
---|
| 2670 | |
---|
| 2671 | def _pw_used(self): |
---|
[8780] | 2672 | # XXX: False if password has not been used. We need an extra |
---|
| 2673 | # attribute which remembers if student logged in. |
---|
[8779] | 2674 | return True |
---|
| 2675 | |
---|
[8854] | 2676 | @action(_('Send login credentials to email address'), style='primary') |
---|
[8779] | 2677 | def get_credentials(self, **data): |
---|
| 2678 | if not self.captcha_result.is_valid: |
---|
| 2679 | # Captcha will display error messages automatically. |
---|
| 2680 | # No need to flash something. |
---|
| 2681 | return |
---|
[8854] | 2682 | number = data.get('number','') |
---|
[8779] | 2683 | firstname = data.get('firstname','') |
---|
| 2684 | cat = getUtility(ICatalog, name='students_catalog') |
---|
| 2685 | results = list( |
---|
[8854] | 2686 | cat.searchResults(reg_number=(number, number))) |
---|
| 2687 | if not results: |
---|
| 2688 | results = list( |
---|
| 2689 | cat.searchResults(matric_number=(number, number))) |
---|
[8779] | 2690 | if results: |
---|
| 2691 | student = results[0] |
---|
| 2692 | if getattr(student,'firstname',None) is None: |
---|
| 2693 | self.flash(_('An error occurred.')) |
---|
| 2694 | return |
---|
| 2695 | elif student.firstname.lower() != firstname.lower(): |
---|
| 2696 | # Don't tell the truth here. Anonymous must not |
---|
| 2697 | # know that a record was found and only the firstname |
---|
| 2698 | # verification failed. |
---|
| 2699 | self.flash(_('No student record found.')) |
---|
| 2700 | return |
---|
| 2701 | elif student.password is not None and self._pw_used: |
---|
| 2702 | self.flash(_('Your password has already been set and used. ' |
---|
| 2703 | 'Please proceed to the login page.')) |
---|
| 2704 | return |
---|
| 2705 | # Store email address but nothing else. |
---|
| 2706 | student.email = data['email'] |
---|
| 2707 | notify(grok.ObjectModifiedEvent(student)) |
---|
| 2708 | else: |
---|
| 2709 | # No record found, this is the truth. |
---|
| 2710 | self.flash(_('No student record found.')) |
---|
| 2711 | return |
---|
| 2712 | |
---|
| 2713 | kofa_utils = getUtility(IKofaUtils) |
---|
| 2714 | password = kofa_utils.genPassword() |
---|
[8857] | 2715 | mandate = PasswordMandate() |
---|
[8853] | 2716 | mandate.params['password'] = password |
---|
[8858] | 2717 | mandate.params['user'] = student |
---|
[8853] | 2718 | site = grok.getSite() |
---|
| 2719 | site['mandates'].addMandate(mandate) |
---|
[8779] | 2720 | # Send email with credentials |
---|
[8853] | 2721 | args = {'mandate_id':mandate.mandate_id} |
---|
| 2722 | mandate_url = self.url(site) + '/mandate?%s' % urlencode(args) |
---|
| 2723 | url_info = u'Confirmation link: %s' % mandate_url |
---|
[8779] | 2724 | msg = _('You have successfully requested a password for the') |
---|
| 2725 | if kofa_utils.sendCredentials(IUserAccount(student), |
---|
[8853] | 2726 | password, url_info, msg): |
---|
[8779] | 2727 | email_sent = student.email |
---|
| 2728 | else: |
---|
| 2729 | email_sent = None |
---|
| 2730 | self._redirect(email=email_sent, password=password, |
---|
| 2731 | student_id=student.student_id) |
---|
[8856] | 2732 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 2733 | self.context.logger.info( |
---|
| 2734 | '%s - %s (%s) - %s' % (ob_class, number, student.student_id, email_sent)) |
---|
[8779] | 2735 | return |
---|
| 2736 | |
---|
| 2737 | class StudentRequestPasswordEmailSent(KofaPage): |
---|
| 2738 | """Landing page after successful password request. |
---|
| 2739 | |
---|
| 2740 | """ |
---|
| 2741 | grok.name('requestpw_complete') |
---|
| 2742 | grok.require('waeup.Public') |
---|
| 2743 | grok.template('requestpwmailsent') |
---|
| 2744 | label = _('Your password request was successful.') |
---|
| 2745 | |
---|
| 2746 | def update(self, email=None, student_id=None, password=None): |
---|
| 2747 | self.email = email |
---|
| 2748 | self.password = password |
---|
| 2749 | self.student_id = student_id |
---|
[8974] | 2750 | return |
---|
[9797] | 2751 | |
---|
[9806] | 2752 | class FilterStudentsInDepartmentPage(KofaPage): |
---|
| 2753 | """Page that filters and lists students. |
---|
| 2754 | """ |
---|
| 2755 | grok.context(IDepartment) |
---|
| 2756 | grok.require('waeup.showStudents') |
---|
| 2757 | grok.name('students') |
---|
| 2758 | grok.template('filterstudentspage') |
---|
| 2759 | pnav = 1 |
---|
[9819] | 2760 | session_label = _('Current Session') |
---|
| 2761 | level_label = _('Current Level') |
---|
[9806] | 2762 | |
---|
| 2763 | def label(self): |
---|
[9819] | 2764 | return 'Students in %s' % self.context.longtitle() |
---|
[9806] | 2765 | |
---|
| 2766 | def _set_session_values(self): |
---|
| 2767 | vocab_terms = academic_sessions_vocab.by_value.values() |
---|
| 2768 | self.sessions = sorted( |
---|
| 2769 | [(x.title, x.token) for x in vocab_terms], reverse=True) |
---|
| 2770 | self.sessions += [('All Sessions', 'all')] |
---|
| 2771 | return |
---|
| 2772 | |
---|
| 2773 | def _set_level_values(self): |
---|
| 2774 | vocab_terms = course_levels.by_value.values() |
---|
| 2775 | self.levels = sorted( |
---|
| 2776 | [(x.title, x.token) for x in vocab_terms]) |
---|
| 2777 | self.levels += [('All Levels', 'all')] |
---|
| 2778 | return |
---|
| 2779 | |
---|
| 2780 | def _searchCatalog(self, session, level): |
---|
| 2781 | if level not in (10, 999, None): |
---|
| 2782 | start_level = 100 * (level // 100) |
---|
| 2783 | end_level = start_level + 90 |
---|
| 2784 | else: |
---|
| 2785 | start_level = end_level = level |
---|
| 2786 | cat = queryUtility(ICatalog, name='students_catalog') |
---|
| 2787 | students = cat.searchResults( |
---|
| 2788 | current_session=(session, session), |
---|
| 2789 | current_level=(start_level, end_level), |
---|
| 2790 | depcode=(self.context.code, self.context.code) |
---|
| 2791 | ) |
---|
| 2792 | hitlist = [] |
---|
| 2793 | for student in students: |
---|
| 2794 | hitlist.append(StudentQueryResultItem(student, view=self)) |
---|
| 2795 | return hitlist |
---|
| 2796 | |
---|
| 2797 | def update(self, SHOW=None, session=None, level=None): |
---|
| 2798 | datatable.need() |
---|
| 2799 | self.parent_url = self.url(self.context.__parent__) |
---|
| 2800 | self._set_session_values() |
---|
| 2801 | self._set_level_values() |
---|
| 2802 | self.hitlist = [] |
---|
| 2803 | self.session_default = session |
---|
| 2804 | self.level_default = level |
---|
| 2805 | if SHOW is not None: |
---|
| 2806 | if session != 'all': |
---|
| 2807 | self.session = int(session) |
---|
| 2808 | self.session_string = '%s %s/%s' % ( |
---|
| 2809 | self.session_label, self.session, self.session+1) |
---|
| 2810 | else: |
---|
| 2811 | self.session = None |
---|
| 2812 | self.session_string = _('in any session') |
---|
| 2813 | if level != 'all': |
---|
| 2814 | self.level = int(level) |
---|
| 2815 | self.level_string = '%s %s' % (self.level_label, self.level) |
---|
| 2816 | else: |
---|
| 2817 | self.level = None |
---|
| 2818 | self.level_string = _('at any level') |
---|
| 2819 | self.hitlist = self._searchCatalog(self.session, self.level) |
---|
| 2820 | if not self.hitlist: |
---|
| 2821 | self.flash(_('No student found.')) |
---|
| 2822 | return |
---|
| 2823 | |
---|
| 2824 | class FilterStudentsInCertificatePage(FilterStudentsInDepartmentPage): |
---|
| 2825 | """Page that filters and lists students. |
---|
| 2826 | """ |
---|
| 2827 | grok.context(ICertificate) |
---|
| 2828 | |
---|
| 2829 | def label(self): |
---|
[9819] | 2830 | return 'Students studying %s' % self.context.longtitle() |
---|
[9806] | 2831 | |
---|
| 2832 | def _searchCatalog(self, session, level): |
---|
| 2833 | if level not in (10, 999, None): |
---|
| 2834 | start_level = 100 * (level // 100) |
---|
| 2835 | end_level = start_level + 90 |
---|
| 2836 | else: |
---|
| 2837 | start_level = end_level = level |
---|
| 2838 | cat = queryUtility(ICatalog, name='students_catalog') |
---|
| 2839 | students = cat.searchResults( |
---|
| 2840 | current_session=(session, session), |
---|
| 2841 | current_level=(start_level, end_level), |
---|
| 2842 | certcode=(self.context.code, self.context.code) |
---|
| 2843 | ) |
---|
| 2844 | hitlist = [] |
---|
| 2845 | for student in students: |
---|
| 2846 | hitlist.append(StudentQueryResultItem(student, view=self)) |
---|
| 2847 | return hitlist |
---|
| 2848 | |
---|
| 2849 | class FilterStudentsInCoursePage(FilterStudentsInDepartmentPage): |
---|
| 2850 | """Page that filters and lists students. |
---|
| 2851 | """ |
---|
| 2852 | grok.context(ICourse) |
---|
| 2853 | |
---|
[10024] | 2854 | session_label = _('Session') |
---|
| 2855 | level_label = _('Level') |
---|
| 2856 | |
---|
[9806] | 2857 | def label(self): |
---|
[9819] | 2858 | return 'Students registered for %s' % self.context.longtitle() |
---|
[9806] | 2859 | |
---|
| 2860 | def _searchCatalog(self, session, level): |
---|
| 2861 | if level not in (10, 999, None): |
---|
| 2862 | start_level = 100 * (level // 100) |
---|
| 2863 | end_level = start_level + 90 |
---|
| 2864 | else: |
---|
| 2865 | start_level = end_level = level |
---|
| 2866 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
---|
| 2867 | coursetickets = cat.searchResults( |
---|
| 2868 | session=(session, session), |
---|
| 2869 | level=(start_level, end_level), |
---|
| 2870 | code=(self.context.code, self.context.code) |
---|
| 2871 | ) |
---|
| 2872 | hitlist = [] |
---|
| 2873 | for ticket in coursetickets: |
---|
| 2874 | hitlist.append(StudentQueryResultItem(ticket.student, view=self)) |
---|
[10039] | 2875 | return list(set(hitlist)) |
---|
[9806] | 2876 | |
---|
[9813] | 2877 | class ExportJobContainerOverview(KofaPage): |
---|
[9835] | 2878 | """Page that lists active student data export jobs and provides links |
---|
| 2879 | to discard or download CSV files. |
---|
| 2880 | |
---|
[9797] | 2881 | """ |
---|
[9813] | 2882 | grok.context(VirtualExportJobContainer) |
---|
[9797] | 2883 | grok.require('waeup.showStudents') |
---|
| 2884 | grok.name('index.html') |
---|
| 2885 | grok.template('exportjobsindex') |
---|
[9813] | 2886 | label = _('Student Data Exports') |
---|
[9797] | 2887 | pnav = 1 |
---|
| 2888 | |
---|
| 2889 | def update(self, CREATE=None, DISCARD=None, job_id=None): |
---|
| 2890 | if CREATE: |
---|
[9836] | 2891 | self.redirect(self.url('@@exportconfig')) |
---|
[9797] | 2892 | return |
---|
| 2893 | if DISCARD and job_id: |
---|
| 2894 | entry = self.context.entry_from_job_id(job_id) |
---|
| 2895 | self.context.delete_export_entry(entry) |
---|
[9836] | 2896 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 2897 | self.context.logger.info( |
---|
| 2898 | '%s - discarded: job_id=%s' % (ob_class, job_id)) |
---|
[9819] | 2899 | self.flash(_('Discarded export') + ' %s' % job_id) |
---|
[9822] | 2900 | self.entries = doll_up(self, user=self.request.principal.id) |
---|
[9797] | 2901 | return |
---|
| 2902 | |
---|
[9833] | 2903 | class ExportJobContainerJobConfig(KofaPage): |
---|
[9797] | 2904 | """Page that configures a students export job. |
---|
[9833] | 2905 | |
---|
| 2906 | This is a baseclass. |
---|
[9797] | 2907 | """ |
---|
[9833] | 2908 | grok.baseclass() |
---|
[9836] | 2909 | grok.name('exportconfig') |
---|
[9797] | 2910 | grok.require('waeup.showStudents') |
---|
[9836] | 2911 | grok.template('exportconfig') |
---|
[9833] | 2912 | label = _('Configure student data export') |
---|
[9797] | 2913 | pnav = 1 |
---|
[9835] | 2914 | redirect_target = '' |
---|
[9797] | 2915 | |
---|
| 2916 | def _set_session_values(self): |
---|
| 2917 | vocab_terms = academic_sessions_vocab.by_value.values() |
---|
| 2918 | self.sessions = sorted( |
---|
| 2919 | [(x.title, x.token) for x in vocab_terms], reverse=True) |
---|
[9819] | 2920 | self.sessions += [(_('All Sessions'), 'all')] |
---|
[9797] | 2921 | return |
---|
| 2922 | |
---|
| 2923 | def _set_level_values(self): |
---|
| 2924 | vocab_terms = course_levels.by_value.values() |
---|
| 2925 | self.levels = sorted( |
---|
| 2926 | [(x.title, x.token) for x in vocab_terms]) |
---|
[9819] | 2927 | self.levels += [(_('All Levels'), 'all')] |
---|
[9797] | 2928 | return |
---|
| 2929 | |
---|
[9803] | 2930 | def _set_mode_values(self): |
---|
| 2931 | utils = getUtility(IKofaUtils) |
---|
[9838] | 2932 | self.modes = sorted([(value, key) for key, value in |
---|
| 2933 | utils.STUDY_MODES_DICT.items()]) |
---|
[9819] | 2934 | self.modes +=[(_('All Modes'), 'all')] |
---|
[9803] | 2935 | return |
---|
| 2936 | |
---|
[9804] | 2937 | def _set_exporter_values(self): |
---|
| 2938 | # We provide all student exporters, nothing else, yet. |
---|
[10248] | 2939 | # Bursary Officers don't have the general exportData permission |
---|
| 2940 | # and are only allowed to export bursary data. |
---|
| 2941 | if not checkPermission('waeup.exportData', self.context): |
---|
| 2942 | self.exporters = [('Bursary Data', 'bursary')] |
---|
| 2943 | return |
---|
[9804] | 2944 | exporters = [] |
---|
| 2945 | for name in EXPORTER_NAMES: |
---|
| 2946 | util = getUtility(ICSVExporter, name=name) |
---|
| 2947 | exporters.append((util.title, name),) |
---|
| 2948 | self.exporters = exporters |
---|
[10247] | 2949 | return |
---|
[9804] | 2950 | |
---|
[9833] | 2951 | @property |
---|
| 2952 | def depcode(self): |
---|
| 2953 | return None |
---|
| 2954 | |
---|
[9842] | 2955 | @property |
---|
| 2956 | def certcode(self): |
---|
| 2957 | return None |
---|
| 2958 | |
---|
[9804] | 2959 | def update(self, START=None, session=None, level=None, mode=None, |
---|
| 2960 | exporter=None): |
---|
[9797] | 2961 | self._set_session_values() |
---|
| 2962 | self._set_level_values() |
---|
[9803] | 2963 | self._set_mode_values() |
---|
[9804] | 2964 | self._set_exporter_values() |
---|
[9797] | 2965 | if START is None: |
---|
| 2966 | return |
---|
| 2967 | if session == 'all': |
---|
| 2968 | session=None |
---|
| 2969 | if level == 'all': |
---|
| 2970 | level = None |
---|
[9803] | 2971 | if mode == 'all': |
---|
| 2972 | mode = None |
---|
[9933] | 2973 | if (mode, level, session, |
---|
| 2974 | self.depcode, self.certcode) == (None, None, None, None, None): |
---|
| 2975 | # Export all students including those without certificate |
---|
| 2976 | job_id = self.context.start_export_job(exporter, |
---|
| 2977 | self.request.principal.id) |
---|
| 2978 | else: |
---|
| 2979 | job_id = self.context.start_export_job(exporter, |
---|
| 2980 | self.request.principal.id, |
---|
| 2981 | current_session=session, |
---|
| 2982 | current_level=level, |
---|
| 2983 | current_mode=mode, |
---|
| 2984 | depcode=self.depcode, |
---|
| 2985 | certcode=self.certcode) |
---|
[9836] | 2986 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 2987 | self.context.logger.info( |
---|
[9842] | 2988 | '%s - exported: %s (%s, %s, %s, %s, %s), job_id=%s' |
---|
| 2989 | % (ob_class, exporter, session, level, mode, self.depcode, |
---|
| 2990 | self.certcode, job_id)) |
---|
[9833] | 2991 | self.flash(_('Export started for students with') + |
---|
| 2992 | ' current_session=%s, current_level=%s, study_mode=%s' % ( |
---|
| 2993 | session, level, mode)) |
---|
[9835] | 2994 | self.redirect(self.url(self.redirect_target)) |
---|
[9797] | 2995 | return |
---|
| 2996 | |
---|
[9822] | 2997 | class ExportJobContainerDownload(ExportCSVView): |
---|
[9835] | 2998 | """Page that downloads a students export csv file. |
---|
| 2999 | |
---|
[9797] | 3000 | """ |
---|
[9813] | 3001 | grok.context(VirtualExportJobContainer) |
---|
[9797] | 3002 | grok.require('waeup.showStudents') |
---|
[9833] | 3003 | |
---|
| 3004 | class DatacenterExportJobContainerJobConfig(ExportJobContainerJobConfig): |
---|
| 3005 | """Page that configures a students export job in datacenter. |
---|
| 3006 | |
---|
| 3007 | """ |
---|
| 3008 | grok.context(IDataCenter) |
---|
[9835] | 3009 | redirect_target = '@@export' |
---|
[9833] | 3010 | |
---|
[10247] | 3011 | class FacultiesExportJobContainerJobConfig(ExportJobContainerJobConfig): |
---|
| 3012 | """Page that configures a students export job in facultiescontainer. |
---|
| 3013 | |
---|
| 3014 | """ |
---|
| 3015 | grok.context(VirtualFacultiesExportJobContainer) |
---|
| 3016 | |
---|
[9833] | 3017 | class DepartmentExportJobContainerJobConfig(ExportJobContainerJobConfig): |
---|
| 3018 | """Page that configures a students export job in departments. |
---|
| 3019 | |
---|
| 3020 | """ |
---|
| 3021 | grok.context(VirtualDepartmentExportJobContainer) |
---|
| 3022 | |
---|
| 3023 | @property |
---|
| 3024 | def depcode(self): |
---|
[9835] | 3025 | return self.context.__parent__.code |
---|
[9842] | 3026 | |
---|
| 3027 | class CertificateExportJobContainerJobConfig(ExportJobContainerJobConfig): |
---|
| 3028 | """Page that configures a students export job for certificates. |
---|
| 3029 | |
---|
| 3030 | """ |
---|
| 3031 | grok.context(VirtualCertificateExportJobContainer) |
---|
[9843] | 3032 | grok.template('exportconfig_certificate') |
---|
[9842] | 3033 | |
---|
| 3034 | @property |
---|
| 3035 | def certcode(self): |
---|
| 3036 | return self.context.__parent__.code |
---|
[9843] | 3037 | |
---|
| 3038 | class CourseExportJobContainerJobConfig(ExportJobContainerJobConfig): |
---|
| 3039 | """Page that configures a students export job for courses. |
---|
| 3040 | |
---|
| 3041 | In contrast to department or certificate student data exports the |
---|
| 3042 | coursetickets_catalog is searched here. Therefore the update |
---|
| 3043 | method from the base class is customized. |
---|
| 3044 | """ |
---|
| 3045 | grok.context(VirtualCourseExportJobContainer) |
---|
| 3046 | grok.template('exportconfig_course') |
---|
| 3047 | |
---|
| 3048 | def _set_exporter_values(self): |
---|
[9844] | 3049 | # We provide only two exporters. |
---|
[9843] | 3050 | exporters = [] |
---|
[9844] | 3051 | for name in ('students', 'coursetickets'): |
---|
[9843] | 3052 | util = getUtility(ICSVExporter, name=name) |
---|
| 3053 | exporters.append((util.title, name),) |
---|
| 3054 | self.exporters = exporters |
---|
| 3055 | |
---|
| 3056 | def update(self, START=None, session=None, level=None, mode=None, |
---|
| 3057 | exporter=None): |
---|
| 3058 | self._set_session_values() |
---|
| 3059 | self._set_level_values() |
---|
| 3060 | self._set_mode_values() |
---|
| 3061 | self._set_exporter_values() |
---|
| 3062 | if START is None: |
---|
| 3063 | return |
---|
| 3064 | if session == 'all': |
---|
[10016] | 3065 | session = None |
---|
[9843] | 3066 | if level == 'all': |
---|
| 3067 | level = None |
---|
| 3068 | job_id = self.context.start_export_job(exporter, |
---|
| 3069 | self.request.principal.id, |
---|
| 3070 | # Use a different catalog and |
---|
| 3071 | # pass different keywords than |
---|
| 3072 | # for the (default) students_catalog |
---|
[9845] | 3073 | catalog='coursetickets', |
---|
[9843] | 3074 | session=session, |
---|
| 3075 | level=level, |
---|
| 3076 | code=self.context.__parent__.code) |
---|
| 3077 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 3078 | self.context.logger.info( |
---|
| 3079 | '%s - exported: %s (%s, %s, %s), job_id=%s' |
---|
| 3080 | % (ob_class, exporter, session, level, |
---|
| 3081 | self.context.__parent__.code, job_id)) |
---|
| 3082 | self.flash(_('Export started for course tickets with') + |
---|
| 3083 | ' level_session=%s, level=%s' % ( |
---|
| 3084 | session, level)) |
---|
| 3085 | self.redirect(self.url(self.redirect_target)) |
---|
| 3086 | return |
---|