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

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

Do it right.

  • Property svn:keywords set to Id
File size: 3.0 KB
RevLine 
[12438]1## $Id: fileviewlets.py 14871 2017-10-13 08:48:46Z henrik $
[12437]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
[13263]20from zope.component import getUtility
21from waeup.kofa.interfaces import IExtFileStore
[12437]22from waeup.kofa.interfaces import MessageFactory as _
23from waeup.kofa.browser.layout import UtilityView
[12448]24from waeup.kofa.browser.fileviewlets import (
[12437]25    FileDisplay, FileUpload, Image)
[13263]26from waeup.kofa.utils.helpers import file_size
[12437]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')
[14871]45    mus = 1.5 * 1024*1024
[12456]46    download_name = u'file.pdf'
[12437]47    tab_redirect = '#tab2'
48
[12447]49    @property
50    def download_filename(self):
[13263]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)
[12437]55
[12447]56
[12437]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')
[12456]66    download_name = u'file.pdf'
[12437]67
[12447]68    @property
69    def download_filename(self):
[13263]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)
[12437]74
[12447]75
[12437]76class PDFScanImage(UtilityView, Image):
77    """Scan document.
78    """
[12456]79    grok.name('file.pdf')
[12437]80    grok.context(PDFDocument)
81    grok.require('waeup.Public')
[12456]82    download_name = u'file.pdf'
[12437]83
[12447]84    @property
85    def download_filename(self):
86        return self.context.document_id
87
[12437]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.