[12438] | 1 | ## $Id: fileviewlets.py 14880 2017-10-26 07:05:14Z henrik $ |
---|
[12421] | 2 | ## |
---|
| 3 | ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
| 18 | |
---|
| 19 | import os |
---|
| 20 | import grok |
---|
| 21 | from zope.component import getUtility |
---|
| 22 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
| 23 | from waeup.kofa.interfaces import ( |
---|
| 24 | IExtFileStore, IFileStoreNameChooser, IKofaObject) |
---|
| 25 | from waeup.kofa.utils.helpers import string_from_bytes, file_size |
---|
| 26 | from waeup.kofa.browser import DEFAULT_IMAGE_PATH |
---|
| 27 | |
---|
| 28 | from waeup.kofa.students.interfaces import IStudent, IStudentsUtils |
---|
| 29 | |
---|
[12448] | 30 | from waeup.kofa.browser.fileviewlets import ( |
---|
| 31 | FileDisplay, FileUpload, Image) |
---|
| 32 | |
---|
[12421] | 33 | from waeup.kofa.browser.layout import ( |
---|
| 34 | default_filedisplay_template, |
---|
| 35 | default_fileupload_template) |
---|
| 36 | |
---|
| 37 | from waeup.kofa.students.browser import ( |
---|
| 38 | StudentBaseDisplayFormPage, StudentBaseManageFormPage, |
---|
| 39 | StudentClearanceDisplayFormPage, StudentClearanceManageFormPage, |
---|
[13056] | 40 | ExportPDFClearanceSlip, StudentFilesUploadPage) |
---|
[12421] | 41 | |
---|
| 42 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
| 43 | grok.templatedir('browser_templates') |
---|
| 44 | |
---|
[12448] | 45 | # File viewlet baseclasses for student base page |
---|
[12421] | 46 | |
---|
[12448] | 47 | class StudentFileDisplay(FileDisplay): |
---|
[12421] | 48 | """Base file display viewlet. |
---|
| 49 | """ |
---|
| 50 | grok.baseclass() |
---|
| 51 | grok.context(IStudent) |
---|
| 52 | grok.view(StudentClearanceDisplayFormPage) |
---|
| 53 | grok.order(1) |
---|
| 54 | grok.require('waeup.viewStudent') |
---|
| 55 | |
---|
[12447] | 56 | |
---|
[12448] | 57 | class StudentFileUpload(FileUpload): |
---|
[12421] | 58 | """Base upload viewlet. |
---|
| 59 | """ |
---|
| 60 | grok.baseclass() |
---|
| 61 | grok.context(IStudent) |
---|
| 62 | grok.view(StudentClearanceManageFormPage) |
---|
| 63 | grok.require('waeup.uploadStudentFile') |
---|
| 64 | |
---|
| 65 | @property |
---|
| 66 | def show_viewlet(self): |
---|
| 67 | students_utils = getUtility(IStudentsUtils) |
---|
| 68 | if self.__name__ in students_utils.SKIP_UPLOAD_VIEWLETS: |
---|
| 69 | return False |
---|
| 70 | return True |
---|
| 71 | |
---|
| 72 | |
---|
[12448] | 73 | class StudentImage(Image): |
---|
| 74 | """Renders images for students. |
---|
| 75 | """ |
---|
| 76 | grok.baseclass() |
---|
| 77 | grok.context(IStudent) |
---|
| 78 | grok.require('waeup.viewStudent') |
---|
[12421] | 79 | |
---|
[12448] | 80 | |
---|
| 81 | # File viewlets for student base page |
---|
| 82 | |
---|
| 83 | class PassportDisplay(StudentFileDisplay): |
---|
[12421] | 84 | """Passport display viewlet. |
---|
| 85 | """ |
---|
| 86 | grok.order(1) |
---|
| 87 | grok.context(IStudent) |
---|
| 88 | grok.view(StudentBaseDisplayFormPage) |
---|
| 89 | grok.require('waeup.viewStudent') |
---|
| 90 | grok.template('imagedisplay') |
---|
| 91 | label = _(u'Passport Picture') |
---|
| 92 | download_name = u'passport.jpg' |
---|
| 93 | |
---|
[12448] | 94 | |
---|
| 95 | class PassportUploadManage(StudentFileUpload): |
---|
[12421] | 96 | """Passport upload viewlet for officers. |
---|
| 97 | """ |
---|
| 98 | grok.order(1) |
---|
| 99 | grok.context(IStudent) |
---|
| 100 | grok.view(StudentBaseManageFormPage) |
---|
| 101 | grok.require('waeup.manageStudent') |
---|
| 102 | grok.template('imageupload') |
---|
| 103 | label = _(u'Passport Picture (jpg only)') |
---|
| 104 | mus = 1024 * 50 |
---|
| 105 | download_name = u'passport.jpg' |
---|
| 106 | tab_redirect = '#tab2' |
---|
| 107 | |
---|
[12448] | 108 | |
---|
[12421] | 109 | class PassportUploadEdit(PassportUploadManage): |
---|
| 110 | """Passport upload viewlet for students. |
---|
| 111 | """ |
---|
| 112 | grok.view(StudentFilesUploadPage) |
---|
| 113 | grok.require('waeup.uploadStudentFile') |
---|
| 114 | |
---|
[12448] | 115 | |
---|
| 116 | class BirthCertificateDisplay(StudentFileDisplay): |
---|
[12421] | 117 | """Birth Certificate display viewlet. |
---|
| 118 | """ |
---|
| 119 | grok.order(1) |
---|
| 120 | label = _(u'Birth Certificate') |
---|
| 121 | title = _(u'Birth Certificate Scan') |
---|
| 122 | download_name = u'birth_certificate' |
---|
| 123 | |
---|
[12448] | 124 | |
---|
[12421] | 125 | class BirthCertificateSlip(BirthCertificateDisplay): |
---|
[13056] | 126 | grok.view(ExportPDFClearanceSlip) |
---|
[12421] | 127 | |
---|
[12448] | 128 | |
---|
| 129 | class BirthCertificateUpload(StudentFileUpload): |
---|
[12421] | 130 | """Birth Certificate upload viewlet. |
---|
| 131 | """ |
---|
| 132 | grok.order(1) |
---|
| 133 | label = _(u'Birth Certificate') |
---|
| 134 | title = _(u'Birth Certificate Scan') |
---|
[14880] | 135 | mus = 1024 * 250 |
---|
[12421] | 136 | download_name = u'birth_certificate' |
---|
| 137 | tab_redirect = '#tab2-top' |
---|
| 138 | |
---|
| 139 | |
---|
[12448] | 140 | class Passport(StudentImage): |
---|
[12421] | 141 | """Renders jpeg passport picture. |
---|
| 142 | """ |
---|
| 143 | grok.name('passport.jpg') |
---|
| 144 | download_name = u'passport.jpg' |
---|
| 145 | grok.context(IStudent) |
---|
| 146 | |
---|
[12448] | 147 | |
---|
| 148 | class ApplicationSlipImage(StudentImage): |
---|
[12421] | 149 | """Renders application slip scan. |
---|
| 150 | """ |
---|
| 151 | grok.name('application_slip') |
---|
| 152 | download_name = u'application_slip' |
---|
| 153 | |
---|
[12448] | 154 | |
---|
| 155 | class BirthCertificateImage(StudentImage): |
---|
[12421] | 156 | """Renders birth certificate scan. |
---|
| 157 | """ |
---|
| 158 | grok.name('birth_certificate') |
---|
| 159 | download_name = u'birth_certificate' |
---|