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