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
RevLine 
[12438]1## $Id: fileviewlets.py 17867 2024-08-02 19:10:34Z 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 ')
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)
[16609]183    grok.require('waeup.uploadStudentFile')
184
[12448]185class BirthCertificateDisplay(StudentFileDisplay):
[12421]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
[12448]193
[12421]194class BirthCertificateSlip(BirthCertificateDisplay):
[13056]195    grok.view(ExportPDFClearanceSlip)
[12421]196
[12448]197
198class BirthCertificateUpload(StudentFileUpload):
[12421]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
[12448]208class Passport(StudentImage):
[12421]209    """Renders jpeg passport picture.
210    """
211    grok.name('passport.jpg')
212    download_name = u'passport.jpg'
213    grok.context(IStudent)
214
[16609]215class Signature(StudentImage):
216    """Renders jpeg signature.
217    """
218    grok.name('signature.jpg')
219    download_name = u'signature.jpg'
220    grok.context(IStudent)
[12448]221
[17867]222class FinalClearance(StudentImage):
223    """Renders pdf slip.
224    """
225    grok.name('routingslip')
226    download_name = u'routingslip'
227
[12448]228class ApplicationSlipImage(StudentImage):
[12421]229    """Renders application slip scan.
230    """
231    grok.name('application_slip')
232    download_name = u'application_slip'
233
[12448]234
[15163]235class FinalTranscriptImage(StudentImage):
236    """Renders final transcript.
237    """
238    grok.name('final_transcript')
239    download_name = u'final_transcript'
240
241
[12448]242class BirthCertificateImage(StudentImage):
[12421]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.