[12225] | 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 | |
---|
| 19 | import grok |
---|
[13264] | 20 | from zope.component import getUtility |
---|
| 21 | from waeup.ikoba.interfaces import IExtFileStore |
---|
[12225] | 22 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
[12240] | 23 | from waeup.ikoba.interfaces import PUBLISHED |
---|
| 24 | from waeup.ikoba.browser.layout import UtilityView |
---|
[12225] | 25 | from waeup.ikoba.browser.fileviewlets import ( |
---|
| 26 | FileDisplay, FileUpload, Image) |
---|
[13264] | 27 | from waeup.ikoba.utils.helpers import file_size |
---|
[12225] | 28 | |
---|
| 29 | from waeup.ikoba.documents.document import PDFDocument |
---|
| 30 | from waeup.ikoba.documents.browser import ( |
---|
| 31 | DocumentManageFormPage, DocumentDisplayFormPage) |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | # File viewlets for documents |
---|
| 35 | |
---|
| 36 | class 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 |
---|
[12444] | 45 | download_name = u'file.pdf' |
---|
[12225] | 46 | tab_redirect = '#tab2' |
---|
| 47 | |
---|
[12446] | 48 | @property |
---|
| 49 | def download_filename(self): |
---|
[13264] | 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) |
---|
[12225] | 54 | |
---|
[12446] | 55 | |
---|
[12225] | 56 | class 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') |
---|
[12444] | 65 | download_name = u'file.pdf' |
---|
[12225] | 66 | |
---|
[12446] | 67 | @property |
---|
| 68 | def download_filename(self): |
---|
[13264] | 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) |
---|
[12225] | 73 | |
---|
[12446] | 74 | |
---|
[12241] | 75 | class PDFScanImage(UtilityView, Image): |
---|
[12225] | 76 | """Scan document. |
---|
| 77 | """ |
---|
[12444] | 78 | grok.name('file.pdf') |
---|
[12225] | 79 | grok.context(PDFDocument) |
---|
| 80 | grok.require('waeup.Public') |
---|
[12444] | 81 | download_name = u'file.pdf' |
---|
[12225] | 82 | |
---|
[12446] | 83 | @property |
---|
| 84 | def download_filename(self): |
---|
[12458] | 85 | return u"%s" % self.context.document_id |
---|
[12446] | 86 | |
---|
[12241] | 87 | def update(self): |
---|
[12240] | 88 | if self.context.state != PUBLISHED: |
---|
| 89 | self.flash(_('The document requested has not yet been published.'), |
---|
| 90 | type="warning") |
---|
[12243] | 91 | self.redirect(self.application_url()) |
---|
[12241] | 92 | return |
---|