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