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

Last change on this file since 17877 was 17877, checked in by Henrik Bettermann, 11 months ago

Add an id to download filenames if necessary. Enable this feature for Final Year Clearance Routing Slip.

  • Property svn:keywords set to Id
File size: 7.1 KB
RevLine 
[12438]1## $Id: fileviewlets.py 17877 2024-08-10 07:01:52Z 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,
[17867]39    ExportPDFClearanceSlip, StudentFilesUploadPage, StudentSignatureUploadPage,
40    StudentFinalClearanceUploadPage)
[12421]41
42grok.context(IKofaObject) # Make IKofaObject the default context
43grok.templatedir('browser_templates')
44
[12448]45# File viewlet baseclasses for student base page
[12421]46
[12448]47class StudentFileDisplay(FileDisplay):
[12421]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
[12447]56
[12448]57class StudentFileUpload(FileUpload):
[12421]58    """Base upload viewlet.
59    """
60    grok.baseclass()
61    grok.context(IStudent)
62    grok.view(StudentClearanceManageFormPage)
63    grok.require('waeup.uploadStudentFile')
64
65    @property
[15652]66    def mus(self):
67        students_utils = getUtility(IStudentsUtils)
68        return 1024 * students_utils.MAX_KB
69
70    @property
[12421]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
[12448]78class StudentImage(Image):
79    """Renders images for students.
80    """
81    grok.baseclass()
82    grok.context(IStudent)
83    grok.require('waeup.viewStudent')
[12421]84
[12448]85
[16609]86# File viewlets for student base and clearance page
[12448]87
88class PassportDisplay(StudentFileDisplay):
[12421]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
[12448]99
100class PassportUploadManage(StudentFileUpload):
[12421]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
[15833]112    @property
113    def mus(self):
114        kofa_utils = getUtility(IKofaUtils)
115        return kofa_utils.MAX_PASSPORT_SIZE
[12448]116
[17867]117class PassportUploadEdit(PassportUploadManage):
118    """Passport upload viewlet for students.
119    """
120    grok.view(StudentFilesUploadPage)
121    grok.require('waeup.uploadStudentFile')
[15833]122
[16609]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
[17867]151class SignatureUploadEdit(SignatureUploadManage):
152    """Signature upload viewlet for students.
[12421]153    """
[17867]154    grok.view(StudentSignatureUploadPage)
[12421]155    grok.require('waeup.uploadStudentFile')
156
[12448]157
[17867]158class FinalClearanceDisplay(StudentFileDisplay):
159    """Final Clearance Routing Slip display viewlet.
[16609]160    """
[17867]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 ')
[17877]166    download_name = u'routingslip.pdf'
[17867]167
168class FinalClearanceUploadManage(StudentFileUpload):
169    """Final Clearance Routing Slip upload viewlet for officers.
170    """
171    grok.order(4)
172    grok.context(IStudent)
173    grok.view(StudentBaseManageFormPage)
174    grok.require('waeup.manageStudent')
[17877]175    label = _(u'Scanned Final Clearance Routing Slip (pdf only)')
176    download_name = u'routingslip.pdf'
[17867]177
178class FinalClearanceUploadEdit(FinalClearanceUploadManage):
179    """Final Clearance Form upload viewlet for students.
180    """
181    grok.view(StudentFinalClearanceUploadPage)
[16609]182    grok.require('waeup.uploadStudentFile')
183
[12448]184class BirthCertificateDisplay(StudentFileDisplay):
[12421]185    """Birth Certificate display viewlet.
186    """
187    grok.order(1)
188    label = _(u'Birth Certificate')
189    title = _(u'Birth Certificate Scan')
190    download_name = u'birth_certificate'
191
[12448]192
[12421]193class BirthCertificateSlip(BirthCertificateDisplay):
[13056]194    grok.view(ExportPDFClearanceSlip)
[12421]195
[12448]196
197class BirthCertificateUpload(StudentFileUpload):
[12421]198    """Birth Certificate upload viewlet.
199    """
200    grok.order(1)
201    label = _(u'Birth Certificate')
202    title = _(u'Birth Certificate Scan')
203    download_name = u'birth_certificate'
204    tab_redirect = '#tab2-top'
205
206
[12448]207class Passport(StudentImage):
[12421]208    """Renders jpeg passport picture.
209    """
210    grok.name('passport.jpg')
211    download_name = u'passport.jpg'
212    grok.context(IStudent)
213
[16609]214class Signature(StudentImage):
215    """Renders jpeg signature.
216    """
217    grok.name('signature.jpg')
218    download_name = u'signature.jpg'
219    grok.context(IStudent)
[12448]220
[17867]221class FinalClearance(StudentImage):
222    """Renders pdf slip.
223    """
[17877]224    grok.name('routingslip.pdf')
[17867]225    download_name = u'routingslip'
226
[17877]227    @property
228    def add_id(self):
229        return self.context.student_id
230
[12448]231class ApplicationSlipImage(StudentImage):
[12421]232    """Renders application slip scan.
233    """
234    grok.name('application_slip')
235    download_name = u'application_slip'
236
[12448]237
[15163]238class FinalTranscriptImage(StudentImage):
239    """Renders final transcript.
240    """
241    grok.name('final_transcript')
242    download_name = u'final_transcript'
243
244
[12448]245class BirthCertificateImage(StudentImage):
[12421]246    """Renders birth certificate scan.
247    """
248    grok.name('birth_certificate')
249    download_name = u'birth_certificate'
Note: See TracBrowser for help on using the repository browser.