[12225] | 1 | ## $Id: fileviewlets.py 12458 2015-01-13 07:59:19Z 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 |
---|
| 20 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
[12240] | 21 | from waeup.ikoba.interfaces import PUBLISHED |
---|
| 22 | from waeup.ikoba.browser.layout import UtilityView |
---|
[12225] | 23 | from waeup.ikoba.browser.fileviewlets import ( |
---|
| 24 | FileDisplay, FileUpload, Image) |
---|
| 25 | |
---|
| 26 | from waeup.ikoba.documents.document import PDFDocument |
---|
| 27 | from waeup.ikoba.documents.browser import ( |
---|
| 28 | DocumentManageFormPage, DocumentDisplayFormPage) |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | # File viewlets for documents |
---|
| 32 | |
---|
| 33 | class PDFScanManageUpload(FileUpload): |
---|
| 34 | """Scan upload viewlet for officers. |
---|
| 35 | """ |
---|
| 36 | grok.view(DocumentManageFormPage) |
---|
| 37 | grok.context(PDFDocument) |
---|
| 38 | grok.require('waeup.manageDocuments') |
---|
| 39 | label = _(u'PDF File') |
---|
| 40 | title = _(u'PDF File') |
---|
| 41 | mus = 1024 * 200 |
---|
[12444] | 42 | download_name = u'file.pdf' |
---|
[12225] | 43 | tab_redirect = '#tab2' |
---|
| 44 | |
---|
[12446] | 45 | @property |
---|
| 46 | def download_filename(self): |
---|
[12458] | 47 | return u"%s.pdf" % self.context.document_id |
---|
[12225] | 48 | |
---|
[12446] | 49 | |
---|
[12225] | 50 | class PDFScanDisplay(FileDisplay): |
---|
| 51 | """Scan display viewlet. |
---|
| 52 | """ |
---|
| 53 | grok.order(1) |
---|
| 54 | grok.context(PDFDocument) |
---|
| 55 | grok.require('waeup.viewDocuments') |
---|
| 56 | grok.view(DocumentDisplayFormPage) |
---|
| 57 | label = _(u'PDF Scan') |
---|
| 58 | title = _(u'PDF Scan') |
---|
[12444] | 59 | download_name = u'file.pdf' |
---|
[12225] | 60 | |
---|
[12446] | 61 | @property |
---|
| 62 | def download_filename(self): |
---|
[12458] | 63 | return u"%s.pdf" % self.context.document_id |
---|
[12225] | 64 | |
---|
[12446] | 65 | |
---|
[12241] | 66 | class PDFScanImage(UtilityView, Image): |
---|
[12225] | 67 | """Scan document. |
---|
| 68 | """ |
---|
[12444] | 69 | grok.name('file.pdf') |
---|
[12225] | 70 | grok.context(PDFDocument) |
---|
| 71 | grok.require('waeup.Public') |
---|
[12444] | 72 | download_name = u'file.pdf' |
---|
[12225] | 73 | |
---|
[12446] | 74 | @property |
---|
| 75 | def download_filename(self): |
---|
[12458] | 76 | return u"%s" % self.context.document_id |
---|
[12446] | 77 | |
---|
[12241] | 78 | def update(self): |
---|
[12240] | 79 | if self.context.state != PUBLISHED: |
---|
| 80 | self.flash(_('The document requested has not yet been published.'), |
---|
| 81 | type="warning") |
---|
[12243] | 82 | self.redirect(self.application_url()) |
---|
[12241] | 83 | return |
---|