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

Last change on this file since 18076 was 18076, checked in by Henrik Bettermann, 14 hours ago
  • Change header of marksheet.
  • Add student_id to all download filenames.
  • Property svn:keywords set to Id
File size: 7.1 KB
RevLine 
[12438]1## $Id: fileviewlets.py 18076 2025-05-18 16:27:41Z 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
[18076]85    @property
86    def add_id(self):
87        return self.context.student_id
[12448]88
[16609]89# File viewlets for student base and clearance page
[12448]90
91class PassportDisplay(StudentFileDisplay):
[12421]92    """Passport display viewlet.
93    """
94    grok.order(1)
95    grok.context(IStudent)
96    grok.view(StudentBaseDisplayFormPage)
97    grok.require('waeup.viewStudent')
98    grok.template('imagedisplay')
99    label = _(u'Passport Picture')
100    download_name = u'passport.jpg'
101
[12448]102
103class PassportUploadManage(StudentFileUpload):
[12421]104    """Passport upload viewlet for officers.
105    """
106    grok.order(1)
107    grok.context(IStudent)
108    grok.view(StudentBaseManageFormPage)
109    grok.require('waeup.manageStudent')
110    grok.template('imageupload')
111    label = _(u'Passport Picture (jpg only)')
112    download_name = u'passport.jpg'
113    tab_redirect = '#tab2'
114
[15833]115    @property
116    def mus(self):
117        kofa_utils = getUtility(IKofaUtils)
118        return kofa_utils.MAX_PASSPORT_SIZE
[12448]119
[17867]120class PassportUploadEdit(PassportUploadManage):
121    """Passport upload viewlet for students.
122    """
123    grok.view(StudentFilesUploadPage)
124    grok.require('waeup.uploadStudentFile')
[15833]125
[16609]126class SignatureDisplay(StudentFileDisplay):
127    """Signature display viewlet.
128    """
129    grok.order(2)
130    grok.context(IStudent)
131    grok.view(StudentBaseDisplayFormPage)
132    grok.require('waeup.viewStudent')
133    grok.template('imagedisplay')
134    label = _(u'Scanned Signature')
135    download_name = u'signature.jpg'
136
137class SignatureUploadManage(StudentFileUpload):
138    """Signature upload viewlet for officers.
139    """
140    grok.order(2)
141    grok.context(IStudent)
142    grok.view(StudentBaseManageFormPage)
143    grok.require('waeup.manageStudent')
144    grok.template('imageupload')
145    label = _(u'Scanned Signature (jpg only)')
146    download_name = u'signature.jpg'
147
148    @property
149    def mus(self):
150        kofa_utils = getUtility(IKofaUtils)
151        return kofa_utils.MAX_PASSPORT_SIZE
152
153
[17867]154class SignatureUploadEdit(SignatureUploadManage):
155    """Signature upload viewlet for students.
[12421]156    """
[17867]157    grok.view(StudentSignatureUploadPage)
[12421]158    grok.require('waeup.uploadStudentFile')
159
[12448]160
[17867]161class FinalClearanceDisplay(StudentFileDisplay):
162    """Final Clearance Routing Slip display viewlet.
[16609]163    """
[17867]164    grok.order(4)
165    grok.context(IStudent)
166    grok.view(StudentBaseDisplayFormPage)
167    grok.require('waeup.viewStudent')
168    label = _(u'Scanned Final Clearance Routing Slip ')
[17877]169    download_name = u'routingslip.pdf'
[17867]170
171class FinalClearanceUploadManage(StudentFileUpload):
172    """Final Clearance Routing Slip upload viewlet for officers.
173    """
174    grok.order(4)
175    grok.context(IStudent)
176    grok.view(StudentBaseManageFormPage)
177    grok.require('waeup.manageStudent')
[17877]178    label = _(u'Scanned Final Clearance Routing Slip (pdf only)')
179    download_name = u'routingslip.pdf'
[17902]180    mus = 1024 * 500
[17867]181
182class FinalClearanceUploadEdit(FinalClearanceUploadManage):
183    """Final Clearance Form upload viewlet for students.
184    """
185    grok.view(StudentFinalClearanceUploadPage)
[16609]186    grok.require('waeup.uploadStudentFile')
187
[12448]188class BirthCertificateDisplay(StudentFileDisplay):
[12421]189    """Birth Certificate display viewlet.
190    """
191    grok.order(1)
192    label = _(u'Birth Certificate')
193    title = _(u'Birth Certificate Scan')
194    download_name = u'birth_certificate'
195
[12448]196
[12421]197class BirthCertificateSlip(BirthCertificateDisplay):
[13056]198    grok.view(ExportPDFClearanceSlip)
[12421]199
[12448]200
201class BirthCertificateUpload(StudentFileUpload):
[12421]202    """Birth Certificate upload viewlet.
203    """
204    grok.order(1)
205    label = _(u'Birth Certificate')
206    title = _(u'Birth Certificate Scan')
207    download_name = u'birth_certificate'
208    tab_redirect = '#tab2-top'
209
210
[12448]211class Passport(StudentImage):
[12421]212    """Renders jpeg passport picture.
213    """
214    grok.name('passport.jpg')
215    download_name = u'passport.jpg'
216    grok.context(IStudent)
217
[16609]218class Signature(StudentImage):
219    """Renders jpeg signature.
220    """
221    grok.name('signature.jpg')
222    download_name = u'signature.jpg'
223    grok.context(IStudent)
[12448]224
[17867]225class FinalClearance(StudentImage):
226    """Renders pdf slip.
227    """
[17877]228    grok.name('routingslip.pdf')
[17867]229    download_name = u'routingslip'
230
[17877]231
[12448]232class ApplicationSlipImage(StudentImage):
[12421]233    """Renders application slip scan.
234    """
235    grok.name('application_slip')
236    download_name = u'application_slip'
237
[12448]238
[15163]239class FinalTranscriptImage(StudentImage):
240    """Renders final transcript.
241    """
242    grok.name('final_transcript')
243    download_name = u'final_transcript'
244
245
[12448]246class BirthCertificateImage(StudentImage):
[12421]247    """Renders birth certificate scan.
248    """
249    grok.name('birth_certificate')
250    download_name = u'birth_certificate'
Note: See TracBrowser for help on using the repository browser.