source: main/waeup.kofa/branches/uli-fix-zc-async/src/waeup/kofa/students/fileviewlets.py @ 17688

Last change on this file since 17688 was 16609, checked in by Henrik Bettermann, 3 years ago

Enable students and officers to upload scanned signature in the same
way as passport pictures are handled. Some tabs and titles had to be
renamed. The placeholder file, which is still the portrait
placeholder, are no longer shown on base pages.

  • Property svn:keywords set to Id
File size: 6.0 KB
Line 
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
19import os
20import grok
21from zope.component import getUtility
22from waeup.kofa.interfaces import MessageFactory as _
23from waeup.kofa.interfaces import (
24    IExtFileStore, IFileStoreNameChooser, IKofaObject, IKofaUtils)
25from waeup.kofa.utils.helpers import string_from_bytes, file_size
26
27from waeup.kofa.students.interfaces import IStudent, IStudentsUtils
28
29from waeup.kofa.browser.fileviewlets import (
30    FileDisplay, FileUpload, Image)
31
32from waeup.kofa.browser.layout import (
33    default_filedisplay_template,
34    default_fileupload_template)
35
36from waeup.kofa.students.browser import (
37    StudentBaseDisplayFormPage, StudentBaseManageFormPage,
38    StudentClearanceDisplayFormPage, StudentClearanceManageFormPage,
39    ExportPDFClearanceSlip, StudentFilesUploadPage, StudentSignatureUploadPage)
40
41grok.context(IKofaObject) # Make IKofaObject the default context
42grok.templatedir('browser_templates')
43
44# File viewlet baseclasses for student base page
45
46class 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
56class 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
77class 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
87class 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
99class 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
117class 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
129class 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
147class PassportUploadEdit(PassportUploadManage):
148    """Passport upload viewlet for students.
149    """
150    grok.view(StudentFilesUploadPage)
151    grok.require('waeup.uploadStudentFile')
152
153
154class SignatureUploadEdit(SignatureUploadManage):
155    """Signature upload viewlet for students.
156    """
157    grok.view(StudentSignatureUploadPage)
158    grok.require('waeup.uploadStudentFile')
159
160
161class 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
170class BirthCertificateSlip(BirthCertificateDisplay):
171    grok.view(ExportPDFClearanceSlip)
172
173
174class 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
184class Passport(StudentImage):
185    """Renders jpeg passport picture.
186    """
187    grok.name('passport.jpg')
188    download_name = u'passport.jpg'
189    grok.context(IStudent)
190
191class Signature(StudentImage):
192    """Renders jpeg signature.
193    """
194    grok.name('signature.jpg')
195    download_name = u'signature.jpg'
196    grok.context(IStudent)
197
198class ApplicationSlipImage(StudentImage):
199    """Renders application slip scan.
200    """
201    grok.name('application_slip')
202    download_name = u'application_slip'
203
204
205class FinalTranscriptImage(StudentImage):
206    """Renders final transcript.
207    """
208    grok.name('final_transcript')
209    download_name = u'final_transcript'
210
211
212class BirthCertificateImage(StudentImage):
213    """Renders birth certificate scan.
214    """
215    grok.name('birth_certificate')
216    download_name = u'birth_certificate'
Note: See TracBrowser for help on using the repository browser.