[7191] | 1 | ## $Id: viewlets.py 9124 2012-08-30 06:28:17Z 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 | |
---|
[9124] | 168 | class StudentDeactivateActionButton(ManageActionButton): |
---|
| 169 | grok.order(5) |
---|
| 170 | grok.context(IStudent) |
---|
| 171 | grok.view(StudentBaseDisplayFormPage) |
---|
| 172 | grok.require('waeup.manageStudent') |
---|
| 173 | text = _('Deactivate account') |
---|
| 174 | target = 'deactivate' |
---|
| 175 | icon = 'actionicon_traffic_lights_red.png' |
---|
| 176 | |
---|
| 177 | @property |
---|
| 178 | def target_url(self): |
---|
| 179 | if self.context.suspended: |
---|
| 180 | return '' |
---|
| 181 | return self.view.url(self.view.context, self.target) |
---|
| 182 | |
---|
| 183 | class StudentActivateActionButton(ManageActionButton): |
---|
| 184 | grok.order(5) |
---|
| 185 | grok.context(IStudent) |
---|
| 186 | grok.view(StudentBaseDisplayFormPage) |
---|
| 187 | grok.require('waeup.manageStudent') |
---|
| 188 | text = _('Activate account') |
---|
| 189 | target = 'activate' |
---|
| 190 | icon = 'actionicon_traffic_lights_green.png' |
---|
| 191 | |
---|
| 192 | @property |
---|
| 193 | def target_url(self): |
---|
| 194 | if not self.context.suspended: |
---|
| 195 | return '' |
---|
| 196 | return self.view.url(self.view.context, self.target) |
---|
| 197 | |
---|
[7591] | 198 | class StudentClearanceManageActionButton(ManageActionButton): |
---|
| 199 | grok.order(1) |
---|
| 200 | grok.context(IStudent) |
---|
| 201 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 202 | grok.require('waeup.manageStudent') |
---|
[7738] | 203 | text = _('Manage') |
---|
[8119] | 204 | target = 'manage_clearance' |
---|
[7591] | 205 | |
---|
| 206 | class StudentClearActionButton(ManageActionButton): |
---|
| 207 | grok.order(2) |
---|
| 208 | grok.context(IStudent) |
---|
| 209 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 210 | grok.require('waeup.clearStudent') |
---|
[7738] | 211 | text = _('Clear student') |
---|
[7591] | 212 | target = 'clear' |
---|
| 213 | icon = 'actionicon_accept.png' |
---|
| 214 | |
---|
| 215 | @property |
---|
| 216 | def target_url(self): |
---|
| 217 | if self.context.state != REQUESTED: |
---|
| 218 | return '' |
---|
| 219 | return self.view.url(self.view.context, self.target) |
---|
| 220 | |
---|
| 221 | class StudentRejectClearanceActionButton(ManageActionButton): |
---|
| 222 | grok.order(3) |
---|
| 223 | grok.context(IStudent) |
---|
| 224 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 225 | grok.require('waeup.clearStudent') |
---|
[7738] | 226 | text = _('Reject clearance') |
---|
[7591] | 227 | target = 'reject_clearance' |
---|
| 228 | icon = 'actionicon_reject.png' |
---|
| 229 | |
---|
| 230 | @property |
---|
| 231 | def target_url(self): |
---|
| 232 | if self.context.state not in (REQUESTED, CLEARED): |
---|
| 233 | return '' |
---|
| 234 | return self.view.url(self.view.context, self.target) |
---|
| 235 | |
---|
| 236 | class ClearanceSlipActionButton(ManageActionButton): |
---|
| 237 | grok.order(4) |
---|
| 238 | grok.context(IStudent) |
---|
| 239 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 240 | grok.require('waeup.viewStudent') |
---|
| 241 | icon = 'actionicon_pdf.png' |
---|
[7738] | 242 | text = _('Download clearance slip') |
---|
[7591] | 243 | target = 'clearance.pdf' |
---|
| 244 | |
---|
[8119] | 245 | class ClearanceViewActionButton(ManageActionButton): |
---|
| 246 | grok.order(1) |
---|
| 247 | grok.context(IStudent) |
---|
| 248 | grok.view(StudentClearanceEditFormPage) |
---|
| 249 | grok.require('waeup.viewStudent') |
---|
| 250 | icon = 'actionicon_view.png' |
---|
| 251 | text = _('View') |
---|
| 252 | target = 'view_clearance' |
---|
| 253 | |
---|
| 254 | class PersonalViewActionButton(ManageActionButton): |
---|
| 255 | grok.order(1) |
---|
| 256 | grok.context(IStudent) |
---|
| 257 | grok.view(StudentPersonalEditFormPage) |
---|
| 258 | grok.require('waeup.viewStudent') |
---|
| 259 | icon = 'actionicon_view.png' |
---|
| 260 | text = _('View') |
---|
| 261 | target = 'view_personal' |
---|
| 262 | |
---|
[8903] | 263 | class StudentPersonalManageActionButton(ManageActionButton): |
---|
[7591] | 264 | grok.order(1) |
---|
| 265 | grok.context(IStudent) |
---|
| 266 | grok.view(StudentPersonalDisplayFormPage) |
---|
[8903] | 267 | grok.require('waeup.manageStudent') |
---|
| 268 | text = _('Manage') |
---|
| 269 | target = 'manage_personal' |
---|
| 270 | |
---|
| 271 | class StudentPersonalEditActionButton(ManageActionButton): |
---|
| 272 | grok.order(2) |
---|
| 273 | grok.context(IStudent) |
---|
| 274 | grok.view(StudentPersonalDisplayFormPage) |
---|
| 275 | grok.require('waeup.handleStudent') |
---|
[7738] | 276 | text = _('Edit') |
---|
[7591] | 277 | target = 'edit_personal' |
---|
| 278 | |
---|
| 279 | class StudyCourseManageActionButton(ManageActionButton): |
---|
| 280 | grok.order(1) |
---|
| 281 | grok.context(IStudentStudyCourse) |
---|
| 282 | grok.view(StudyCourseDisplayFormPage) |
---|
| 283 | grok.require('waeup.manageStudent') |
---|
[7738] | 284 | text = _('Manage') |
---|
[7591] | 285 | target = 'manage' |
---|
| 286 | |
---|
[8078] | 287 | class StudyLevelManageActionButton(ManageActionButton): |
---|
[7591] | 288 | grok.order(1) |
---|
| 289 | grok.context(IStudentStudyLevel) |
---|
| 290 | grok.view(StudyLevelDisplayFormPage) |
---|
| 291 | grok.require('waeup.manageStudent') |
---|
[7738] | 292 | text = _('Manage') |
---|
[7591] | 293 | target = 'manage' |
---|
| 294 | |
---|
| 295 | class StudentValidateCoursesActionButton(ManageActionButton): |
---|
| 296 | grok.order(3) |
---|
| 297 | grok.context(IStudentStudyLevel) |
---|
| 298 | grok.view(StudyLevelDisplayFormPage) |
---|
| 299 | grok.require('waeup.validateStudent') |
---|
[7738] | 300 | text = _('Validate courses') |
---|
[7591] | 301 | target = 'validate_courses' |
---|
| 302 | icon = 'actionicon_accept.png' |
---|
| 303 | |
---|
| 304 | @property |
---|
| 305 | def target_url(self): |
---|
[8736] | 306 | if self.context.student.state != REGISTERED or \ |
---|
[7591] | 307 | str(self.context.__parent__.current_level) != self.context.__name__: |
---|
| 308 | return '' |
---|
| 309 | return self.view.url(self.view.context, self.target) |
---|
| 310 | |
---|
| 311 | class StudentRejectCoursesActionButton(ManageActionButton): |
---|
| 312 | grok.order(4) |
---|
| 313 | grok.context(IStudentStudyLevel) |
---|
| 314 | grok.view(StudyLevelDisplayFormPage) |
---|
| 315 | grok.require('waeup.validateStudent') |
---|
[7738] | 316 | text = _('Reject courses') |
---|
[7591] | 317 | target = 'reject_courses' |
---|
| 318 | icon = 'actionicon_reject.png' |
---|
| 319 | |
---|
| 320 | @property |
---|
| 321 | def target_url(self): |
---|
[8736] | 322 | if self.context.student.state not in (VALIDATED, REGISTERED) or \ |
---|
[7591] | 323 | str(self.context.__parent__.current_level) != self.context.__name__: |
---|
| 324 | return '' |
---|
| 325 | return self.view.url(self.view.context, self.target) |
---|
| 326 | |
---|
[8078] | 327 | class CourseRegistrationSlipActionButton(ManageActionButton): |
---|
| 328 | grok.order(5) |
---|
| 329 | grok.context(IStudentStudyLevel) |
---|
| 330 | grok.view(StudyLevelDisplayFormPage) |
---|
| 331 | grok.require('waeup.viewStudent') |
---|
| 332 | icon = 'actionicon_pdf.png' |
---|
| 333 | text = _('Download course registration slip') |
---|
| 334 | target = 'course_registration.pdf' |
---|
| 335 | |
---|
[7591] | 336 | class CourseTicketManageActionButton(ManageActionButton): |
---|
| 337 | grok.order(1) |
---|
| 338 | grok.context(ICourseTicket) |
---|
| 339 | grok.view(CourseTicketDisplayFormPage) |
---|
| 340 | grok.require('waeup.manageStudent') |
---|
[7738] | 341 | text = _('Manage') |
---|
[7591] | 342 | target = 'manage' |
---|
| 343 | |
---|
| 344 | #class OnlinePaymentManageActionButton(ManageActionButton): |
---|
| 345 | # grok.order(1) |
---|
| 346 | # grok.context(IStudentPaymentsContainer) |
---|
| 347 | # grok.view(PaymentsDisplayFormPage) |
---|
| 348 | # grok.require('waeup.manageStudent') |
---|
| 349 | # text = 'Manage payments' |
---|
| 350 | # target = 'manage' |
---|
| 351 | |
---|
| 352 | class PaymentReceiptActionButton(ManageActionButton): |
---|
[9070] | 353 | grok.order(9) # This button should always be the last one. |
---|
[7591] | 354 | grok.context(IStudentOnlinePayment) |
---|
| 355 | grok.view(OnlinePaymentDisplayFormPage) |
---|
| 356 | grok.require('waeup.viewStudent') |
---|
| 357 | icon = 'actionicon_pdf.png' |
---|
[8262] | 358 | text = _('Download payment slip') |
---|
| 359 | target = 'payment_slip.pdf' |
---|
[7591] | 360 | |
---|
| 361 | @property |
---|
| 362 | def target_url(self): |
---|
[8262] | 363 | #if self.context.p_state != 'paid': |
---|
| 364 | # return '' |
---|
[7591] | 365 | return self.view.url(self.view.context, self.target) |
---|
| 366 | |
---|
[8420] | 367 | class ApprovePaymentActionButton(ManageActionButton): |
---|
[9070] | 368 | grok.order(8) |
---|
[7591] | 369 | grok.context(IStudentOnlinePayment) |
---|
| 370 | grok.view(OnlinePaymentDisplayFormPage) |
---|
[8420] | 371 | grok.require('waeup.managePortal') |
---|
[8435] | 372 | icon = 'actionicon_accept.png' |
---|
[8420] | 373 | text = _('Approve payment') |
---|
| 374 | target = 'approve' |
---|
[7591] | 375 | |
---|
| 376 | @property |
---|
| 377 | def target_url(self): |
---|
[7888] | 378 | if self.context.p_state == 'paid': |
---|
[7591] | 379 | return '' |
---|
| 380 | return self.view.url(self.view.context, self.target) |
---|
| 381 | |
---|
| 382 | class AddBedTicketActionButton(ManageActionButton): |
---|
| 383 | grok.order(1) |
---|
| 384 | grok.context(IStudentAccommodation) |
---|
| 385 | grok.view(AccommodationManageFormPage) |
---|
| 386 | grok.require('waeup.handleAccommodation') |
---|
| 387 | icon = 'actionicon_home.png' |
---|
[7738] | 388 | text = _('Book accommodation') |
---|
[7591] | 389 | target = 'add' |
---|
| 390 | |
---|
| 391 | class BedTicketSlipActionButton(ManageActionButton): |
---|
| 392 | grok.order(1) |
---|
| 393 | grok.context(IBedTicket) |
---|
| 394 | grok.view(BedTicketDisplayFormPage) |
---|
| 395 | grok.require('waeup.handleAccommodation') |
---|
| 396 | icon = 'actionicon_pdf.png' |
---|
[7738] | 397 | text = _('Download bed allocation slip') |
---|
[7591] | 398 | target = 'bed_allocation.pdf' |
---|
| 399 | |
---|
| 400 | class RelocateStudentActionButton(ManageActionButton): |
---|
| 401 | grok.order(2) |
---|
| 402 | grok.context(IBedTicket) |
---|
| 403 | grok.view(BedTicketDisplayFormPage) |
---|
| 404 | grok.require('waeup.manageHostels') |
---|
| 405 | icon = 'actionicon_reload.png' |
---|
[7738] | 406 | text = _('Relocate student') |
---|
[7591] | 407 | target = 'relocate' |
---|
| 408 | |
---|
| 409 | class StudentBaseActionButton(ManageActionButton): |
---|
| 410 | grok.order(1) |
---|
| 411 | grok.context(IStudent) |
---|
| 412 | grok.view(StudentBaseDisplayFormPage) |
---|
| 413 | grok.require('waeup.handleStudent') |
---|
[7876] | 414 | text = _('Edit') |
---|
[7591] | 415 | target = 'edit_base' |
---|
| 416 | |
---|
| 417 | class StudentPasswordActionButton(ManageActionButton): |
---|
| 418 | grok.order(2) |
---|
| 419 | grok.context(IStudent) |
---|
| 420 | grok.view(StudentBaseDisplayFormPage) |
---|
| 421 | grok.require('waeup.handleStudent') |
---|
| 422 | icon = 'actionicon_key.png' |
---|
[7738] | 423 | text = _('Change password') |
---|
[7591] | 424 | target = 'change_password' |
---|
| 425 | |
---|
| 426 | class StudentPassportActionButton(ManageActionButton): |
---|
| 427 | grok.order(3) |
---|
| 428 | grok.context(IStudent) |
---|
| 429 | grok.view(StudentBaseDisplayFormPage) |
---|
| 430 | grok.require('waeup.handleStudent') |
---|
| 431 | icon = 'actionicon_portrait.png' |
---|
[7738] | 432 | text = _('Change portrait') |
---|
[7591] | 433 | target = 'change_portrait' |
---|
| 434 | |
---|
| 435 | @property |
---|
| 436 | def target_url(self): |
---|
[7671] | 437 | if self.context.state != ADMITTED: |
---|
[7591] | 438 | return '' |
---|
| 439 | return self.view.url(self.view.context, self.target) |
---|
| 440 | |
---|
| 441 | class StudentClearanceStartActionButton(ManageActionButton): |
---|
| 442 | grok.order(1) |
---|
| 443 | grok.context(IStudent) |
---|
| 444 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 445 | grok.require('waeup.handleStudent') |
---|
| 446 | icon = 'actionicon_start.gif' |
---|
[7738] | 447 | text = _('Start clearance') |
---|
[7591] | 448 | target = 'start_clearance' |
---|
| 449 | |
---|
| 450 | @property |
---|
| 451 | def target_url(self): |
---|
[7671] | 452 | if self.context.state != ADMITTED: |
---|
[7591] | 453 | return '' |
---|
| 454 | return self.view.url(self.view.context, self.target) |
---|
| 455 | |
---|
| 456 | class StudentClearanceEditActionButton(ManageActionButton): |
---|
| 457 | grok.order(1) |
---|
| 458 | grok.context(IStudent) |
---|
| 459 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 460 | grok.require('waeup.handleStudent') |
---|
[7738] | 461 | text = _('Edit') |
---|
[7591] | 462 | target = 'cedit' |
---|
| 463 | |
---|
| 464 | @property |
---|
| 465 | def target_url(self): |
---|
| 466 | if self.context.clearance_locked: |
---|
| 467 | return '' |
---|
| 468 | return self.view.url(self.view.context, self.target) |
---|
| 469 | |
---|
[8476] | 470 | class StartSessionActionButton(ManageActionButton): |
---|
[7591] | 471 | grok.order(1) |
---|
| 472 | grok.context(IStudentStudyCourse) |
---|
| 473 | grok.view(StudyCourseDisplayFormPage) |
---|
| 474 | grok.require('waeup.handleStudent') |
---|
| 475 | icon = 'actionicon_start.gif' |
---|
[8920] | 476 | text = _('Start new session') |
---|
[8471] | 477 | target = 'start_session' |
---|
[7591] | 478 | |
---|
| 479 | @property |
---|
| 480 | def target_url(self): |
---|
[8471] | 481 | if self.context.next_session_allowed: |
---|
| 482 | return self.view.url(self.view.context, self.target) |
---|
| 483 | return False |
---|
[7591] | 484 | |
---|
| 485 | class AddStudyLevelActionButton(AddActionButton): |
---|
| 486 | grok.order(1) |
---|
| 487 | grok.context(IStudentStudyCourse) |
---|
| 488 | grok.view(StudyCourseDisplayFormPage) |
---|
| 489 | grok.require('waeup.handleStudent') |
---|
[7738] | 490 | text = _('Add course list') |
---|
[7591] | 491 | target = 'add' |
---|
| 492 | |
---|
| 493 | @property |
---|
| 494 | def target_url(self): |
---|
[8736] | 495 | student = self.view.context.student |
---|
[7671] | 496 | condition1 = student.state != PAID |
---|
[7591] | 497 | condition2 = str(student['studycourse'].current_level) in \ |
---|
| 498 | self.view.context.keys() |
---|
| 499 | if condition1 or condition2: |
---|
| 500 | return '' |
---|
| 501 | return self.view.url(self.view.context, self.target) |
---|
| 502 | |
---|
| 503 | class StudyLevelEditActionButton(ManageActionButton): |
---|
[8078] | 504 | grok.order(2) |
---|
[7591] | 505 | grok.context(IStudentStudyLevel) |
---|
| 506 | grok.view(StudyLevelDisplayFormPage) |
---|
| 507 | grok.require('waeup.handleStudent') |
---|
[8920] | 508 | text = _('Edit course list') |
---|
[7591] | 509 | target = 'edit' |
---|
| 510 | |
---|
| 511 | @property |
---|
| 512 | def target_url(self): |
---|
[8736] | 513 | student = self.view.context.student |
---|
[7671] | 514 | condition1 = student.state != PAID |
---|
[7591] | 515 | condition2 = student[ |
---|
| 516 | 'studycourse'].current_level != self.view.context.level |
---|
| 517 | if condition1 or condition2: |
---|
| 518 | return '' |
---|
| 519 | return self.view.url(self.view.context, self.target) |
---|
| 520 | |
---|
[7184] | 521 | class StudentsTab(PrimaryNavTab): |
---|
| 522 | """Students tab in primary navigation. |
---|
| 523 | """ |
---|
| 524 | |
---|
[7819] | 525 | grok.context(IKofaObject) |
---|
[7184] | 526 | grok.order(4) |
---|
[7240] | 527 | grok.require('waeup.viewStudentsTab') |
---|
[7184] | 528 | |
---|
| 529 | pnav = 4 |
---|
[7674] | 530 | tab_title = _(u'Students') |
---|
[7184] | 531 | |
---|
| 532 | @property |
---|
| 533 | def link_target(self): |
---|
| 534 | return self.view.application_url('students') |
---|
| 535 | |
---|
[6687] | 536 | class PrimaryStudentNavManager(grok.ViewletManager): |
---|
| 537 | """Viewlet manager for the primary navigation tab. |
---|
| 538 | """ |
---|
| 539 | grok.name('primary_nav_student') |
---|
| 540 | |
---|
| 541 | class PrimaryStudentNavTab(grok.Viewlet): |
---|
| 542 | """Base for primary student nav tabs. |
---|
| 543 | """ |
---|
| 544 | grok.baseclass() |
---|
| 545 | grok.viewletmanager(PrimaryStudentNavManager) |
---|
[7243] | 546 | template = default_primary_nav_template |
---|
[6687] | 547 | grok.order(1) |
---|
[7184] | 548 | grok.require('waeup.Authenticated') |
---|
[8467] | 549 | pnav = 0 |
---|
[6687] | 550 | tab_title = u'Some Text' |
---|
| 551 | |
---|
| 552 | @property |
---|
| 553 | def link_target(self): |
---|
| 554 | return self.view.application_url() |
---|
| 555 | |
---|
| 556 | @property |
---|
| 557 | def active(self): |
---|
| 558 | view_pnav = getattr(self.view, 'pnav', 0) |
---|
| 559 | if view_pnav == self.pnav: |
---|
| 560 | return 'active' |
---|
| 561 | return '' |
---|
| 562 | |
---|
[7240] | 563 | class MyStudentDataTab(PrimaryStudentNavTab): |
---|
[7459] | 564 | """MyData dropdown tab in primary navigation. |
---|
[6687] | 565 | """ |
---|
| 566 | grok.order(3) |
---|
[7240] | 567 | grok.require('waeup.viewMyStudentDataTab') |
---|
[7459] | 568 | grok.template('mydatadropdowntabs') |
---|
[6687] | 569 | pnav = 4 |
---|
[7738] | 570 | tab_title = _(u'My Data') |
---|
[6687] | 571 | |
---|
| 572 | @property |
---|
[7459] | 573 | def active(self): |
---|
| 574 | view_pnav = getattr(self.view, 'pnav', 0) |
---|
| 575 | if view_pnav == self.pnav: |
---|
| 576 | return 'active dropdown' |
---|
| 577 | return 'dropdown' |
---|
[7097] | 578 | |
---|
[7459] | 579 | @property |
---|
| 580 | def targets(self): |
---|
| 581 | student_url = self.view.application_url() + ( |
---|
| 582 | '/students/%s' % self.request.principal.id) |
---|
| 583 | #app_slip = getUtility(IExtFileStore).getFileByContext( |
---|
[8736] | 584 | # self.context.student, 'application_slip') |
---|
[7459] | 585 | targets = [] |
---|
| 586 | #if app_slip: |
---|
| 587 | # targets = [{'url':student_url + '/application_slip', 'title':'Application Slip'},] |
---|
| 588 | targets += [ |
---|
| 589 | {'url':student_url, 'title':'Base Data'}, |
---|
[8467] | 590 | {'url':student_url + '/view_clearance', |
---|
| 591 | 'title':_('Clearance Data')}, |
---|
[7738] | 592 | {'url':student_url + '/view_personal', 'title':_('Personal Data')}, |
---|
| 593 | {'url':student_url + '/studycourse', 'title':_('Study Course')}, |
---|
| 594 | {'url':student_url + '/payments', 'title':_('Payments')}, |
---|
[8467] | 595 | {'url':student_url + '/accommodation', |
---|
| 596 | 'title':_('Accommodation Data')}, |
---|
[7738] | 597 | {'url':student_url + '/history', 'title':_('History')}, |
---|
[7459] | 598 | ] |
---|
| 599 | return targets |
---|
| 600 | |
---|
[7107] | 601 | def handle_file_delete(context, view, download_name): |
---|
| 602 | """Handle deletion of student file. |
---|
| 603 | |
---|
| 604 | """ |
---|
| 605 | store = getUtility(IExtFileStore) |
---|
| 606 | store.deleteFileByContext(context, attr=download_name) |
---|
[8735] | 607 | context.writeLogMessage(view, 'deleted: %s' % download_name) |
---|
[7738] | 608 | view.flash(_('${a} deleted.', mapping = {'a':download_name})) |
---|
[7107] | 609 | return |
---|
| 610 | |
---|
[7106] | 611 | def handle_file_upload(upload, context, view, max_size, download_name=None): |
---|
| 612 | """Handle upload of student file. |
---|
[7097] | 613 | |
---|
| 614 | Returns `True` in case of success or `False`. |
---|
| 615 | |
---|
| 616 | Please note that file pointer passed in (`upload`) most probably |
---|
| 617 | points to end of file when leaving this function. |
---|
| 618 | """ |
---|
[7106] | 619 | # Check some file requirements first |
---|
[8467] | 620 | size = file_size(upload) |
---|
| 621 | if size > max_size: |
---|
| 622 | view.flash(_('Uploaded file is too big.')) |
---|
[7106] | 623 | return False |
---|
[8467] | 624 | upload.seek(0) # file pointer moved when determining size |
---|
| 625 | file_format = get_fileformat(None, upload.read(512)) |
---|
| 626 | upload.seek(0) # same here |
---|
| 627 | if file_format is None: |
---|
| 628 | view.flash(_('Could not determine file type.')) |
---|
[7106] | 629 | return False |
---|
| 630 | basename, expected_ext = os.path.splitext(download_name) |
---|
[7123] | 631 | if expected_ext: |
---|
[8467] | 632 | if '.' + file_format != expected_ext: |
---|
[7738] | 633 | view.flash(_('${a} file extension expected.', |
---|
[8467] | 634 | mapping = {'a':expected_ext[1:]})) |
---|
[7123] | 635 | return False |
---|
| 636 | else: |
---|
[8467] | 637 | if not file_format in ALLOWED_FILE_EXTENSIONS: |
---|
[7123] | 638 | view.flash( |
---|
[8467] | 639 | _('Only the following extensions are allowed: ${a}', |
---|
[7738] | 640 | mapping = {'a':', '.join(ALLOWED_FILE_EXTENSIONS)})) |
---|
[7123] | 641 | return False |
---|
[8467] | 642 | download_name += '.' + file_format |
---|
[7097] | 643 | store = getUtility(IExtFileStore) |
---|
[7106] | 644 | file_id = IFileStoreNameChooser(context).chooseName(attr=download_name) |
---|
[7097] | 645 | store.createFile(file_id, upload) |
---|
[8735] | 646 | context.writeLogMessage(view, 'uploaded: %s (%s)' % ( |
---|
[8467] | 647 | download_name,upload.filename)) |
---|
[7738] | 648 | view.flash(_('File ${a} uploaded.', mapping = {'a':download_name})) |
---|
[7097] | 649 | return True |
---|
| 650 | |
---|
| 651 | class FileManager(grok.ViewletManager): |
---|
| 652 | """Viewlet manager for uploading files, preferably scanned images. |
---|
| 653 | """ |
---|
| 654 | grok.name('files') |
---|
| 655 | |
---|
| 656 | class FileDisplay(grok.Viewlet): |
---|
| 657 | """Base file display viewlet. |
---|
| 658 | """ |
---|
| 659 | grok.baseclass() |
---|
[7993] | 660 | grok.context(IStudent) |
---|
[7097] | 661 | grok.viewletmanager(FileManager) |
---|
| 662 | grok.view(StudentClearanceDisplayFormPage) |
---|
[8106] | 663 | template = default_filedisplay_template |
---|
[7097] | 664 | grok.order(1) |
---|
| 665 | grok.require('waeup.viewStudent') |
---|
[7738] | 666 | label = _(u'File') |
---|
| 667 | title = _(u'Scan') |
---|
[7106] | 668 | download_name = u'filename.jpg' |
---|
[7097] | 669 | |
---|
[7107] | 670 | @property |
---|
| 671 | def file_exists(self): |
---|
| 672 | image = getUtility(IExtFileStore).getFileByContext( |
---|
| 673 | self.context, attr=self.download_name) |
---|
| 674 | if image: |
---|
| 675 | return True |
---|
| 676 | else: |
---|
| 677 | return False |
---|
| 678 | |
---|
[7097] | 679 | class FileUpload(FileDisplay): |
---|
| 680 | """Base upload viewlet. |
---|
| 681 | """ |
---|
| 682 | grok.baseclass() |
---|
[7993] | 683 | grok.context(IStudent) |
---|
[7097] | 684 | grok.viewletmanager(FileManager) |
---|
| 685 | grok.view(StudentClearanceManageFormPage) |
---|
[8106] | 686 | template = default_fileupload_template |
---|
[7127] | 687 | grok.require('waeup.uploadStudentFile') |
---|
[7491] | 688 | tab_redirect = '?tab2' |
---|
[7097] | 689 | mus = 1024 * 150 |
---|
[7735] | 690 | upload_button =_('Upload new file') |
---|
| 691 | delete_button = _('Delete attachment') |
---|
[8135] | 692 | show_viewlet = True |
---|
[7097] | 693 | |
---|
[7117] | 694 | @property |
---|
| 695 | def input_name(self): |
---|
| 696 | return "%s" % self.__name__ |
---|
| 697 | |
---|
[7097] | 698 | def update(self): |
---|
| 699 | self.max_upload_size = string_from_bytes(self.mus) |
---|
[7117] | 700 | delete_button = self.request.form.get( |
---|
| 701 | 'delete_%s' % self.input_name, None) |
---|
| 702 | upload_button = self.request.form.get( |
---|
| 703 | 'upload_%s' % self.input_name, None) |
---|
[7108] | 704 | if delete_button: |
---|
[7107] | 705 | handle_file_delete( |
---|
| 706 | context=self.context, view=self.view, |
---|
| 707 | download_name=self.download_name) |
---|
| 708 | self.view.redirect( |
---|
[7134] | 709 | self.view.url( |
---|
| 710 | self.context, self.view.__name__) + self.tab_redirect) |
---|
[7107] | 711 | return |
---|
[7108] | 712 | if upload_button: |
---|
| 713 | upload = self.request.form.get(self.input_name, None) |
---|
| 714 | if upload: |
---|
| 715 | # We got a fresh upload |
---|
[7111] | 716 | handle_file_upload(upload, |
---|
| 717 | self.context, self.view, self.mus, self.download_name) |
---|
| 718 | self.view.redirect( |
---|
[7134] | 719 | self.view.url( |
---|
| 720 | self.context, self.view.__name__) + self.tab_redirect) |
---|
[7117] | 721 | else: |
---|
[7738] | 722 | self.view.flash(_('No local file selected.')) |
---|
[7117] | 723 | self.view.redirect( |
---|
[7134] | 724 | self.view.url( |
---|
| 725 | self.context, self.view.__name__) + self.tab_redirect) |
---|
[7097] | 726 | return |
---|
| 727 | |
---|
[7112] | 728 | class PassportDisplay(FileDisplay): |
---|
| 729 | """Passport display viewlet. |
---|
| 730 | """ |
---|
| 731 | grok.order(1) |
---|
| 732 | grok.context(IStudent) |
---|
| 733 | grok.view(StudentBaseDisplayFormPage) |
---|
| 734 | grok.require('waeup.viewStudent') |
---|
| 735 | grok.template('imagedisplay') |
---|
[7738] | 736 | label = _(u'Passport Picture') |
---|
[7112] | 737 | download_name = u'passport.jpg' |
---|
| 738 | |
---|
| 739 | class PassportUploadManage(FileUpload): |
---|
| 740 | """Passport upload viewlet for officers. |
---|
| 741 | """ |
---|
| 742 | grok.order(1) |
---|
| 743 | grok.context(IStudent) |
---|
| 744 | grok.view(StudentBaseManageFormPage) |
---|
[7136] | 745 | grok.require('waeup.manageStudent') |
---|
[7112] | 746 | grok.template('imageupload') |
---|
[7738] | 747 | label = _(u'Passport Picture (jpg only)') |
---|
[7112] | 748 | mus = 1024 * 50 |
---|
| 749 | download_name = u'passport.jpg' |
---|
[7491] | 750 | tab_redirect = '?tab2' |
---|
[7112] | 751 | |
---|
| 752 | class PassportUploadEdit(PassportUploadManage): |
---|
| 753 | """Passport upload viewlet for students. |
---|
| 754 | """ |
---|
[7114] | 755 | grok.view(StudentFilesUploadPage) |
---|
[7127] | 756 | grok.require('waeup.uploadStudentFile') |
---|
[7112] | 757 | |
---|
[7097] | 758 | class BirthCertificateDisplay(FileDisplay): |
---|
[7112] | 759 | """Birth Certificate display viewlet. |
---|
[7097] | 760 | """ |
---|
| 761 | grok.order(1) |
---|
[7738] | 762 | label = _(u'Birth Certificate') |
---|
| 763 | title = _(u'Birth Certificate Scan') |
---|
[7123] | 764 | download_name = u'birth_certificate' |
---|
[7097] | 765 | |
---|
[7280] | 766 | class BirthCertificateSlip(BirthCertificateDisplay): |
---|
| 767 | grok.view(ExportPDFClearanceSlipPage) |
---|
| 768 | |
---|
[7127] | 769 | class BirthCertificateUpload(FileUpload): |
---|
[7097] | 770 | """Birth Certificate upload viewlet. |
---|
| 771 | """ |
---|
| 772 | grok.order(1) |
---|
[7738] | 773 | label = _(u'Birth Certificate') |
---|
| 774 | title = _(u'Birth Certificate Scan') |
---|
[7097] | 775 | mus = 1024 * 150 |
---|
[7123] | 776 | download_name = u'birth_certificate' |
---|
[7491] | 777 | tab_redirect = '?tab2' |
---|
[7097] | 778 | |
---|
[7111] | 779 | class AcceptanceLetterDisplay(FileDisplay): |
---|
[7112] | 780 | """Acceptance Letter display viewlet. |
---|
[7111] | 781 | """ |
---|
| 782 | grok.order(1) |
---|
[7738] | 783 | label = _(u'Acceptance Letter') |
---|
| 784 | title = _(u'Acceptance Letter Scan') |
---|
[8109] | 785 | download_name = u'acc_let' |
---|
[7111] | 786 | |
---|
[7280] | 787 | class AcceptanceLetterSlip(AcceptanceLetterDisplay): |
---|
| 788 | grok.view(ExportPDFClearanceSlipPage) |
---|
| 789 | |
---|
[7127] | 790 | class AcceptanceLetterUpload(FileUpload): |
---|
[7111] | 791 | """AcceptanceLetter upload viewlet. |
---|
| 792 | """ |
---|
[7112] | 793 | grok.order(2) |
---|
[7738] | 794 | label = _(u'Acceptance Letter') |
---|
| 795 | title = _(u'Acceptance Letter Scan') |
---|
[7111] | 796 | mus = 1024 * 150 |
---|
[8109] | 797 | download_name = u'acc_let' |
---|
[7491] | 798 | tab_redirect = '?tab2' |
---|
[7111] | 799 | |
---|
[7097] | 800 | class Image(grok.View): |
---|
[7351] | 801 | """Renders images for students. |
---|
[7097] | 802 | """ |
---|
[7106] | 803 | grok.baseclass() |
---|
[7097] | 804 | grok.name('none.jpg') |
---|
[7993] | 805 | grok.context(IStudent) |
---|
[7097] | 806 | grok.require('waeup.viewStudent') |
---|
[7106] | 807 | download_name = u'none.jpg' |
---|
[7097] | 808 | |
---|
| 809 | def render(self): |
---|
| 810 | # A filename chooser turns a context into a filename suitable |
---|
| 811 | # for file storage. |
---|
| 812 | image = getUtility(IExtFileStore).getFileByContext( |
---|
[7106] | 813 | self.context, attr=self.download_name) |
---|
[7097] | 814 | if image is None: |
---|
| 815 | # show placeholder image |
---|
[7123] | 816 | self.response.setHeader('Content-Type', 'image/jpeg') |
---|
[7097] | 817 | return open(DEFAULT_IMAGE_PATH, 'rb').read() |
---|
[7123] | 818 | dummy,ext = os.path.splitext(image.name) |
---|
| 819 | if ext == '.jpg': |
---|
| 820 | self.response.setHeader('Content-Type', 'image/jpeg') |
---|
| 821 | elif ext == '.png': |
---|
| 822 | self.response.setHeader('Content-Type', 'image/png') |
---|
| 823 | elif ext == '.pdf': |
---|
| 824 | self.response.setHeader('Content-Type', 'application/pdf') |
---|
| 825 | elif ext == '.tif': |
---|
| 826 | self.response.setHeader('Content-Type', 'image/tiff') |
---|
[7097] | 827 | return image |
---|
| 828 | |
---|
[7112] | 829 | class Passport(Image): |
---|
| 830 | """Renders jpeg passport picture. |
---|
| 831 | """ |
---|
| 832 | grok.name('passport.jpg') |
---|
| 833 | download_name = u'passport.jpg' |
---|
| 834 | grok.context(IStudent) |
---|
| 835 | |
---|
[7351] | 836 | class ApplicationSlipImage(Image): |
---|
| 837 | """Renders application slip scan. |
---|
| 838 | """ |
---|
| 839 | grok.name('application_slip') |
---|
| 840 | download_name = u'application_slip' |
---|
| 841 | |
---|
[7097] | 842 | class BirthCertificateImage(Image): |
---|
[7351] | 843 | """Renders birth certificate scan. |
---|
[7097] | 844 | """ |
---|
[7123] | 845 | grok.name('birth_certificate') |
---|
| 846 | download_name = u'birth_certificate' |
---|
[7111] | 847 | |
---|
| 848 | class AcceptanceLetterImage(Image): |
---|
[7351] | 849 | """Renders acceptance letter scan. |
---|
[7111] | 850 | """ |
---|
[8109] | 851 | grok.name('acc_let') |
---|
| 852 | download_name = u'acc_let' |
---|