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

Last change on this file since 14553 was 13056, checked in by Henrik Bettermann, 10 years ago

Forgotten to rename.

  • Property svn:keywords set to Id
File size: 4.5 KB
RevLine 
[12438]1## $Id: fileviewlets.py 13056 2015-06-16 11:35:48Z 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 (
24    IExtFileStore, IFileStoreNameChooser, IKofaObject)
25from waeup.kofa.utils.helpers import string_from_bytes, file_size
26from waeup.kofa.browser import DEFAULT_IMAGE_PATH
27
28from waeup.kofa.students.interfaces import IStudent, IStudentsUtils
29
[12448]30from waeup.kofa.browser.fileviewlets import (
31    FileDisplay, FileUpload, Image)
32
[12421]33from waeup.kofa.browser.layout import (
34    default_filedisplay_template,
35    default_fileupload_template)
36
37from waeup.kofa.students.browser import (
38    StudentBaseDisplayFormPage, StudentBaseManageFormPage,
39    StudentClearanceDisplayFormPage, StudentClearanceManageFormPage,
[13056]40    ExportPDFClearanceSlip, StudentFilesUploadPage)
[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
66    def show_viewlet(self):
67        students_utils = getUtility(IStudentsUtils)
68        if self.__name__ in students_utils.SKIP_UPLOAD_VIEWLETS:
69            return False
70        return True
71
72
[12448]73class StudentImage(Image):
74    """Renders images for students.
75    """
76    grok.baseclass()
77    grok.context(IStudent)
78    grok.require('waeup.viewStudent')
[12421]79
[12448]80
81# File viewlets for student base page
82
83class PassportDisplay(StudentFileDisplay):
[12421]84    """Passport display viewlet.
85    """
86    grok.order(1)
87    grok.context(IStudent)
88    grok.view(StudentBaseDisplayFormPage)
89    grok.require('waeup.viewStudent')
90    grok.template('imagedisplay')
91    label = _(u'Passport Picture')
92    download_name = u'passport.jpg'
93
[12448]94
95class PassportUploadManage(StudentFileUpload):
[12421]96    """Passport upload viewlet for officers.
97    """
98    grok.order(1)
99    grok.context(IStudent)
100    grok.view(StudentBaseManageFormPage)
101    grok.require('waeup.manageStudent')
102    grok.template('imageupload')
103    label = _(u'Passport Picture (jpg only)')
104    mus = 1024 * 50
105    download_name = u'passport.jpg'
106    tab_redirect = '#tab2'
107
[12448]108
[12421]109class PassportUploadEdit(PassportUploadManage):
110    """Passport upload viewlet for students.
111    """
112    grok.view(StudentFilesUploadPage)
113    grok.require('waeup.uploadStudentFile')
114
[12448]115
116class BirthCertificateDisplay(StudentFileDisplay):
[12421]117    """Birth Certificate display viewlet.
118    """
119    grok.order(1)
120    label = _(u'Birth Certificate')
121    title = _(u'Birth Certificate Scan')
122    download_name = u'birth_certificate'
123
[12448]124
[12421]125class BirthCertificateSlip(BirthCertificateDisplay):
[13056]126    grok.view(ExportPDFClearanceSlip)
[12421]127
[12448]128
129class BirthCertificateUpload(StudentFileUpload):
[12421]130    """Birth Certificate upload viewlet.
131    """
132    grok.order(1)
133    label = _(u'Birth Certificate')
134    title = _(u'Birth Certificate Scan')
135    mus = 1024 * 150
136    download_name = u'birth_certificate'
137    tab_redirect = '#tab2-top'
138
139
[12448]140class Passport(StudentImage):
[12421]141    """Renders jpeg passport picture.
142    """
143    grok.name('passport.jpg')
144    download_name = u'passport.jpg'
145    grok.context(IStudent)
146
[12448]147
148class ApplicationSlipImage(StudentImage):
[12421]149    """Renders application slip scan.
150    """
151    grok.name('application_slip')
152    download_name = u'application_slip'
153
[12448]154
155class BirthCertificateImage(StudentImage):
[12421]156    """Renders birth certificate scan.
157    """
158    grok.name('birth_certificate')
159    download_name = u'birth_certificate'
Note: See TracBrowser for help on using the repository browser.