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