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