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

Last change on this file since 17867 was 17867, checked in by Henrik Bettermann, 3 months ago

Implement Final Year Clearance Routing Slip upload (not active in base package).

  • Property svn:keywords set to Id
File size: 7.0 KB
Line 
1## $Id: fileviewlets.py 17867 2024-08-02 19:10:34Z 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    StudentFinalClearanceUploadPage)
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 mus(self):
67        students_utils = getUtility(IStudentsUtils)
68        return 1024 * students_utils.MAX_KB
69
70    @property
71    def show_viewlet(self):
72        students_utils = getUtility(IStudentsUtils)
73        if self.__name__ in students_utils.SKIP_UPLOAD_VIEWLETS:
74            return False
75        return True
76
77
78class StudentImage(Image):
79    """Renders images for students.
80    """
81    grok.baseclass()
82    grok.context(IStudent)
83    grok.require('waeup.viewStudent')
84
85
86# File viewlets for student base and clearance page
87
88class PassportDisplay(StudentFileDisplay):
89    """Passport display viewlet.
90    """
91    grok.order(1)
92    grok.context(IStudent)
93    grok.view(StudentBaseDisplayFormPage)
94    grok.require('waeup.viewStudent')
95    grok.template('imagedisplay')
96    label = _(u'Passport Picture')
97    download_name = u'passport.jpg'
98
99
100class PassportUploadManage(StudentFileUpload):
101    """Passport upload viewlet for officers.
102    """
103    grok.order(1)
104    grok.context(IStudent)
105    grok.view(StudentBaseManageFormPage)
106    grok.require('waeup.manageStudent')
107    grok.template('imageupload')
108    label = _(u'Passport Picture (jpg only)')
109    download_name = u'passport.jpg'
110    tab_redirect = '#tab2'
111
112    @property
113    def mus(self):
114        kofa_utils = getUtility(IKofaUtils)
115        return kofa_utils.MAX_PASSPORT_SIZE
116
117class PassportUploadEdit(PassportUploadManage):
118    """Passport upload viewlet for students.
119    """
120    grok.view(StudentFilesUploadPage)
121    grok.require('waeup.uploadStudentFile')
122
123class SignatureDisplay(StudentFileDisplay):
124    """Signature display viewlet.
125    """
126    grok.order(2)
127    grok.context(IStudent)
128    grok.view(StudentBaseDisplayFormPage)
129    grok.require('waeup.viewStudent')
130    grok.template('imagedisplay')
131    label = _(u'Scanned Signature')
132    download_name = u'signature.jpg'
133
134class SignatureUploadManage(StudentFileUpload):
135    """Signature upload viewlet for officers.
136    """
137    grok.order(2)
138    grok.context(IStudent)
139    grok.view(StudentBaseManageFormPage)
140    grok.require('waeup.manageStudent')
141    grok.template('imageupload')
142    label = _(u'Scanned Signature (jpg only)')
143    download_name = u'signature.jpg'
144
145    @property
146    def mus(self):
147        kofa_utils = getUtility(IKofaUtils)
148        return kofa_utils.MAX_PASSPORT_SIZE
149
150
151class SignatureUploadEdit(SignatureUploadManage):
152    """Signature upload viewlet for students.
153    """
154    grok.view(StudentSignatureUploadPage)
155    grok.require('waeup.uploadStudentFile')
156
157
158class FinalClearanceDisplay(StudentFileDisplay):
159    """Final Clearance Routing Slip display viewlet.
160    """
161    grok.order(4)
162    grok.context(IStudent)
163    grok.view(StudentBaseDisplayFormPage)
164    grok.require('waeup.viewStudent')
165    label = _(u'Scanned Final Clearance Routing Slip ')
166    download_name = u'routingslip'
167
168
169class FinalClearanceUploadManage(StudentFileUpload):
170    """Final Clearance Routing Slip upload viewlet for officers.
171    """
172    grok.order(4)
173    grok.context(IStudent)
174    grok.view(StudentBaseManageFormPage)
175    grok.require('waeup.manageStudent')
176    label = _(u'Scanned Final Clearance Routing Slip (pdf preferred)')
177    download_name = u'routingslip'
178
179class FinalClearanceUploadEdit(FinalClearanceUploadManage):
180    """Final Clearance Form upload viewlet for students.
181    """
182    grok.view(StudentFinalClearanceUploadPage)
183    grok.require('waeup.uploadStudentFile')
184
185class BirthCertificateDisplay(StudentFileDisplay):
186    """Birth Certificate display viewlet.
187    """
188    grok.order(1)
189    label = _(u'Birth Certificate')
190    title = _(u'Birth Certificate Scan')
191    download_name = u'birth_certificate'
192
193
194class BirthCertificateSlip(BirthCertificateDisplay):
195    grok.view(ExportPDFClearanceSlip)
196
197
198class BirthCertificateUpload(StudentFileUpload):
199    """Birth Certificate upload viewlet.
200    """
201    grok.order(1)
202    label = _(u'Birth Certificate')
203    title = _(u'Birth Certificate Scan')
204    download_name = u'birth_certificate'
205    tab_redirect = '#tab2-top'
206
207
208class Passport(StudentImage):
209    """Renders jpeg passport picture.
210    """
211    grok.name('passport.jpg')
212    download_name = u'passport.jpg'
213    grok.context(IStudent)
214
215class Signature(StudentImage):
216    """Renders jpeg signature.
217    """
218    grok.name('signature.jpg')
219    download_name = u'signature.jpg'
220    grok.context(IStudent)
221
222class FinalClearance(StudentImage):
223    """Renders pdf slip.
224    """
225    grok.name('routingslip')
226    download_name = u'routingslip'
227
228class ApplicationSlipImage(StudentImage):
229    """Renders application slip scan.
230    """
231    grok.name('application_slip')
232    download_name = u'application_slip'
233
234
235class FinalTranscriptImage(StudentImage):
236    """Renders final transcript.
237    """
238    grok.name('final_transcript')
239    download_name = u'final_transcript'
240
241
242class BirthCertificateImage(StudentImage):
243    """Renders birth certificate scan.
244    """
245    grok.name('birth_certificate')
246    download_name = u'birth_certificate'
Note: See TracBrowser for help on using the repository browser.