1 | ## $Id: fileviewlets.py 13066 2015-06-16 14:48:55Z 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 _ |
---|
21 | |
---|
22 | from waeup.ikoba.browser.fileviewlets import ( |
---|
23 | FileDisplay, FileUpload, Image) |
---|
24 | |
---|
25 | from waeup.ikoba.customers.interfaces import ICustomer |
---|
26 | |
---|
27 | from waeup.ikoba.customers.documents import ( |
---|
28 | CustomerSampleDocument, CustomerPDFDocument |
---|
29 | ) |
---|
30 | from waeup.ikoba.customers.browser import ( |
---|
31 | CustomerBaseDisplayFormPage, CustomerBaseManageFormPage, |
---|
32 | CustomerFilesUploadPage, |
---|
33 | DocumentDisplayFormPage, DocumentManageFormPage, DocumentEditFormPage, |
---|
34 | PDFDocumentSlip,) |
---|
35 | |
---|
36 | grok.templatedir('browser_templates') |
---|
37 | |
---|
38 | # File viewlets for customer base page |
---|
39 | |
---|
40 | class PassportDisplay(FileDisplay): |
---|
41 | """Passport display viewlet. |
---|
42 | """ |
---|
43 | grok.order(1) |
---|
44 | grok.context(ICustomer) |
---|
45 | grok.view(CustomerBaseDisplayFormPage) |
---|
46 | grok.require('waeup.viewCustomer') |
---|
47 | grok.template('imagedisplay') |
---|
48 | label = _(u'Passport Picture') |
---|
49 | download_name = u'passport.jpg' |
---|
50 | |
---|
51 | |
---|
52 | class PassportManageUpload(FileUpload): |
---|
53 | """Passport upload viewlet for officers. |
---|
54 | """ |
---|
55 | grok.order(1) |
---|
56 | grok.context(ICustomer) |
---|
57 | grok.view(CustomerBaseManageFormPage) |
---|
58 | grok.require('waeup.manageCustomer') |
---|
59 | grok.template('imageupload') |
---|
60 | label = _(u'Passport Picture (jpg only)') |
---|
61 | mus = 1024 * 50 |
---|
62 | download_name = u'passport.jpg' |
---|
63 | tab_redirect = '#tab2' |
---|
64 | |
---|
65 | |
---|
66 | class PassportEditUpload(PassportManageUpload): |
---|
67 | """Passport upload viewlet for customers. |
---|
68 | """ |
---|
69 | grok.view(CustomerFilesUploadPage) |
---|
70 | grok.require('waeup.handleCustomer') |
---|
71 | |
---|
72 | |
---|
73 | class Passport(Image): |
---|
74 | """Renders jpeg passport picture. |
---|
75 | """ |
---|
76 | grok.name('passport.jpg') |
---|
77 | download_name = u'passport.jpg' |
---|
78 | grok.context(ICustomer) |
---|
79 | grok.require('waeup.viewCustomer') |
---|
80 | |
---|
81 | # File viewlets for customer documents |
---|
82 | |
---|
83 | class SampleScanManageUpload(FileUpload): |
---|
84 | """Scan upload viewlet for officers. |
---|
85 | """ |
---|
86 | grok.order(1) |
---|
87 | grok.context(CustomerSampleDocument) |
---|
88 | grok.view(DocumentManageFormPage) |
---|
89 | grok.require('waeup.manageCustomer') |
---|
90 | label = _(u'Sample Scan') |
---|
91 | title = _(u'Sample Scan') |
---|
92 | mus = 1024 * 200 |
---|
93 | download_name = u'sample' |
---|
94 | download_filename = download_name |
---|
95 | tab_redirect = '#tab2' |
---|
96 | |
---|
97 | |
---|
98 | class SampleScanEditUpload(SampleScanManageUpload): |
---|
99 | """Scan upload viewlet for customer. |
---|
100 | |
---|
101 | If a user has both permissions, waeup.manageCustomer and |
---|
102 | waeup.handleCustomer, the upload viewlet appears twice. |
---|
103 | """ |
---|
104 | grok.view(DocumentEditFormPage) |
---|
105 | grok.require('waeup.handleCustomer') |
---|
106 | |
---|
107 | |
---|
108 | class SampleScanDisplay(FileDisplay): |
---|
109 | """Scan display viewlet. |
---|
110 | """ |
---|
111 | grok.order(1) |
---|
112 | grok.context(CustomerSampleDocument) |
---|
113 | grok.require('waeup.viewCustomer') |
---|
114 | grok.view(DocumentDisplayFormPage) |
---|
115 | label = _(u'Sample Scan') |
---|
116 | title = _(u'Sample Scan') |
---|
117 | download_name = u'sample' |
---|
118 | download_filename = download_name |
---|
119 | |
---|
120 | |
---|
121 | class SampleScanImage(Image): |
---|
122 | """Scan document. |
---|
123 | """ |
---|
124 | |
---|
125 | grok.name('sample') |
---|
126 | grok.context(CustomerSampleDocument) |
---|
127 | grok.require('waeup.viewCustomer') |
---|
128 | download_name = u'sample' |
---|
129 | download_filename = download_name |
---|
130 | |
---|
131 | |
---|
132 | class SampleScanPDFSlip(SampleScanDisplay): |
---|
133 | grok.view(PDFDocumentSlip) |
---|
134 | |
---|
135 | |
---|
136 | class PDFScanManageUpload(FileUpload): |
---|
137 | """Scan upload viewlet for officers. |
---|
138 | """ |
---|
139 | grok.view(DocumentManageFormPage) |
---|
140 | grok.context(CustomerPDFDocument) |
---|
141 | grok.require('waeup.manageCustomer') |
---|
142 | label = _(u'PDF File') |
---|
143 | title = _(u'PDF File') |
---|
144 | mus = 1024 * 1000 |
---|
145 | download_name = u'sample.pdf' |
---|
146 | tab_redirect = '#tab2' |
---|
147 | |
---|
148 | @property |
---|
149 | def download_filename(self): |
---|
150 | return u"%s.pdf" % self.context.document_id[:9] |
---|
151 | |
---|
152 | |
---|
153 | class PDFScanEditUpload(PDFScanManageUpload): |
---|
154 | """Scan upload viewlet for customer. |
---|
155 | """ |
---|
156 | grok.view(DocumentEditFormPage) |
---|
157 | grok.require('waeup.handleCustomer') |
---|
158 | |
---|
159 | |
---|
160 | class PDFScanDisplay(FileDisplay): |
---|
161 | """Scan display viewlet. |
---|
162 | """ |
---|
163 | grok.order(1) |
---|
164 | grok.context(CustomerPDFDocument) |
---|
165 | grok.require('waeup.viewCustomer') |
---|
166 | grok.view(DocumentDisplayFormPage) |
---|
167 | label = _(u'PDF Scan') |
---|
168 | title = _(u'PDF Scan') |
---|
169 | download_name = u'sample.pdf' |
---|
170 | |
---|
171 | @property |
---|
172 | def download_filename(self): |
---|
173 | return u"%s.pdf" % self.context.document_id[:9] |
---|
174 | |
---|
175 | |
---|
176 | class PDFScanImage(Image): |
---|
177 | """Scan document. |
---|
178 | """ |
---|
179 | grok.name('sample.pdf') |
---|
180 | grok.context(CustomerPDFDocument) |
---|
181 | grok.require('waeup.viewCustomer') |
---|
182 | download_name = u'sample.pdf' |
---|
183 | |
---|
184 | @property |
---|
185 | def download_filename(self): |
---|
186 | return u"%s" % self.context.document_id[:9] |
---|
187 | |
---|
188 | |
---|
189 | class PDFScanSlip(PDFScanDisplay): |
---|
190 | grok.view(PDFDocumentSlip) |
---|