1 | ## $Id: fileviewlets.py 16609 2021-09-08 07:15:07Z henrik $ |
---|
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, IKofaUtils) |
---|
25 | from waeup.kofa.utils.helpers import string_from_bytes, file_size |
---|
26 | |
---|
27 | from waeup.kofa.students.interfaces import IStudent, IStudentsUtils |
---|
28 | |
---|
29 | from waeup.kofa.browser.fileviewlets import ( |
---|
30 | FileDisplay, FileUpload, Image) |
---|
31 | |
---|
32 | from waeup.kofa.browser.layout import ( |
---|
33 | default_filedisplay_template, |
---|
34 | default_fileupload_template) |
---|
35 | |
---|
36 | from waeup.kofa.students.browser import ( |
---|
37 | StudentBaseDisplayFormPage, StudentBaseManageFormPage, |
---|
38 | StudentClearanceDisplayFormPage, StudentClearanceManageFormPage, |
---|
39 | ExportPDFClearanceSlip, StudentFilesUploadPage, StudentSignatureUploadPage) |
---|
40 | |
---|
41 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
42 | grok.templatedir('browser_templates') |
---|
43 | |
---|
44 | # File viewlet baseclasses for student base page |
---|
45 | |
---|
46 | class StudentFileDisplay(FileDisplay): |
---|
47 | """Base file display viewlet. |
---|
48 | """ |
---|
49 | grok.baseclass() |
---|
50 | grok.context(IStudent) |
---|
51 | grok.view(StudentClearanceDisplayFormPage) |
---|
52 | grok.order(1) |
---|
53 | grok.require('waeup.viewStudent') |
---|
54 | |
---|
55 | |
---|
56 | class StudentFileUpload(FileUpload): |
---|
57 | """Base upload viewlet. |
---|
58 | """ |
---|
59 | grok.baseclass() |
---|
60 | grok.context(IStudent) |
---|
61 | grok.view(StudentClearanceManageFormPage) |
---|
62 | grok.require('waeup.uploadStudentFile') |
---|
63 | |
---|
64 | @property |
---|
65 | def mus(self): |
---|
66 | students_utils = getUtility(IStudentsUtils) |
---|
67 | return 1024 * students_utils.MAX_KB |
---|
68 | |
---|
69 | @property |
---|
70 | def show_viewlet(self): |
---|
71 | students_utils = getUtility(IStudentsUtils) |
---|
72 | if self.__name__ in students_utils.SKIP_UPLOAD_VIEWLETS: |
---|
73 | return False |
---|
74 | return True |
---|
75 | |
---|
76 | |
---|
77 | class StudentImage(Image): |
---|
78 | """Renders images for students. |
---|
79 | """ |
---|
80 | grok.baseclass() |
---|
81 | grok.context(IStudent) |
---|
82 | grok.require('waeup.viewStudent') |
---|
83 | |
---|
84 | |
---|
85 | # File viewlets for student base and clearance page |
---|
86 | |
---|
87 | class PassportDisplay(StudentFileDisplay): |
---|
88 | """Passport display viewlet. |
---|
89 | """ |
---|
90 | grok.order(1) |
---|
91 | grok.context(IStudent) |
---|
92 | grok.view(StudentBaseDisplayFormPage) |
---|
93 | grok.require('waeup.viewStudent') |
---|
94 | grok.template('imagedisplay') |
---|
95 | label = _(u'Passport Picture') |
---|
96 | download_name = u'passport.jpg' |
---|
97 | |
---|
98 | |
---|
99 | class PassportUploadManage(StudentFileUpload): |
---|
100 | """Passport upload viewlet for officers. |
---|
101 | """ |
---|
102 | grok.order(1) |
---|
103 | grok.context(IStudent) |
---|
104 | grok.view(StudentBaseManageFormPage) |
---|
105 | grok.require('waeup.manageStudent') |
---|
106 | grok.template('imageupload') |
---|
107 | label = _(u'Passport Picture (jpg only)') |
---|
108 | download_name = u'passport.jpg' |
---|
109 | tab_redirect = '#tab2' |
---|
110 | |
---|
111 | @property |
---|
112 | def mus(self): |
---|
113 | kofa_utils = getUtility(IKofaUtils) |
---|
114 | return kofa_utils.MAX_PASSPORT_SIZE |
---|
115 | |
---|
116 | |
---|
117 | class SignatureDisplay(StudentFileDisplay): |
---|
118 | """Signature display viewlet. |
---|
119 | """ |
---|
120 | grok.order(2) |
---|
121 | grok.context(IStudent) |
---|
122 | grok.view(StudentBaseDisplayFormPage) |
---|
123 | grok.require('waeup.viewStudent') |
---|
124 | grok.template('imagedisplay') |
---|
125 | label = _(u'Scanned Signature') |
---|
126 | download_name = u'signature.jpg' |
---|
127 | |
---|
128 | |
---|
129 | class SignatureUploadManage(StudentFileUpload): |
---|
130 | """Signature upload viewlet for officers. |
---|
131 | """ |
---|
132 | grok.order(2) |
---|
133 | grok.context(IStudent) |
---|
134 | grok.view(StudentBaseManageFormPage) |
---|
135 | grok.require('waeup.manageStudent') |
---|
136 | grok.template('imageupload') |
---|
137 | label = _(u'Scanned Signature (jpg only)') |
---|
138 | download_name = u'signature.jpg' |
---|
139 | tab_redirect = '#tab2' |
---|
140 | |
---|
141 | @property |
---|
142 | def mus(self): |
---|
143 | kofa_utils = getUtility(IKofaUtils) |
---|
144 | return kofa_utils.MAX_PASSPORT_SIZE |
---|
145 | |
---|
146 | |
---|
147 | class PassportUploadEdit(PassportUploadManage): |
---|
148 | """Passport upload viewlet for students. |
---|
149 | """ |
---|
150 | grok.view(StudentFilesUploadPage) |
---|
151 | grok.require('waeup.uploadStudentFile') |
---|
152 | |
---|
153 | |
---|
154 | class SignatureUploadEdit(SignatureUploadManage): |
---|
155 | """Signature upload viewlet for students. |
---|
156 | """ |
---|
157 | grok.view(StudentSignatureUploadPage) |
---|
158 | grok.require('waeup.uploadStudentFile') |
---|
159 | |
---|
160 | |
---|
161 | class BirthCertificateDisplay(StudentFileDisplay): |
---|
162 | """Birth Certificate display viewlet. |
---|
163 | """ |
---|
164 | grok.order(1) |
---|
165 | label = _(u'Birth Certificate') |
---|
166 | title = _(u'Birth Certificate Scan') |
---|
167 | download_name = u'birth_certificate' |
---|
168 | |
---|
169 | |
---|
170 | class BirthCertificateSlip(BirthCertificateDisplay): |
---|
171 | grok.view(ExportPDFClearanceSlip) |
---|
172 | |
---|
173 | |
---|
174 | class BirthCertificateUpload(StudentFileUpload): |
---|
175 | """Birth Certificate upload viewlet. |
---|
176 | """ |
---|
177 | grok.order(1) |
---|
178 | label = _(u'Birth Certificate') |
---|
179 | title = _(u'Birth Certificate Scan') |
---|
180 | download_name = u'birth_certificate' |
---|
181 | tab_redirect = '#tab2-top' |
---|
182 | |
---|
183 | |
---|
184 | class Passport(StudentImage): |
---|
185 | """Renders jpeg passport picture. |
---|
186 | """ |
---|
187 | grok.name('passport.jpg') |
---|
188 | download_name = u'passport.jpg' |
---|
189 | grok.context(IStudent) |
---|
190 | |
---|
191 | class Signature(StudentImage): |
---|
192 | """Renders jpeg signature. |
---|
193 | """ |
---|
194 | grok.name('signature.jpg') |
---|
195 | download_name = u'signature.jpg' |
---|
196 | grok.context(IStudent) |
---|
197 | |
---|
198 | class ApplicationSlipImage(StudentImage): |
---|
199 | """Renders application slip scan. |
---|
200 | """ |
---|
201 | grok.name('application_slip') |
---|
202 | download_name = u'application_slip' |
---|
203 | |
---|
204 | |
---|
205 | class FinalTranscriptImage(StudentImage): |
---|
206 | """Renders final transcript. |
---|
207 | """ |
---|
208 | grok.name('final_transcript') |
---|
209 | download_name = u'final_transcript' |
---|
210 | |
---|
211 | |
---|
212 | class BirthCertificateImage(StudentImage): |
---|
213 | """Renders birth certificate scan. |
---|
214 | """ |
---|
215 | grok.name('birth_certificate') |
---|
216 | download_name = u'birth_certificate' |
---|