source: main/waeup.kofa/trunk/src/waeup/kofa/students/fileviewlets.py @ 17816

Last change on this file since 17816 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
RevLine 
[12438]1## $Id: fileviewlets.py 16609 2021-09-08 07:15:07Z 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
19import os
20import grok
21from zope.component import getUtility
22from waeup.kofa.interfaces import MessageFactory as _
23from waeup.kofa.interfaces import (
[15833]24    IExtFileStore, IFileStoreNameChooser, IKofaObject, IKofaUtils)
[12421]25from waeup.kofa.utils.helpers import string_from_bytes, file_size
26
27from waeup.kofa.students.interfaces import IStudent, IStudentsUtils
28
[12448]29from waeup.kofa.browser.fileviewlets import (
30    FileDisplay, FileUpload, Image)
31
[12421]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,
[16609]39    ExportPDFClearanceSlip, StudentFilesUploadPage, StudentSignatureUploadPage)
[12421]40
41grok.context(IKofaObject) # Make IKofaObject the default context
42grok.templatedir('browser_templates')
43
[12448]44# File viewlet baseclasses for student base page
[12421]45
[12448]46class StudentFileDisplay(FileDisplay):
[12421]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
[12447]55
[12448]56class StudentFileUpload(FileUpload):
[12421]57    """Base upload viewlet.
58    """
59    grok.baseclass()
60    grok.context(IStudent)
61    grok.view(StudentClearanceManageFormPage)
62    grok.require('waeup.uploadStudentFile')
63
64    @property
[15652]65    def mus(self):
66        students_utils = getUtility(IStudentsUtils)
67        return 1024 * students_utils.MAX_KB
68
69    @property
[12421]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
[12448]77class StudentImage(Image):
78    """Renders images for students.
79    """
80    grok.baseclass()
81    grok.context(IStudent)
82    grok.require('waeup.viewStudent')
[12421]83
[12448]84
[16609]85# File viewlets for student base and clearance page
[12448]86
87class PassportDisplay(StudentFileDisplay):
[12421]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
[12448]98
99class PassportUploadManage(StudentFileUpload):
[12421]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
[15833]111    @property
112    def mus(self):
113        kofa_utils = getUtility(IKofaUtils)
114        return kofa_utils.MAX_PASSPORT_SIZE
[12448]115
[15833]116
[16609]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
[12421]147class PassportUploadEdit(PassportUploadManage):
148    """Passport upload viewlet for students.
149    """
150    grok.view(StudentFilesUploadPage)
151    grok.require('waeup.uploadStudentFile')
152
[12448]153
[16609]154class SignatureUploadEdit(SignatureUploadManage):
155    """Signature upload viewlet for students.
156    """
157    grok.view(StudentSignatureUploadPage)
158    grok.require('waeup.uploadStudentFile')
159
160
[12448]161class BirthCertificateDisplay(StudentFileDisplay):
[12421]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
[12448]169
[12421]170class BirthCertificateSlip(BirthCertificateDisplay):
[13056]171    grok.view(ExportPDFClearanceSlip)
[12421]172
[12448]173
174class BirthCertificateUpload(StudentFileUpload):
[12421]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
[12448]184class Passport(StudentImage):
[12421]185    """Renders jpeg passport picture.
186    """
187    grok.name('passport.jpg')
188    download_name = u'passport.jpg'
189    grok.context(IStudent)
190
[16609]191class Signature(StudentImage):
192    """Renders jpeg signature.
193    """
194    grok.name('signature.jpg')
195    download_name = u'signature.jpg'
196    grok.context(IStudent)
[12448]197
198class ApplicationSlipImage(StudentImage):
[12421]199    """Renders application slip scan.
200    """
201    grok.name('application_slip')
202    download_name = u'application_slip'
203
[12448]204
[15163]205class FinalTranscriptImage(StudentImage):
206    """Renders final transcript.
207    """
208    grok.name('final_transcript')
209    download_name = u'final_transcript'
210
211
[12448]212class BirthCertificateImage(StudentImage):
[12421]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.