[12438] | 1 | ## $Id: fileviewlets.py 15652 2019-10-09 09:27:16Z 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 |
---|
[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 | mus = 1024 * 50 |
---|
| 110 | download_name = u'passport.jpg' |
---|
| 111 | tab_redirect = '#tab2' |
---|
| 112 | |
---|
[12448] | 113 | |
---|
[12421] | 114 | class PassportUploadEdit(PassportUploadManage): |
---|
| 115 | """Passport upload viewlet for students. |
---|
| 116 | """ |
---|
| 117 | grok.view(StudentFilesUploadPage) |
---|
| 118 | grok.require('waeup.uploadStudentFile') |
---|
| 119 | |
---|
[12448] | 120 | |
---|
| 121 | class BirthCertificateDisplay(StudentFileDisplay): |
---|
[12421] | 122 | """Birth Certificate display viewlet. |
---|
| 123 | """ |
---|
| 124 | grok.order(1) |
---|
| 125 | label = _(u'Birth Certificate') |
---|
| 126 | title = _(u'Birth Certificate Scan') |
---|
| 127 | download_name = u'birth_certificate' |
---|
| 128 | |
---|
[12448] | 129 | |
---|
[12421] | 130 | class BirthCertificateSlip(BirthCertificateDisplay): |
---|
[13056] | 131 | grok.view(ExportPDFClearanceSlip) |
---|
[12421] | 132 | |
---|
[12448] | 133 | |
---|
| 134 | class BirthCertificateUpload(StudentFileUpload): |
---|
[12421] | 135 | """Birth Certificate upload viewlet. |
---|
| 136 | """ |
---|
| 137 | grok.order(1) |
---|
| 138 | label = _(u'Birth Certificate') |
---|
| 139 | title = _(u'Birth Certificate Scan') |
---|
| 140 | download_name = u'birth_certificate' |
---|
| 141 | tab_redirect = '#tab2-top' |
---|
| 142 | |
---|
| 143 | |
---|
[12448] | 144 | class Passport(StudentImage): |
---|
[12421] | 145 | """Renders jpeg passport picture. |
---|
| 146 | """ |
---|
| 147 | grok.name('passport.jpg') |
---|
| 148 | download_name = u'passport.jpg' |
---|
| 149 | grok.context(IStudent) |
---|
| 150 | |
---|
[12448] | 151 | |
---|
| 152 | class ApplicationSlipImage(StudentImage): |
---|
[12421] | 153 | """Renders application slip scan. |
---|
| 154 | """ |
---|
| 155 | grok.name('application_slip') |
---|
| 156 | download_name = u'application_slip' |
---|
| 157 | |
---|
[12448] | 158 | |
---|
[15163] | 159 | class FinalTranscriptImage(StudentImage): |
---|
| 160 | """Renders final transcript. |
---|
| 161 | """ |
---|
| 162 | grok.name('final_transcript') |
---|
| 163 | download_name = u'final_transcript' |
---|
| 164 | |
---|
| 165 | |
---|
[12448] | 166 | class BirthCertificateImage(StudentImage): |
---|
[12421] | 167 | """Renders birth certificate scan. |
---|
| 168 | """ |
---|
| 169 | grok.name('birth_certificate') |
---|
| 170 | download_name = u'birth_certificate' |
---|