source: main/waeup.kofa/trunk/src/waeup/kofa/documents/fileviewlets.py @ 17954

Last change on this file since 17954 was 14871, checked in by Henrik Bettermann, 7 years ago

Do it right.

  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1## $Id: fileviewlets.py 14871 2017-10-13 08:48:46Z 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 grok
20from zope.component import getUtility
21from waeup.kofa.interfaces import IExtFileStore
22from waeup.kofa.interfaces import MessageFactory as _
23from waeup.kofa.browser.layout import UtilityView
24from waeup.kofa.browser.fileviewlets import (
25    FileDisplay, FileUpload, Image)
26from waeup.kofa.utils.helpers import file_size
27
28from waeup.kofa.documents.document import PDFDocument
29from waeup.kofa.documents.browser import (
30    DocumentManageFormPage, DocumentDisplayFormPage)
31
32from waeup.kofa.documents.workflow import PUBLISHED
33
34
35# File viewlets for documents
36
37class PDFScanManageUpload(FileUpload):
38    """Scan upload viewlet for officers.
39    """
40    grok.view(DocumentManageFormPage)
41    grok.context(PDFDocument)
42    grok.require('waeup.manageDocuments')
43    label = _(u'PDF File')
44    title = _(u'PDF File')
45    mus = 1.5 * 1024*1024
46    download_name = u'file.pdf'
47    tab_redirect = '#tab2'
48
49    @property
50    def download_filename(self):
51        file = getUtility(IExtFileStore).getFileByContext(
52            self.context, attr=self.download_name)
53        fs = file_size(file)/1024.0
54        return u"%s.pdf (%.1f kB)" % (self.context.document_id, fs)
55
56
57class PDFScanDisplay(FileDisplay):
58    """Scan display viewlet.
59    """
60    grok.order(1)
61    grok.context(PDFDocument)
62    grok.require('waeup.viewDocuments')
63    grok.view(DocumentDisplayFormPage)
64    label = _(u'PDF Scan')
65    title = _(u'PDF Scan')
66    download_name = u'file.pdf'
67
68    @property
69    def download_filename(self):
70        file = getUtility(IExtFileStore).getFileByContext(
71            self.context, attr=self.download_name)
72        fs = file_size(file)/1024.0
73        return u"%s.pdf (%.1f kB)" % (self.context.document_id, fs)
74
75
76class PDFScanImage(UtilityView, Image):
77    """Scan document.
78    """
79    grok.name('file.pdf')
80    grok.context(PDFDocument)
81    grok.require('waeup.Public')
82    download_name = u'file.pdf'
83
84    @property
85    def download_filename(self):
86        return self.context.document_id
87
88    def update(self):
89        if self.context.state != PUBLISHED:
90            self.flash(_('The document requested has not yet been published.'),
91                type="warning")
92            self.redirect(self.application_url())
93        return
Note: See TracBrowser for help on using the repository browser.