[12438] | 1 | ## $Id: fileviewlets.py 15833 2019-11-21 06:43:08Z 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 ( |
---|
[15833] | 24 | IExtFileStore, IFileStoreNameChooser, IKofaObject, IKofaUtils) |
---|
[12421] | 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 |
---|
[15652] | 66 | def mus(self): |
---|
| 67 | students_utils = getUtility(IStudentsUtils) |
---|
| 68 | return 1024 * students_utils.MAX_KB |
---|
| 69 | |
---|
| 70 | @property |
---|
[12421] | 71 | def show_viewlet(self): |
---|
| 72 | students_utils = getUtility(IStudentsUtils) |
---|
| 73 | if self.__name__ in students_utils.SKIP_UPLOAD_VIEWLETS: |
---|
| 74 | return False |
---|
| 75 | return True |
---|
| 76 | |
---|
| 77 | |
---|
[12448] | 78 | class StudentImage(Image): |
---|
| 79 | """Renders images for students. |
---|
| 80 | """ |
---|
| 81 | grok.baseclass() |
---|
| 82 | grok.context(IStudent) |
---|
| 83 | grok.require('waeup.viewStudent') |
---|
[12421] | 84 | |
---|
[12448] | 85 | |
---|
| 86 | # File viewlets for student base page |
---|
| 87 | |
---|
| 88 | class PassportDisplay(StudentFileDisplay): |
---|
[12421] | 89 | """Passport display viewlet. |
---|
| 90 | """ |
---|
| 91 | grok.order(1) |
---|
| 92 | grok.context(IStudent) |
---|
| 93 | grok.view(StudentBaseDisplayFormPage) |
---|
| 94 | grok.require('waeup.viewStudent') |
---|
| 95 | grok.template('imagedisplay') |
---|
| 96 | label = _(u'Passport Picture') |
---|
| 97 | download_name = u'passport.jpg' |
---|
| 98 | |
---|
[12448] | 99 | |
---|
| 100 | class PassportUploadManage(StudentFileUpload): |
---|
[12421] | 101 | """Passport upload viewlet for officers. |
---|
| 102 | """ |
---|
| 103 | grok.order(1) |
---|
| 104 | grok.context(IStudent) |
---|
| 105 | grok.view(StudentBaseManageFormPage) |
---|
| 106 | grok.require('waeup.manageStudent') |
---|
| 107 | grok.template('imageupload') |
---|
| 108 | label = _(u'Passport Picture (jpg only)') |
---|
| 109 | download_name = u'passport.jpg' |
---|
| 110 | tab_redirect = '#tab2' |
---|
| 111 | |
---|
[15833] | 112 | @property |
---|
| 113 | def mus(self): |
---|
| 114 | kofa_utils = getUtility(IKofaUtils) |
---|
| 115 | return kofa_utils.MAX_PASSPORT_SIZE |
---|
[12448] | 116 | |
---|
[15833] | 117 | |
---|
[12421] | 118 | class PassportUploadEdit(PassportUploadManage): |
---|
| 119 | """Passport upload viewlet for students. |
---|
| 120 | """ |
---|
| 121 | grok.view(StudentFilesUploadPage) |
---|
| 122 | grok.require('waeup.uploadStudentFile') |
---|
| 123 | |
---|
[12448] | 124 | |
---|
| 125 | class BirthCertificateDisplay(StudentFileDisplay): |
---|
[12421] | 126 | """Birth Certificate display viewlet. |
---|
| 127 | """ |
---|
| 128 | grok.order(1) |
---|
| 129 | label = _(u'Birth Certificate') |
---|
| 130 | title = _(u'Birth Certificate Scan') |
---|
| 131 | download_name = u'birth_certificate' |
---|
| 132 | |
---|
[12448] | 133 | |
---|
[12421] | 134 | class BirthCertificateSlip(BirthCertificateDisplay): |
---|
[13056] | 135 | grok.view(ExportPDFClearanceSlip) |
---|
[12421] | 136 | |
---|
[12448] | 137 | |
---|
| 138 | class BirthCertificateUpload(StudentFileUpload): |
---|
[12421] | 139 | """Birth Certificate upload viewlet. |
---|
| 140 | """ |
---|
| 141 | grok.order(1) |
---|
| 142 | label = _(u'Birth Certificate') |
---|
| 143 | title = _(u'Birth Certificate Scan') |
---|
| 144 | download_name = u'birth_certificate' |
---|
| 145 | tab_redirect = '#tab2-top' |
---|
| 146 | |
---|
| 147 | |
---|
[12448] | 148 | class Passport(StudentImage): |
---|
[12421] | 149 | """Renders jpeg passport picture. |
---|
| 150 | """ |
---|
| 151 | grok.name('passport.jpg') |
---|
| 152 | download_name = u'passport.jpg' |
---|
| 153 | grok.context(IStudent) |
---|
| 154 | |
---|
[12448] | 155 | |
---|
| 156 | class ApplicationSlipImage(StudentImage): |
---|
[12421] | 157 | """Renders application slip scan. |
---|
| 158 | """ |
---|
| 159 | grok.name('application_slip') |
---|
| 160 | download_name = u'application_slip' |
---|
| 161 | |
---|
[12448] | 162 | |
---|
[15163] | 163 | class FinalTranscriptImage(StudentImage): |
---|
| 164 | """Renders final transcript. |
---|
| 165 | """ |
---|
| 166 | grok.name('final_transcript') |
---|
| 167 | download_name = u'final_transcript' |
---|
| 168 | |
---|
| 169 | |
---|
[12448] | 170 | class BirthCertificateImage(StudentImage): |
---|
[12421] | 171 | """Renders birth certificate scan. |
---|
| 172 | """ |
---|
| 173 | grok.name('birth_certificate') |
---|
| 174 | download_name = u'birth_certificate' |
---|