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