source: main/waeup.ikoba/trunk/src/waeup/ikoba/documents/fileviewlets.py @ 15284

Last change on this file since 15284 was 13264, checked in by Henrik Bettermann, 9 years ago

Show file size of pdf documents in the documents section.

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