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, 10 hours ago
  • Change header of marksheet.
  • Add student_id to all download filenames.
  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1## $Id: fileviewlets.py 18076 2025-05-18 16:27:41Z 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    @property
86    def add_id(self):
87        return self.context.student_id
88
89# File viewlets for student base and clearance page
90
91class PassportDisplay(StudentFileDisplay):
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
102
103class PassportUploadManage(StudentFileUpload):
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
115    @property
116    def mus(self):
117        kofa_utils = getUtility(IKofaUtils)
118        return kofa_utils.MAX_PASSPORT_SIZE
119
120class PassportUploadEdit(PassportUploadManage):
121    """Passport upload viewlet for students.
122    """
123    grok.view(StudentFilesUploadPage)
124    grok.require('waeup.uploadStudentFile')
125
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
154class SignatureUploadEdit(SignatureUploadManage):
155    """Signature upload viewlet for students.
156    """
157    grok.view(StudentSignatureUploadPage)
158    grok.require('waeup.uploadStudentFile')
159
160
161class FinalClearanceDisplay(StudentFileDisplay):
162    """Final Clearance Routing Slip display viewlet.
163    """
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 ')
169    download_name = u'routingslip.pdf'
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')
178    label = _(u'Scanned Final Clearance Routing Slip (pdf only)')
179    download_name = u'routingslip.pdf'
180    mus = 1024 * 500
181
182class FinalClearanceUploadEdit(FinalClearanceUploadManage):
183    """Final Clearance Form upload viewlet for students.
184    """
185    grok.view(StudentFinalClearanceUploadPage)
186    grok.require('waeup.uploadStudentFile')
187
188class BirthCertificateDisplay(StudentFileDisplay):
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
196
197class BirthCertificateSlip(BirthCertificateDisplay):
198    grok.view(ExportPDFClearanceSlip)
199
200
201class BirthCertificateUpload(StudentFileUpload):
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
211class Passport(StudentImage):
212    """Renders jpeg passport picture.
213    """
214    grok.name('passport.jpg')
215    download_name = u'passport.jpg'
216    grok.context(IStudent)
217
218class Signature(StudentImage):
219    """Renders jpeg signature.
220    """
221    grok.name('signature.jpg')
222    download_name = u'signature.jpg'
223    grok.context(IStudent)
224
225class FinalClearance(StudentImage):
226    """Renders pdf slip.
227    """
228    grok.name('routingslip.pdf')
229    download_name = u'routingslip'
230
231
232class ApplicationSlipImage(StudentImage):
233    """Renders application slip scan.
234    """
235    grok.name('application_slip')
236    download_name = u'application_slip'
237
238
239class FinalTranscriptImage(StudentImage):
240    """Renders final transcript.
241    """
242    grok.name('final_transcript')
243    download_name = u'final_transcript'
244
245
246class BirthCertificateImage(StudentImage):
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.