1 | ## $Id: fileviewlets.py 15163 2018-09-23 05:05:04Z 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) |
---|
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 | |
---|
30 | from waeup.kofa.browser.fileviewlets import ( |
---|
31 | FileDisplay, FileUpload, Image) |
---|
32 | |
---|
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, |
---|
40 | ExportPDFClearanceSlip, StudentFilesUploadPage) |
---|
41 | |
---|
42 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
43 | grok.templatedir('browser_templates') |
---|
44 | |
---|
45 | # File viewlet baseclasses for student base page |
---|
46 | |
---|
47 | class StudentFileDisplay(FileDisplay): |
---|
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 | |
---|
56 | |
---|
57 | class StudentFileUpload(FileUpload): |
---|
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 | |
---|
73 | class StudentImage(Image): |
---|
74 | """Renders images for students. |
---|
75 | """ |
---|
76 | grok.baseclass() |
---|
77 | grok.context(IStudent) |
---|
78 | grok.require('waeup.viewStudent') |
---|
79 | |
---|
80 | |
---|
81 | # File viewlets for student base page |
---|
82 | |
---|
83 | class PassportDisplay(StudentFileDisplay): |
---|
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 | |
---|
94 | |
---|
95 | class PassportUploadManage(StudentFileUpload): |
---|
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 | |
---|
108 | |
---|
109 | class PassportUploadEdit(PassportUploadManage): |
---|
110 | """Passport upload viewlet for students. |
---|
111 | """ |
---|
112 | grok.view(StudentFilesUploadPage) |
---|
113 | grok.require('waeup.uploadStudentFile') |
---|
114 | |
---|
115 | |
---|
116 | class BirthCertificateDisplay(StudentFileDisplay): |
---|
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 | |
---|
124 | |
---|
125 | class BirthCertificateSlip(BirthCertificateDisplay): |
---|
126 | grok.view(ExportPDFClearanceSlip) |
---|
127 | |
---|
128 | |
---|
129 | class BirthCertificateUpload(StudentFileUpload): |
---|
130 | """Birth Certificate upload viewlet. |
---|
131 | """ |
---|
132 | grok.order(1) |
---|
133 | label = _(u'Birth Certificate') |
---|
134 | title = _(u'Birth Certificate Scan') |
---|
135 | mus = 1024 * 250 |
---|
136 | download_name = u'birth_certificate' |
---|
137 | tab_redirect = '#tab2-top' |
---|
138 | |
---|
139 | |
---|
140 | class Passport(StudentImage): |
---|
141 | """Renders jpeg passport picture. |
---|
142 | """ |
---|
143 | grok.name('passport.jpg') |
---|
144 | download_name = u'passport.jpg' |
---|
145 | grok.context(IStudent) |
---|
146 | |
---|
147 | |
---|
148 | class ApplicationSlipImage(StudentImage): |
---|
149 | """Renders application slip scan. |
---|
150 | """ |
---|
151 | grok.name('application_slip') |
---|
152 | download_name = u'application_slip' |
---|
153 | |
---|
154 | |
---|
155 | class FinalTranscriptImage(StudentImage): |
---|
156 | """Renders final transcript. |
---|
157 | """ |
---|
158 | grok.name('final_transcript') |
---|
159 | download_name = u'final_transcript' |
---|
160 | |
---|
161 | |
---|
162 | class BirthCertificateImage(StudentImage): |
---|
163 | """Renders birth certificate scan. |
---|
164 | """ |
---|
165 | grok.name('birth_certificate') |
---|
166 | download_name = u'birth_certificate' |
---|