source: main/waeup.kofa/branches/uli-rm-bootstrap/src/waeup/kofa/students/fileviewlets.py @ 17952

Last change on this file since 17952 was 14880, checked in by Henrik Bettermann, 7 years ago

Increase allowed file size.

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1## $Id: fileviewlets.py 14880 2017-10-26 07:05:14Z 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)
25from waeup.kofa.utils.helpers import string_from_bytes, file_size
26from waeup.kofa.browser import DEFAULT_IMAGE_PATH
27
28from waeup.kofa.students.interfaces import IStudent, IStudentsUtils
29
30from waeup.kofa.browser.fileviewlets import (
31    FileDisplay, FileUpload, Image)
32
33from waeup.kofa.browser.layout import (
34    default_filedisplay_template,
35    default_fileupload_template)
36
37from waeup.kofa.students.browser import (
38    StudentBaseDisplayFormPage, StudentBaseManageFormPage,
39    StudentClearanceDisplayFormPage, StudentClearanceManageFormPage,
40    ExportPDFClearanceSlip, StudentFilesUploadPage)
41
42grok.context(IKofaObject) # Make IKofaObject the default context
43grok.templatedir('browser_templates')
44
45# File viewlet baseclasses for student base page
46
47class 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
57class 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
73class 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
83class 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
95class 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
109class PassportUploadEdit(PassportUploadManage):
110    """Passport upload viewlet for students.
111    """
112    grok.view(StudentFilesUploadPage)
113    grok.require('waeup.uploadStudentFile')
114
115
116class 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
125class BirthCertificateSlip(BirthCertificateDisplay):
126    grok.view(ExportPDFClearanceSlip)
127
128
129class 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
140class 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
148class ApplicationSlipImage(StudentImage):
149    """Renders application slip scan.
150    """
151    grok.name('application_slip')
152    download_name = u'application_slip'
153
154
155class BirthCertificateImage(StudentImage):
156    """Renders birth certificate scan.
157    """
158    grok.name('birth_certificate')
159    download_name = u'birth_certificate'
Note: See TracBrowser for help on using the repository browser.