[7191] | 1 | ## $Id: viewlets.py 8736 2012-06-17 07:09:21Z henrik $ |
---|
| 2 | ## |
---|
| 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 | ## |
---|
[7106] | 18 | import os |
---|
[6642] | 19 | import grok |
---|
[7097] | 20 | from zope.component import getUtility |
---|
[6642] | 21 | from zope.interface import Interface |
---|
[7741] | 22 | from zope.i18n import translate |
---|
[7811] | 23 | from waeup.kofa.interfaces import ( |
---|
[8467] | 24 | IKofaObject, IExtFileStore, IFileStoreNameChooser) |
---|
[7811] | 25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
| 26 | from waeup.kofa.utils.helpers import string_from_bytes, file_size |
---|
| 27 | from waeup.kofa.browser import DEFAULT_IMAGE_PATH |
---|
| 28 | from waeup.kofa.browser.viewlets import ( |
---|
[7591] | 29 | PrimaryNavTab, ManageActionButton, AddActionButton) |
---|
[8106] | 30 | from waeup.kofa.browser.layout import ( |
---|
[8467] | 31 | default_primary_nav_template, default_filedisplay_template, |
---|
| 32 | default_fileupload_template) |
---|
| 33 | from waeup.kofa.students.workflow import ( |
---|
| 34 | ADMITTED, PAID, REQUESTED, RETURNING, CLEARED, REGISTERED, |
---|
| 35 | VALIDATED) |
---|
[7811] | 36 | from waeup.kofa.students.browser import ( |
---|
[8735] | 37 | StudentClearanceManageFormPage, |
---|
[8467] | 38 | StudentBaseManageFormPage, StudentFilesUploadPage, |
---|
| 39 | ExportPDFClearanceSlipPage, StudentsContainerPage, |
---|
[7591] | 40 | StudentsContainerManagePage, StudentBaseDisplayFormPage, |
---|
| 41 | StudentClearanceDisplayFormPage, StudentPersonalDisplayFormPage, |
---|
| 42 | StudyCourseDisplayFormPage, StudyLevelDisplayFormPage, |
---|
| 43 | CourseTicketDisplayFormPage, OnlinePaymentDisplayFormPage, |
---|
[8119] | 44 | AccommodationManageFormPage, BedTicketDisplayFormPage, |
---|
| 45 | StudentClearanceEditFormPage, StudentPersonalEditFormPage) |
---|
[7811] | 46 | from waeup.kofa.students.interfaces import ( |
---|
[8467] | 47 | IStudentsContainer, IStudent, IStudentStudyCourse, IStudentAccommodation, |
---|
| 48 | IStudentStudyLevel, ICourseTicket, IStudentOnlinePayment, IBedTicket, |
---|
[7591] | 49 | ) |
---|
[8467] | 50 | from waeup.kofa.utils.helpers import get_fileformat |
---|
[6642] | 51 | |
---|
[7819] | 52 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
[6687] | 53 | grok.templatedir('browser_templates') |
---|
[6642] | 54 | |
---|
[7123] | 55 | ALLOWED_FILE_EXTENSIONS = ('jpg', 'png', 'pdf', 'tif') |
---|
| 56 | |
---|
[6687] | 57 | class StudentManageSidebar(grok.ViewletManager): |
---|
| 58 | grok.name('left_studentmanage') |
---|
[6642] | 59 | |
---|
[6687] | 60 | class StudentManageLink(grok.Viewlet): |
---|
[6660] | 61 | """A link displayed in the student box which shows up for StudentNavigation |
---|
[6642] | 62 | objects. |
---|
| 63 | |
---|
| 64 | """ |
---|
| 65 | grok.baseclass() |
---|
[6687] | 66 | grok.viewletmanager(StudentManageSidebar) |
---|
[7819] | 67 | grok.context(IKofaObject) |
---|
[6642] | 68 | grok.view(Interface) |
---|
| 69 | grok.order(5) |
---|
[6660] | 70 | grok.require('waeup.viewStudent') |
---|
[6642] | 71 | |
---|
| 72 | link = 'index' |
---|
[7738] | 73 | text = _(u'Base Data') |
---|
[6642] | 74 | |
---|
| 75 | def render(self): |
---|
[8736] | 76 | url = self.view.url(self.context.student, self.link) |
---|
[7833] | 77 | # Here we know that the cookie has been set |
---|
| 78 | lang = self.request.cookies.get('kofa.language') |
---|
[7811] | 79 | text = translate(self.text, 'waeup.kofa', |
---|
[7741] | 80 | target_language=lang) |
---|
[7459] | 81 | return u'<li><a href="%s">%s</a></li>' % ( |
---|
[7741] | 82 | url, text) |
---|
[6642] | 83 | |
---|
[7459] | 84 | class StudentManageApplicationLink(StudentManageLink): |
---|
[6687] | 85 | grok.order(1) |
---|
[7351] | 86 | link = 'application_slip' |
---|
[7738] | 87 | text = _(u'Application Slip') |
---|
[7340] | 88 | |
---|
| 89 | def render(self): |
---|
[7351] | 90 | slip = getUtility(IExtFileStore).getFileByContext( |
---|
[8736] | 91 | self.context.student, attr=self.link) |
---|
[7351] | 92 | if slip: |
---|
| 93 | url = self.view.url(self.context,self.link) |
---|
[7459] | 94 | return u'<li><a href="%s">%s</a></li>' % ( |
---|
[7340] | 95 | url, self.text) |
---|
| 96 | return '' |
---|
| 97 | |
---|
[7459] | 98 | class StudentManageBaseLink(StudentManageLink): |
---|
| 99 | grok.order(2) |
---|
| 100 | link = 'index' |
---|
[7738] | 101 | text = _(u'Base Data') |
---|
[7459] | 102 | |
---|
[6687] | 103 | class StudentManageClearanceLink(StudentManageLink): |
---|
[7340] | 104 | grok.order(3) |
---|
[6687] | 105 | link = 'view_clearance' |
---|
[7738] | 106 | text = _(u'Clearance Data') |
---|
[6687] | 107 | |
---|
| 108 | class StudentManagePersonalLink(StudentManageLink): |
---|
[7340] | 109 | grok.order(4) |
---|
[6687] | 110 | link = 'view_personal' |
---|
[7738] | 111 | text = _(u'Personal Data') |
---|
[6687] | 112 | |
---|
| 113 | class StudentManageStudyCourseLink(StudentManageLink): |
---|
[7340] | 114 | grok.order(5) |
---|
[6687] | 115 | link = 'studycourse' |
---|
[7738] | 116 | text = _(u'Study Course') |
---|
[6687] | 117 | |
---|
| 118 | class StudentManagePaymentsLink(StudentManageLink): |
---|
[7340] | 119 | grok.order(6) |
---|
[7181] | 120 | grok.require('waeup.payStudent') |
---|
[6687] | 121 | link = 'payments' |
---|
[7738] | 122 | text = _(u'Payments') |
---|
[6687] | 123 | |
---|
| 124 | class StudentManageAccommodationLink(StudentManageLink): |
---|
[7340] | 125 | grok.order(7) |
---|
[7181] | 126 | grok.require('waeup.handleAccommodation') |
---|
[6687] | 127 | link = 'accommodation' |
---|
[7738] | 128 | text = _(u'Accommodation') |
---|
[6687] | 129 | |
---|
| 130 | class StudentManageHistoryLink(StudentManageLink): |
---|
[7340] | 131 | grok.order(8) |
---|
[6687] | 132 | link = 'history' |
---|
[7738] | 133 | text = _(u'History') |
---|
[6687] | 134 | |
---|
[7591] | 135 | |
---|
| 136 | class StudentsContainerManageActionButton(ManageActionButton): |
---|
| 137 | grok.order(1) |
---|
| 138 | grok.context(IStudentsContainer) |
---|
| 139 | grok.view(StudentsContainerPage) |
---|
| 140 | grok.require('waeup.manageStudent') |
---|
[7738] | 141 | text = _('Manage student section') |
---|
[7591] | 142 | |
---|
| 143 | class StudentsContainerAddActionButton(AddActionButton): |
---|
| 144 | grok.order(1) |
---|
| 145 | grok.context(IStudentsContainer) |
---|
| 146 | grok.view(StudentsContainerManagePage) |
---|
| 147 | grok.require('waeup.manageStudent') |
---|
[7738] | 148 | text = _('Add student') |
---|
[7591] | 149 | target = 'addstudent' |
---|
| 150 | |
---|
| 151 | class ContactActionButton(ManageActionButton): |
---|
| 152 | grok.order(4) |
---|
| 153 | grok.context(IStudent) |
---|
| 154 | grok.view(StudentBaseDisplayFormPage) |
---|
| 155 | grok.require('waeup.manageStudent') |
---|
| 156 | icon = 'actionicon_mail.png' |
---|
[7738] | 157 | text = _('Send email') |
---|
[7591] | 158 | target = 'contactstudent' |
---|
| 159 | |
---|
| 160 | class StudentBaseManageActionButton(ManageActionButton): |
---|
| 161 | grok.order(1) |
---|
| 162 | grok.context(IStudent) |
---|
| 163 | grok.view(StudentBaseDisplayFormPage) |
---|
| 164 | grok.require('waeup.manageStudent') |
---|
[7738] | 165 | text = _('Manage') |
---|
[7591] | 166 | target = 'manage_base' |
---|
| 167 | |
---|
| 168 | class StudentClearanceManageActionButton(ManageActionButton): |
---|
| 169 | grok.order(1) |
---|
| 170 | grok.context(IStudent) |
---|
| 171 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 172 | grok.require('waeup.manageStudent') |
---|
[7738] | 173 | text = _('Manage') |
---|
[8119] | 174 | target = 'manage_clearance' |
---|
[7591] | 175 | |
---|
| 176 | class StudentClearActionButton(ManageActionButton): |
---|
| 177 | grok.order(2) |
---|
| 178 | grok.context(IStudent) |
---|
| 179 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 180 | grok.require('waeup.clearStudent') |
---|
[7738] | 181 | text = _('Clear student') |
---|
[7591] | 182 | target = 'clear' |
---|
| 183 | icon = 'actionicon_accept.png' |
---|
| 184 | |
---|
| 185 | @property |
---|
| 186 | def target_url(self): |
---|
| 187 | if self.context.state != REQUESTED: |
---|
| 188 | return '' |
---|
| 189 | return self.view.url(self.view.context, self.target) |
---|
| 190 | |
---|
| 191 | class StudentRejectClearanceActionButton(ManageActionButton): |
---|
| 192 | grok.order(3) |
---|
| 193 | grok.context(IStudent) |
---|
| 194 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 195 | grok.require('waeup.clearStudent') |
---|
[7738] | 196 | text = _('Reject clearance') |
---|
[7591] | 197 | target = 'reject_clearance' |
---|
| 198 | icon = 'actionicon_reject.png' |
---|
| 199 | |
---|
| 200 | @property |
---|
| 201 | def target_url(self): |
---|
| 202 | if self.context.state not in (REQUESTED, CLEARED): |
---|
| 203 | return '' |
---|
| 204 | return self.view.url(self.view.context, self.target) |
---|
| 205 | |
---|
| 206 | class ClearanceSlipActionButton(ManageActionButton): |
---|
| 207 | grok.order(4) |
---|
| 208 | grok.context(IStudent) |
---|
| 209 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 210 | grok.require('waeup.viewStudent') |
---|
| 211 | icon = 'actionicon_pdf.png' |
---|
[7738] | 212 | text = _('Download clearance slip') |
---|
[7591] | 213 | target = 'clearance.pdf' |
---|
| 214 | |
---|
[8119] | 215 | class ClearanceViewActionButton(ManageActionButton): |
---|
| 216 | grok.order(1) |
---|
| 217 | grok.context(IStudent) |
---|
| 218 | grok.view(StudentClearanceEditFormPage) |
---|
| 219 | grok.require('waeup.viewStudent') |
---|
| 220 | icon = 'actionicon_view.png' |
---|
| 221 | text = _('View') |
---|
| 222 | target = 'view_clearance' |
---|
| 223 | |
---|
| 224 | class PersonalViewActionButton(ManageActionButton): |
---|
| 225 | grok.order(1) |
---|
| 226 | grok.context(IStudent) |
---|
| 227 | grok.view(StudentPersonalEditFormPage) |
---|
| 228 | grok.require('waeup.viewStudent') |
---|
| 229 | icon = 'actionicon_view.png' |
---|
| 230 | text = _('View') |
---|
| 231 | target = 'view_personal' |
---|
| 232 | |
---|
[7591] | 233 | class StudentPersonalEditActionButton(ManageActionButton): |
---|
| 234 | grok.order(1) |
---|
| 235 | grok.context(IStudent) |
---|
| 236 | grok.view(StudentPersonalDisplayFormPage) |
---|
| 237 | grok.require('waeup.viewStudent') |
---|
[7738] | 238 | text = _('Edit') |
---|
[7591] | 239 | target = 'edit_personal' |
---|
| 240 | |
---|
| 241 | class StudyCourseManageActionButton(ManageActionButton): |
---|
| 242 | grok.order(1) |
---|
| 243 | grok.context(IStudentStudyCourse) |
---|
| 244 | grok.view(StudyCourseDisplayFormPage) |
---|
| 245 | grok.require('waeup.manageStudent') |
---|
[7738] | 246 | text = _('Manage') |
---|
[7591] | 247 | target = 'manage' |
---|
| 248 | |
---|
[8078] | 249 | class StudyLevelManageActionButton(ManageActionButton): |
---|
[7591] | 250 | grok.order(1) |
---|
| 251 | grok.context(IStudentStudyLevel) |
---|
| 252 | grok.view(StudyLevelDisplayFormPage) |
---|
| 253 | grok.require('waeup.manageStudent') |
---|
[7738] | 254 | text = _('Manage') |
---|
[7591] | 255 | target = 'manage' |
---|
| 256 | |
---|
| 257 | class StudentValidateCoursesActionButton(ManageActionButton): |
---|
| 258 | grok.order(3) |
---|
| 259 | grok.context(IStudentStudyLevel) |
---|
| 260 | grok.view(StudyLevelDisplayFormPage) |
---|
| 261 | grok.require('waeup.validateStudent') |
---|
[7738] | 262 | text = _('Validate courses') |
---|
[7591] | 263 | target = 'validate_courses' |
---|
| 264 | icon = 'actionicon_accept.png' |
---|
| 265 | |
---|
| 266 | @property |
---|
| 267 | def target_url(self): |
---|
[8736] | 268 | if self.context.student.state != REGISTERED or \ |
---|
[7591] | 269 | str(self.context.__parent__.current_level) != self.context.__name__: |
---|
| 270 | return '' |
---|
| 271 | return self.view.url(self.view.context, self.target) |
---|
| 272 | |
---|
| 273 | class StudentRejectCoursesActionButton(ManageActionButton): |
---|
| 274 | grok.order(4) |
---|
| 275 | grok.context(IStudentStudyLevel) |
---|
| 276 | grok.view(StudyLevelDisplayFormPage) |
---|
| 277 | grok.require('waeup.validateStudent') |
---|
[7738] | 278 | text = _('Reject courses') |
---|
[7591] | 279 | target = 'reject_courses' |
---|
| 280 | icon = 'actionicon_reject.png' |
---|
| 281 | |
---|
| 282 | @property |
---|
| 283 | def target_url(self): |
---|
[8736] | 284 | if self.context.student.state not in (VALIDATED, REGISTERED) or \ |
---|
[7591] | 285 | str(self.context.__parent__.current_level) != self.context.__name__: |
---|
| 286 | return '' |
---|
| 287 | return self.view.url(self.view.context, self.target) |
---|
| 288 | |
---|
[8078] | 289 | class CourseRegistrationSlipActionButton(ManageActionButton): |
---|
| 290 | grok.order(5) |
---|
| 291 | grok.context(IStudentStudyLevel) |
---|
| 292 | grok.view(StudyLevelDisplayFormPage) |
---|
| 293 | grok.require('waeup.viewStudent') |
---|
| 294 | icon = 'actionicon_pdf.png' |
---|
| 295 | text = _('Download course registration slip') |
---|
| 296 | target = 'course_registration.pdf' |
---|
| 297 | |
---|
[7591] | 298 | class CourseTicketManageActionButton(ManageActionButton): |
---|
| 299 | grok.order(1) |
---|
| 300 | grok.context(ICourseTicket) |
---|
| 301 | grok.view(CourseTicketDisplayFormPage) |
---|
| 302 | grok.require('waeup.manageStudent') |
---|
[7738] | 303 | text = _('Manage') |
---|
[7591] | 304 | target = 'manage' |
---|
| 305 | |
---|
| 306 | #class OnlinePaymentManageActionButton(ManageActionButton): |
---|
| 307 | # grok.order(1) |
---|
| 308 | # grok.context(IStudentPaymentsContainer) |
---|
| 309 | # grok.view(PaymentsDisplayFormPage) |
---|
| 310 | # grok.require('waeup.manageStudent') |
---|
| 311 | # text = 'Manage payments' |
---|
| 312 | # target = 'manage' |
---|
| 313 | |
---|
| 314 | class PaymentReceiptActionButton(ManageActionButton): |
---|
| 315 | grok.order(1) |
---|
| 316 | grok.context(IStudentOnlinePayment) |
---|
| 317 | grok.view(OnlinePaymentDisplayFormPage) |
---|
| 318 | grok.require('waeup.viewStudent') |
---|
| 319 | icon = 'actionicon_pdf.png' |
---|
[8262] | 320 | text = _('Download payment slip') |
---|
| 321 | target = 'payment_slip.pdf' |
---|
[7591] | 322 | |
---|
| 323 | @property |
---|
| 324 | def target_url(self): |
---|
[8262] | 325 | #if self.context.p_state != 'paid': |
---|
| 326 | # return '' |
---|
[7591] | 327 | return self.view.url(self.view.context, self.target) |
---|
| 328 | |
---|
[8420] | 329 | |
---|
| 330 | class ApprovePaymentActionButton(ManageActionButton): |
---|
[7591] | 331 | grok.order(2) |
---|
| 332 | grok.context(IStudentOnlinePayment) |
---|
| 333 | grok.view(OnlinePaymentDisplayFormPage) |
---|
[8420] | 334 | grok.require('waeup.managePortal') |
---|
[8435] | 335 | icon = 'actionicon_accept.png' |
---|
[8420] | 336 | text = _('Approve payment') |
---|
| 337 | target = 'approve' |
---|
[7591] | 338 | |
---|
| 339 | @property |
---|
| 340 | def target_url(self): |
---|
[7888] | 341 | if self.context.p_state == 'paid': |
---|
[7591] | 342 | return '' |
---|
| 343 | return self.view.url(self.view.context, self.target) |
---|
| 344 | |
---|
| 345 | class AddBedTicketActionButton(ManageActionButton): |
---|
| 346 | grok.order(1) |
---|
| 347 | grok.context(IStudentAccommodation) |
---|
| 348 | grok.view(AccommodationManageFormPage) |
---|
| 349 | grok.require('waeup.handleAccommodation') |
---|
| 350 | icon = 'actionicon_home.png' |
---|
[7738] | 351 | text = _('Book accommodation') |
---|
[7591] | 352 | target = 'add' |
---|
| 353 | |
---|
| 354 | class BedTicketSlipActionButton(ManageActionButton): |
---|
| 355 | grok.order(1) |
---|
| 356 | grok.context(IBedTicket) |
---|
| 357 | grok.view(BedTicketDisplayFormPage) |
---|
| 358 | grok.require('waeup.handleAccommodation') |
---|
| 359 | icon = 'actionicon_pdf.png' |
---|
[7738] | 360 | text = _('Download bed allocation slip') |
---|
[7591] | 361 | target = 'bed_allocation.pdf' |
---|
| 362 | |
---|
| 363 | class RelocateStudentActionButton(ManageActionButton): |
---|
| 364 | grok.order(2) |
---|
| 365 | grok.context(IBedTicket) |
---|
| 366 | grok.view(BedTicketDisplayFormPage) |
---|
| 367 | grok.require('waeup.manageHostels') |
---|
| 368 | icon = 'actionicon_reload.png' |
---|
[7738] | 369 | text = _('Relocate student') |
---|
[7591] | 370 | target = 'relocate' |
---|
| 371 | |
---|
| 372 | class StudentBaseActionButton(ManageActionButton): |
---|
| 373 | grok.order(1) |
---|
| 374 | grok.context(IStudent) |
---|
| 375 | grok.view(StudentBaseDisplayFormPage) |
---|
| 376 | grok.require('waeup.handleStudent') |
---|
[7876] | 377 | text = _('Edit') |
---|
[7591] | 378 | target = 'edit_base' |
---|
| 379 | |
---|
| 380 | class StudentPasswordActionButton(ManageActionButton): |
---|
| 381 | grok.order(2) |
---|
| 382 | grok.context(IStudent) |
---|
| 383 | grok.view(StudentBaseDisplayFormPage) |
---|
| 384 | grok.require('waeup.handleStudent') |
---|
| 385 | icon = 'actionicon_key.png' |
---|
[7738] | 386 | text = _('Change password') |
---|
[7591] | 387 | target = 'change_password' |
---|
| 388 | |
---|
| 389 | class StudentPassportActionButton(ManageActionButton): |
---|
| 390 | grok.order(3) |
---|
| 391 | grok.context(IStudent) |
---|
| 392 | grok.view(StudentBaseDisplayFormPage) |
---|
| 393 | grok.require('waeup.handleStudent') |
---|
| 394 | icon = 'actionicon_portrait.png' |
---|
[7738] | 395 | text = _('Change portrait') |
---|
[7591] | 396 | target = 'change_portrait' |
---|
| 397 | |
---|
| 398 | @property |
---|
| 399 | def target_url(self): |
---|
[7671] | 400 | if self.context.state != ADMITTED: |
---|
[7591] | 401 | return '' |
---|
| 402 | return self.view.url(self.view.context, self.target) |
---|
| 403 | |
---|
| 404 | class StudentClearanceStartActionButton(ManageActionButton): |
---|
| 405 | grok.order(1) |
---|
| 406 | grok.context(IStudent) |
---|
| 407 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 408 | grok.require('waeup.handleStudent') |
---|
| 409 | icon = 'actionicon_start.gif' |
---|
[7738] | 410 | text = _('Start clearance') |
---|
[7591] | 411 | target = 'start_clearance' |
---|
| 412 | |
---|
| 413 | @property |
---|
| 414 | def target_url(self): |
---|
[7671] | 415 | if self.context.state != ADMITTED: |
---|
[7591] | 416 | return '' |
---|
| 417 | return self.view.url(self.view.context, self.target) |
---|
| 418 | |
---|
| 419 | class StudentClearanceEditActionButton(ManageActionButton): |
---|
| 420 | grok.order(1) |
---|
| 421 | grok.context(IStudent) |
---|
| 422 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 423 | grok.require('waeup.handleStudent') |
---|
[7738] | 424 | text = _('Edit') |
---|
[7591] | 425 | target = 'cedit' |
---|
| 426 | |
---|
| 427 | @property |
---|
| 428 | def target_url(self): |
---|
| 429 | if self.context.clearance_locked: |
---|
| 430 | return '' |
---|
| 431 | return self.view.url(self.view.context, self.target) |
---|
| 432 | |
---|
[8476] | 433 | class StartSessionActionButton(ManageActionButton): |
---|
[7591] | 434 | grok.order(1) |
---|
| 435 | grok.context(IStudentStudyCourse) |
---|
| 436 | grok.view(StudyCourseDisplayFormPage) |
---|
| 437 | grok.require('waeup.handleStudent') |
---|
| 438 | icon = 'actionicon_start.gif' |
---|
[8471] | 439 | text = _('Start session') |
---|
| 440 | target = 'start_session' |
---|
[7591] | 441 | |
---|
| 442 | @property |
---|
| 443 | def target_url(self): |
---|
[8471] | 444 | if self.context.next_session_allowed: |
---|
| 445 | return self.view.url(self.view.context, self.target) |
---|
| 446 | return False |
---|
[7591] | 447 | |
---|
| 448 | class AddStudyLevelActionButton(AddActionButton): |
---|
| 449 | grok.order(1) |
---|
| 450 | grok.context(IStudentStudyCourse) |
---|
| 451 | grok.view(StudyCourseDisplayFormPage) |
---|
| 452 | grok.require('waeup.handleStudent') |
---|
[7738] | 453 | text = _('Add course list') |
---|
[7591] | 454 | target = 'add' |
---|
| 455 | |
---|
| 456 | @property |
---|
| 457 | def target_url(self): |
---|
[8736] | 458 | student = self.view.context.student |
---|
[7671] | 459 | condition1 = student.state != PAID |
---|
[7591] | 460 | condition2 = str(student['studycourse'].current_level) in \ |
---|
| 461 | self.view.context.keys() |
---|
| 462 | if condition1 or condition2: |
---|
| 463 | return '' |
---|
| 464 | return self.view.url(self.view.context, self.target) |
---|
| 465 | |
---|
| 466 | class StudyLevelEditActionButton(ManageActionButton): |
---|
[8078] | 467 | grok.order(2) |
---|
[7591] | 468 | grok.context(IStudentStudyLevel) |
---|
| 469 | grok.view(StudyLevelDisplayFormPage) |
---|
| 470 | grok.require('waeup.handleStudent') |
---|
[7738] | 471 | text = _('Add and remove courses') |
---|
[7591] | 472 | target = 'edit' |
---|
| 473 | |
---|
| 474 | @property |
---|
| 475 | def target_url(self): |
---|
[8736] | 476 | student = self.view.context.student |
---|
[7671] | 477 | condition1 = student.state != PAID |
---|
[7591] | 478 | condition2 = student[ |
---|
| 479 | 'studycourse'].current_level != self.view.context.level |
---|
| 480 | if condition1 or condition2: |
---|
| 481 | return '' |
---|
| 482 | return self.view.url(self.view.context, self.target) |
---|
| 483 | |
---|
[7184] | 484 | class StudentsTab(PrimaryNavTab): |
---|
| 485 | """Students tab in primary navigation. |
---|
| 486 | """ |
---|
| 487 | |
---|
[7819] | 488 | grok.context(IKofaObject) |
---|
[7184] | 489 | grok.order(4) |
---|
[7240] | 490 | grok.require('waeup.viewStudentsTab') |
---|
[7184] | 491 | |
---|
| 492 | pnav = 4 |
---|
[7674] | 493 | tab_title = _(u'Students') |
---|
[7184] | 494 | |
---|
| 495 | @property |
---|
| 496 | def link_target(self): |
---|
| 497 | return self.view.application_url('students') |
---|
| 498 | |
---|
[6687] | 499 | class PrimaryStudentNavManager(grok.ViewletManager): |
---|
| 500 | """Viewlet manager for the primary navigation tab. |
---|
| 501 | """ |
---|
| 502 | grok.name('primary_nav_student') |
---|
| 503 | |
---|
| 504 | class PrimaryStudentNavTab(grok.Viewlet): |
---|
| 505 | """Base for primary student nav tabs. |
---|
| 506 | """ |
---|
| 507 | grok.baseclass() |
---|
| 508 | grok.viewletmanager(PrimaryStudentNavManager) |
---|
[7243] | 509 | template = default_primary_nav_template |
---|
[6687] | 510 | grok.order(1) |
---|
[7184] | 511 | grok.require('waeup.Authenticated') |
---|
[8467] | 512 | pnav = 0 |
---|
[6687] | 513 | tab_title = u'Some Text' |
---|
| 514 | |
---|
| 515 | @property |
---|
| 516 | def link_target(self): |
---|
| 517 | return self.view.application_url() |
---|
| 518 | |
---|
| 519 | @property |
---|
| 520 | def active(self): |
---|
| 521 | view_pnav = getattr(self.view, 'pnav', 0) |
---|
| 522 | if view_pnav == self.pnav: |
---|
| 523 | return 'active' |
---|
| 524 | return '' |
---|
| 525 | |
---|
[7240] | 526 | class MyStudentDataTab(PrimaryStudentNavTab): |
---|
[7459] | 527 | """MyData dropdown tab in primary navigation. |
---|
[6687] | 528 | """ |
---|
| 529 | grok.order(3) |
---|
[7240] | 530 | grok.require('waeup.viewMyStudentDataTab') |
---|
[7459] | 531 | grok.template('mydatadropdowntabs') |
---|
[6687] | 532 | pnav = 4 |
---|
[7738] | 533 | tab_title = _(u'My Data') |
---|
[6687] | 534 | |
---|
| 535 | @property |
---|
[7459] | 536 | def active(self): |
---|
| 537 | view_pnav = getattr(self.view, 'pnav', 0) |
---|
| 538 | if view_pnav == self.pnav: |
---|
| 539 | return 'active dropdown' |
---|
| 540 | return 'dropdown' |
---|
[7097] | 541 | |
---|
[7459] | 542 | @property |
---|
| 543 | def targets(self): |
---|
| 544 | student_url = self.view.application_url() + ( |
---|
| 545 | '/students/%s' % self.request.principal.id) |
---|
| 546 | #app_slip = getUtility(IExtFileStore).getFileByContext( |
---|
[8736] | 547 | # self.context.student, 'application_slip') |
---|
[7459] | 548 | targets = [] |
---|
| 549 | #if app_slip: |
---|
| 550 | # targets = [{'url':student_url + '/application_slip', 'title':'Application Slip'},] |
---|
| 551 | targets += [ |
---|
| 552 | {'url':student_url, 'title':'Base Data'}, |
---|
[8467] | 553 | {'url':student_url + '/view_clearance', |
---|
| 554 | 'title':_('Clearance Data')}, |
---|
[7738] | 555 | {'url':student_url + '/view_personal', 'title':_('Personal Data')}, |
---|
| 556 | {'url':student_url + '/studycourse', 'title':_('Study Course')}, |
---|
| 557 | {'url':student_url + '/payments', 'title':_('Payments')}, |
---|
[8467] | 558 | {'url':student_url + '/accommodation', |
---|
| 559 | 'title':_('Accommodation Data')}, |
---|
[7738] | 560 | {'url':student_url + '/history', 'title':_('History')}, |
---|
[7459] | 561 | ] |
---|
| 562 | return targets |
---|
| 563 | |
---|
[7107] | 564 | def handle_file_delete(context, view, download_name): |
---|
| 565 | """Handle deletion of student file. |
---|
| 566 | |
---|
| 567 | """ |
---|
| 568 | store = getUtility(IExtFileStore) |
---|
| 569 | store.deleteFileByContext(context, attr=download_name) |
---|
[8735] | 570 | context.writeLogMessage(view, 'deleted: %s' % download_name) |
---|
[7738] | 571 | view.flash(_('${a} deleted.', mapping = {'a':download_name})) |
---|
[7107] | 572 | return |
---|
| 573 | |
---|
[7106] | 574 | def handle_file_upload(upload, context, view, max_size, download_name=None): |
---|
| 575 | """Handle upload of student file. |
---|
[7097] | 576 | |
---|
| 577 | Returns `True` in case of success or `False`. |
---|
| 578 | |
---|
| 579 | Please note that file pointer passed in (`upload`) most probably |
---|
| 580 | points to end of file when leaving this function. |
---|
| 581 | """ |
---|
[7106] | 582 | # Check some file requirements first |
---|
[8467] | 583 | size = file_size(upload) |
---|
| 584 | if size > max_size: |
---|
| 585 | view.flash(_('Uploaded file is too big.')) |
---|
[7106] | 586 | return False |
---|
[8467] | 587 | upload.seek(0) # file pointer moved when determining size |
---|
| 588 | file_format = get_fileformat(None, upload.read(512)) |
---|
| 589 | upload.seek(0) # same here |
---|
| 590 | if file_format is None: |
---|
| 591 | view.flash(_('Could not determine file type.')) |
---|
[7106] | 592 | return False |
---|
| 593 | basename, expected_ext = os.path.splitext(download_name) |
---|
[7123] | 594 | if expected_ext: |
---|
[8467] | 595 | if '.' + file_format != expected_ext: |
---|
[7738] | 596 | view.flash(_('${a} file extension expected.', |
---|
[8467] | 597 | mapping = {'a':expected_ext[1:]})) |
---|
[7123] | 598 | return False |
---|
| 599 | else: |
---|
[8467] | 600 | if not file_format in ALLOWED_FILE_EXTENSIONS: |
---|
[7123] | 601 | view.flash( |
---|
[8467] | 602 | _('Only the following extensions are allowed: ${a}', |
---|
[7738] | 603 | mapping = {'a':', '.join(ALLOWED_FILE_EXTENSIONS)})) |
---|
[7123] | 604 | return False |
---|
[8467] | 605 | download_name += '.' + file_format |
---|
[7097] | 606 | store = getUtility(IExtFileStore) |
---|
[7106] | 607 | file_id = IFileStoreNameChooser(context).chooseName(attr=download_name) |
---|
[7097] | 608 | store.createFile(file_id, upload) |
---|
[8735] | 609 | context.writeLogMessage(view, 'uploaded: %s (%s)' % ( |
---|
[8467] | 610 | download_name,upload.filename)) |
---|
[7738] | 611 | view.flash(_('File ${a} uploaded.', mapping = {'a':download_name})) |
---|
[7097] | 612 | return True |
---|
| 613 | |
---|
| 614 | class FileManager(grok.ViewletManager): |
---|
| 615 | """Viewlet manager for uploading files, preferably scanned images. |
---|
| 616 | """ |
---|
| 617 | grok.name('files') |
---|
| 618 | |
---|
| 619 | class FileDisplay(grok.Viewlet): |
---|
| 620 | """Base file display viewlet. |
---|
| 621 | """ |
---|
| 622 | grok.baseclass() |
---|
[7993] | 623 | grok.context(IStudent) |
---|
[7097] | 624 | grok.viewletmanager(FileManager) |
---|
| 625 | grok.view(StudentClearanceDisplayFormPage) |
---|
[8106] | 626 | template = default_filedisplay_template |
---|
[7097] | 627 | grok.order(1) |
---|
| 628 | grok.require('waeup.viewStudent') |
---|
[7738] | 629 | label = _(u'File') |
---|
| 630 | title = _(u'Scan') |
---|
[7106] | 631 | download_name = u'filename.jpg' |
---|
[7097] | 632 | |
---|
[7107] | 633 | @property |
---|
| 634 | def file_exists(self): |
---|
| 635 | image = getUtility(IExtFileStore).getFileByContext( |
---|
| 636 | self.context, attr=self.download_name) |
---|
| 637 | if image: |
---|
| 638 | return True |
---|
| 639 | else: |
---|
| 640 | return False |
---|
| 641 | |
---|
[7097] | 642 | class FileUpload(FileDisplay): |
---|
| 643 | """Base upload viewlet. |
---|
| 644 | """ |
---|
| 645 | grok.baseclass() |
---|
[7993] | 646 | grok.context(IStudent) |
---|
[7097] | 647 | grok.viewletmanager(FileManager) |
---|
| 648 | grok.view(StudentClearanceManageFormPage) |
---|
[8106] | 649 | template = default_fileupload_template |
---|
[7127] | 650 | grok.require('waeup.uploadStudentFile') |
---|
[7491] | 651 | tab_redirect = '?tab2' |
---|
[7097] | 652 | mus = 1024 * 150 |
---|
[7735] | 653 | upload_button =_('Upload new file') |
---|
| 654 | delete_button = _('Delete attachment') |
---|
[8135] | 655 | show_viewlet = True |
---|
[7097] | 656 | |
---|
[7117] | 657 | @property |
---|
| 658 | def input_name(self): |
---|
| 659 | return "%s" % self.__name__ |
---|
| 660 | |
---|
[7097] | 661 | def update(self): |
---|
| 662 | self.max_upload_size = string_from_bytes(self.mus) |
---|
[7117] | 663 | delete_button = self.request.form.get( |
---|
| 664 | 'delete_%s' % self.input_name, None) |
---|
| 665 | upload_button = self.request.form.get( |
---|
| 666 | 'upload_%s' % self.input_name, None) |
---|
[7108] | 667 | if delete_button: |
---|
[7107] | 668 | handle_file_delete( |
---|
| 669 | context=self.context, view=self.view, |
---|
| 670 | download_name=self.download_name) |
---|
| 671 | self.view.redirect( |
---|
[7134] | 672 | self.view.url( |
---|
| 673 | self.context, self.view.__name__) + self.tab_redirect) |
---|
[7107] | 674 | return |
---|
[7108] | 675 | if upload_button: |
---|
| 676 | upload = self.request.form.get(self.input_name, None) |
---|
| 677 | if upload: |
---|
| 678 | # We got a fresh upload |
---|
[7111] | 679 | handle_file_upload(upload, |
---|
| 680 | self.context, self.view, self.mus, self.download_name) |
---|
| 681 | self.view.redirect( |
---|
[7134] | 682 | self.view.url( |
---|
| 683 | self.context, self.view.__name__) + self.tab_redirect) |
---|
[7117] | 684 | else: |
---|
[7738] | 685 | self.view.flash(_('No local file selected.')) |
---|
[7117] | 686 | self.view.redirect( |
---|
[7134] | 687 | self.view.url( |
---|
| 688 | self.context, self.view.__name__) + self.tab_redirect) |
---|
[7097] | 689 | return |
---|
| 690 | |
---|
[7112] | 691 | class PassportDisplay(FileDisplay): |
---|
| 692 | """Passport display viewlet. |
---|
| 693 | """ |
---|
| 694 | grok.order(1) |
---|
| 695 | grok.context(IStudent) |
---|
| 696 | grok.view(StudentBaseDisplayFormPage) |
---|
| 697 | grok.require('waeup.viewStudent') |
---|
| 698 | grok.template('imagedisplay') |
---|
[7738] | 699 | label = _(u'Passport Picture') |
---|
[7112] | 700 | download_name = u'passport.jpg' |
---|
| 701 | |
---|
| 702 | class PassportUploadManage(FileUpload): |
---|
| 703 | """Passport upload viewlet for officers. |
---|
| 704 | """ |
---|
| 705 | grok.order(1) |
---|
| 706 | grok.context(IStudent) |
---|
| 707 | grok.view(StudentBaseManageFormPage) |
---|
[7136] | 708 | grok.require('waeup.manageStudent') |
---|
[7112] | 709 | grok.template('imageupload') |
---|
[7738] | 710 | label = _(u'Passport Picture (jpg only)') |
---|
[7112] | 711 | mus = 1024 * 50 |
---|
| 712 | download_name = u'passport.jpg' |
---|
[7491] | 713 | tab_redirect = '?tab2' |
---|
[7112] | 714 | |
---|
| 715 | class PassportUploadEdit(PassportUploadManage): |
---|
| 716 | """Passport upload viewlet for students. |
---|
| 717 | """ |
---|
[7114] | 718 | grok.view(StudentFilesUploadPage) |
---|
[7127] | 719 | grok.require('waeup.uploadStudentFile') |
---|
[7112] | 720 | |
---|
[7097] | 721 | class BirthCertificateDisplay(FileDisplay): |
---|
[7112] | 722 | """Birth Certificate display viewlet. |
---|
[7097] | 723 | """ |
---|
| 724 | grok.order(1) |
---|
[7738] | 725 | label = _(u'Birth Certificate') |
---|
| 726 | title = _(u'Birth Certificate Scan') |
---|
[7123] | 727 | download_name = u'birth_certificate' |
---|
[7097] | 728 | |
---|
[7280] | 729 | class BirthCertificateSlip(BirthCertificateDisplay): |
---|
| 730 | grok.view(ExportPDFClearanceSlipPage) |
---|
| 731 | |
---|
[7127] | 732 | class BirthCertificateUpload(FileUpload): |
---|
[7097] | 733 | """Birth Certificate upload viewlet. |
---|
| 734 | """ |
---|
| 735 | grok.order(1) |
---|
[7738] | 736 | label = _(u'Birth Certificate') |
---|
| 737 | title = _(u'Birth Certificate Scan') |
---|
[7097] | 738 | mus = 1024 * 150 |
---|
[7123] | 739 | download_name = u'birth_certificate' |
---|
[7491] | 740 | tab_redirect = '?tab2' |
---|
[7097] | 741 | |
---|
[7111] | 742 | class AcceptanceLetterDisplay(FileDisplay): |
---|
[7112] | 743 | """Acceptance Letter display viewlet. |
---|
[7111] | 744 | """ |
---|
| 745 | grok.order(1) |
---|
[7738] | 746 | label = _(u'Acceptance Letter') |
---|
| 747 | title = _(u'Acceptance Letter Scan') |
---|
[8109] | 748 | download_name = u'acc_let' |
---|
[7111] | 749 | |
---|
[7280] | 750 | class AcceptanceLetterSlip(AcceptanceLetterDisplay): |
---|
| 751 | grok.view(ExportPDFClearanceSlipPage) |
---|
| 752 | |
---|
[7127] | 753 | class AcceptanceLetterUpload(FileUpload): |
---|
[7111] | 754 | """AcceptanceLetter upload viewlet. |
---|
| 755 | """ |
---|
[7112] | 756 | grok.order(2) |
---|
[7738] | 757 | label = _(u'Acceptance Letter') |
---|
| 758 | title = _(u'Acceptance Letter Scan') |
---|
[7111] | 759 | mus = 1024 * 150 |
---|
[8109] | 760 | download_name = u'acc_let' |
---|
[7491] | 761 | tab_redirect = '?tab2' |
---|
[7111] | 762 | |
---|
[7097] | 763 | class Image(grok.View): |
---|
[7351] | 764 | """Renders images for students. |
---|
[7097] | 765 | """ |
---|
[7106] | 766 | grok.baseclass() |
---|
[7097] | 767 | grok.name('none.jpg') |
---|
[7993] | 768 | grok.context(IStudent) |
---|
[7097] | 769 | grok.require('waeup.viewStudent') |
---|
[7106] | 770 | download_name = u'none.jpg' |
---|
[7097] | 771 | |
---|
| 772 | def render(self): |
---|
| 773 | # A filename chooser turns a context into a filename suitable |
---|
| 774 | # for file storage. |
---|
| 775 | image = getUtility(IExtFileStore).getFileByContext( |
---|
[7106] | 776 | self.context, attr=self.download_name) |
---|
[7097] | 777 | if image is None: |
---|
| 778 | # show placeholder image |
---|
[7123] | 779 | self.response.setHeader('Content-Type', 'image/jpeg') |
---|
[7097] | 780 | return open(DEFAULT_IMAGE_PATH, 'rb').read() |
---|
[7123] | 781 | dummy,ext = os.path.splitext(image.name) |
---|
| 782 | if ext == '.jpg': |
---|
| 783 | self.response.setHeader('Content-Type', 'image/jpeg') |
---|
| 784 | elif ext == '.png': |
---|
| 785 | self.response.setHeader('Content-Type', 'image/png') |
---|
| 786 | elif ext == '.pdf': |
---|
| 787 | self.response.setHeader('Content-Type', 'application/pdf') |
---|
| 788 | elif ext == '.tif': |
---|
| 789 | self.response.setHeader('Content-Type', 'image/tiff') |
---|
[7097] | 790 | return image |
---|
| 791 | |
---|
[7112] | 792 | class Passport(Image): |
---|
| 793 | """Renders jpeg passport picture. |
---|
| 794 | """ |
---|
| 795 | grok.name('passport.jpg') |
---|
| 796 | download_name = u'passport.jpg' |
---|
| 797 | grok.context(IStudent) |
---|
| 798 | |
---|
[7351] | 799 | class ApplicationSlipImage(Image): |
---|
| 800 | """Renders application slip scan. |
---|
| 801 | """ |
---|
| 802 | grok.name('application_slip') |
---|
| 803 | download_name = u'application_slip' |
---|
| 804 | |
---|
[7097] | 805 | class BirthCertificateImage(Image): |
---|
[7351] | 806 | """Renders birth certificate scan. |
---|
[7097] | 807 | """ |
---|
[7123] | 808 | grok.name('birth_certificate') |
---|
| 809 | download_name = u'birth_certificate' |
---|
[7111] | 810 | |
---|
| 811 | class AcceptanceLetterImage(Image): |
---|
[7351] | 812 | """Renders acceptance letter scan. |
---|
[7111] | 813 | """ |
---|
[8109] | 814 | grok.name('acc_let') |
---|
| 815 | download_name = u'acc_let' |
---|