1 | ## $Id: interfaces.py 12363 2015-01-02 07:50:34Z 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 | #from datetime import datetime |
---|
19 | from zope.component import getUtility |
---|
20 | from zope.interface import Attribute, Interface |
---|
21 | from zope import schema |
---|
22 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
23 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
24 | from waeup.ikoba.interfaces import ( |
---|
25 | IIkobaObject, validate_email, ICSVExporter, validate_uuid) |
---|
26 | from waeup.ikoba.schema import TextLineChoice, FormattedDate, PhoneNumber |
---|
27 | from waeup.ikoba.browser.interfaces import ICustomerNavigationBase |
---|
28 | from waeup.ikoba.documents.interfaces import IDocumentsContainer, IDocument |
---|
29 | from waeup.ikoba.products.productoptions import ProductOptionField |
---|
30 | |
---|
31 | from waeup.ikoba.customers.vocabularies import ( |
---|
32 | contextual_reg_num_source, GenderSource, nats_vocab, |
---|
33 | ConCatProductSource, CustomerDocumentSource, |
---|
34 | ProductOptionSourceFactory) |
---|
35 | |
---|
36 | |
---|
37 | class ICustomersUtils(Interface): |
---|
38 | """A collection of methods which are subject to customization. |
---|
39 | |
---|
40 | """ |
---|
41 | |
---|
42 | |
---|
43 | class ICustomersContainer(IIkobaObject): |
---|
44 | """A customers container contains company customers. |
---|
45 | |
---|
46 | """ |
---|
47 | def addCustomer(customer): |
---|
48 | """Add an ICustomer object and subcontainers. |
---|
49 | |
---|
50 | """ |
---|
51 | |
---|
52 | unique_customer_id = Attribute("""A unique customer id.""") |
---|
53 | |
---|
54 | |
---|
55 | class ICustomerNavigation(ICustomerNavigationBase): |
---|
56 | """Interface needed for custom navigation, logging, etc. |
---|
57 | |
---|
58 | """ |
---|
59 | customer = Attribute('Customer object of context.') |
---|
60 | |
---|
61 | def writeLogMessage(view, message): |
---|
62 | """Write a view specific log message into custom.log. |
---|
63 | |
---|
64 | """ |
---|
65 | |
---|
66 | |
---|
67 | class ICustomer(IIkobaObject): |
---|
68 | """Representation of a customer. |
---|
69 | |
---|
70 | """ |
---|
71 | |
---|
72 | history = Attribute('Object history, a list of messages') |
---|
73 | state = Attribute('Returns the registration state of a customer') |
---|
74 | password = Attribute('Encrypted password of a customer') |
---|
75 | temp_password = Attribute( |
---|
76 | 'Dictionary with user name, timestamp and encrypted password') |
---|
77 | fullname = Attribute('All name parts separated by hyphens') |
---|
78 | display_fullname = Attribute('The fullname of an applicant') |
---|
79 | |
---|
80 | suspended = schema.Bool( |
---|
81 | title = _(u'Account suspended'), |
---|
82 | default = False, |
---|
83 | required = False, |
---|
84 | ) |
---|
85 | |
---|
86 | suspended_comment = schema.Text( |
---|
87 | title = _(u"Reasons for Deactivation"), |
---|
88 | required = False, |
---|
89 | description = _( |
---|
90 | u'This message will be shown if and only if deactivated ' |
---|
91 | 'customers try to login.'), |
---|
92 | ) |
---|
93 | |
---|
94 | customer_id = schema.TextLine( |
---|
95 | title = _(u'Customer Id'), |
---|
96 | required = False, |
---|
97 | ) |
---|
98 | |
---|
99 | firstname = schema.TextLine( |
---|
100 | title = _(u'First Name'), |
---|
101 | required = True, |
---|
102 | ) |
---|
103 | |
---|
104 | middlename = schema.TextLine( |
---|
105 | title = _(u'Middle Name'), |
---|
106 | required = False, |
---|
107 | ) |
---|
108 | |
---|
109 | lastname = schema.TextLine( |
---|
110 | title = _(u'Last Name (Surname)'), |
---|
111 | required = True, |
---|
112 | ) |
---|
113 | |
---|
114 | sex = schema.Choice( |
---|
115 | title = _(u'Sex'), |
---|
116 | source = GenderSource(), |
---|
117 | required = True, |
---|
118 | ) |
---|
119 | |
---|
120 | reg_number = TextLineChoice( |
---|
121 | title = _(u'Registration Number'), |
---|
122 | required = True, |
---|
123 | readonly = False, |
---|
124 | source = contextual_reg_num_source, |
---|
125 | ) |
---|
126 | |
---|
127 | email = schema.ASCIILine( |
---|
128 | title = _(u'Email'), |
---|
129 | required = False, |
---|
130 | constraint=validate_email, |
---|
131 | ) |
---|
132 | |
---|
133 | phone = PhoneNumber( |
---|
134 | title = _(u'Phone'), |
---|
135 | description = u'', |
---|
136 | required = False, |
---|
137 | ) |
---|
138 | |
---|
139 | def setTempPassword(user, password): |
---|
140 | """Set a temporary password (LDAP-compatible) SSHA encoded for |
---|
141 | officers. |
---|
142 | |
---|
143 | """ |
---|
144 | |
---|
145 | def getTempPassword(): |
---|
146 | """Check if a temporary password has been set and if it |
---|
147 | is not expired. |
---|
148 | |
---|
149 | Return the temporary password if valid, |
---|
150 | None otherwise. Unset the temporary password if expired. |
---|
151 | """ |
---|
152 | |
---|
153 | |
---|
154 | class ICustomerUpdateByRegNo(ICustomer): |
---|
155 | """Representation of a customer. Skip regular reg_number validation. |
---|
156 | |
---|
157 | """ |
---|
158 | reg_number = schema.TextLine( |
---|
159 | title = _(u'Registration Number'), |
---|
160 | required = False, |
---|
161 | ) |
---|
162 | |
---|
163 | |
---|
164 | class ICSVCustomerExporter(ICSVExporter): |
---|
165 | """A regular ICSVExporter that additionally supports exporting |
---|
166 | data from a given customer object. |
---|
167 | """ |
---|
168 | def get_filtered(site, **kw): |
---|
169 | """Get a filtered set of customer. |
---|
170 | """ |
---|
171 | |
---|
172 | def export_customer(customer, filepath=None): |
---|
173 | """Export data for a given customer. |
---|
174 | """ |
---|
175 | |
---|
176 | def export_filtered(site, filepath=None, **kw): |
---|
177 | """Export filtered set of customers. |
---|
178 | """ |
---|
179 | |
---|
180 | |
---|
181 | class ICustomerRequestPW(IIkobaObject): |
---|
182 | """Representation of a customer for first-time password request. |
---|
183 | |
---|
184 | This interface is used when customers use the requestpw page to |
---|
185 | login for the the first time. |
---|
186 | """ |
---|
187 | number = schema.TextLine( |
---|
188 | title = _(u'Registration Number'), |
---|
189 | required = True, |
---|
190 | ) |
---|
191 | |
---|
192 | firstname = schema.TextLine( |
---|
193 | title = _(u'First Name'), |
---|
194 | required = True, |
---|
195 | ) |
---|
196 | |
---|
197 | email = schema.ASCIILine( |
---|
198 | title = _(u'Email Address'), |
---|
199 | required = True, |
---|
200 | constraint=validate_email, |
---|
201 | ) |
---|
202 | |
---|
203 | |
---|
204 | class ICustomerCreate(IIkobaObject): |
---|
205 | """Representation of an customer for account creation. |
---|
206 | |
---|
207 | This interface is used when customers use the createaccount page. |
---|
208 | """ |
---|
209 | |
---|
210 | firstname = schema.TextLine( |
---|
211 | title = _(u'First Name'), |
---|
212 | required = True, |
---|
213 | ) |
---|
214 | |
---|
215 | middlename = schema.TextLine( |
---|
216 | title = _(u'Middle Name'), |
---|
217 | required = False, |
---|
218 | ) |
---|
219 | |
---|
220 | lastname = schema.TextLine( |
---|
221 | title = _(u'Last Name (Surname)'), |
---|
222 | required = True, |
---|
223 | ) |
---|
224 | |
---|
225 | email = schema.ASCIILine( |
---|
226 | title = _(u'Email Address'), |
---|
227 | required = True, |
---|
228 | constraint=validate_email, |
---|
229 | ) |
---|
230 | |
---|
231 | |
---|
232 | # Customer document interfaces |
---|
233 | |
---|
234 | class ICustomerDocumentsContainer(IDocumentsContainer): |
---|
235 | """A container for customer document objects. |
---|
236 | |
---|
237 | """ |
---|
238 | |
---|
239 | |
---|
240 | class ICustomerDocument(IDocument): |
---|
241 | """A customer document object. |
---|
242 | |
---|
243 | """ |
---|
244 | |
---|
245 | is_editable_by_customer = Attribute('Document editable by customer') |
---|
246 | is_editable_by_manager = Attribute('Document editable by manager') |
---|
247 | |
---|
248 | document_id = schema.TextLine( |
---|
249 | title = _(u'Document Id'), |
---|
250 | required = False, |
---|
251 | constraint=validate_uuid, |
---|
252 | ) |
---|
253 | |
---|
254 | |
---|
255 | class ICustomerSampleDocument(ICustomerDocument): |
---|
256 | """A customer sample document object. |
---|
257 | |
---|
258 | """ |
---|
259 | |
---|
260 | |
---|
261 | class ICustomerPDFDocument(ICustomerDocument): |
---|
262 | """A customer pdf document object. |
---|
263 | |
---|
264 | """ |
---|
265 | |
---|
266 | # Customer contract interfaces |
---|
267 | |
---|
268 | class IContractsContainer(IIkobaObject): |
---|
269 | """A container for customer aplication objects. |
---|
270 | |
---|
271 | """ |
---|
272 | |
---|
273 | def addContract(contract): |
---|
274 | """Add an contract object. |
---|
275 | """ |
---|
276 | |
---|
277 | |
---|
278 | class IContract(IIkobaObject): |
---|
279 | """A customer contract. |
---|
280 | |
---|
281 | """ |
---|
282 | history = Attribute('Object history, a list of messages') |
---|
283 | state = Attribute('Returns the contract state') |
---|
284 | translated_state = Attribute( |
---|
285 | 'Returns a translated, more verbose appliction state') |
---|
286 | class_name = Attribute('Name of the contract class') |
---|
287 | formatted_transition_date = Attribute( |
---|
288 | 'Last transition formatted date string') |
---|
289 | contract_category = Attribute('Category for the grouping of products') |
---|
290 | last_product_id = Attribute( |
---|
291 | 'Id of product recently stored with the contract') |
---|
292 | is_editable = Attribute('Contract editable by customer and manager') |
---|
293 | is_approvable = Attribute('Contract approvable by officer') |
---|
294 | translated_class_name = Attribute('Translatable class name') |
---|
295 | user_id = Attribute('Id of a user, actually the id of the customer') |
---|
296 | title = Attribute('Title generated by the associated product') |
---|
297 | tc_dict = Attribute('Multilingual "Terms and Conditions" dict') |
---|
298 | |
---|
299 | contract_id = schema.TextLine( |
---|
300 | title = _(u'Contract Id'), |
---|
301 | required = False, |
---|
302 | constraint=validate_uuid, |
---|
303 | ) |
---|
304 | |
---|
305 | product_object = schema.Choice( |
---|
306 | title = _(u'Product'), |
---|
307 | source = ConCatProductSource(), |
---|
308 | required = False, |
---|
309 | ) |
---|
310 | |
---|
311 | product_options = schema.List( |
---|
312 | title = _(u'Options/Fees'), |
---|
313 | value_type = schema.Choice( |
---|
314 | source=ProductOptionSourceFactory(), |
---|
315 | required = True, |
---|
316 | ), |
---|
317 | required = False, |
---|
318 | readonly = False, |
---|
319 | default = [], |
---|
320 | ) |
---|
321 | |
---|
322 | |
---|
323 | class IContractProcess(IContract): |
---|
324 | """Interface for processing contract data. |
---|
325 | """ |
---|
326 | |
---|
327 | product_options = schema.List( |
---|
328 | title = _(u'Options/Fees'), |
---|
329 | value_type = ProductOptionField(), |
---|
330 | required = False, |
---|
331 | readonly = False, |
---|
332 | default = [], |
---|
333 | ) |
---|
334 | |
---|
335 | |
---|
336 | class IContractEdit(IContract): |
---|
337 | """Interface for editing contract data by customers. |
---|
338 | |
---|
339 | """ |
---|
340 | |
---|
341 | product_object = schema.Choice( |
---|
342 | title = _(u'Product'), |
---|
343 | source = ConCatProductSource(), |
---|
344 | required = True, |
---|
345 | ) |
---|
346 | |
---|
347 | |
---|
348 | class ISampleContract(IContract): |
---|
349 | """A customer contract sample with document attached. |
---|
350 | |
---|
351 | """ |
---|
352 | |
---|
353 | document_object = schema.Choice( |
---|
354 | title = _(u'Document'), |
---|
355 | source = CustomerDocumentSource(), |
---|
356 | required = False, |
---|
357 | ) |
---|
358 | |
---|
359 | |
---|
360 | class ISampleContractProcess(ISampleContract): |
---|
361 | """Interface for processing contract data. |
---|
362 | """ |
---|
363 | |
---|
364 | product_options = schema.List( |
---|
365 | title = _(u'Options/Fees'), |
---|
366 | value_type = ProductOptionField(), |
---|
367 | required = False, |
---|
368 | readonly = False, |
---|
369 | default = [], |
---|
370 | ) |
---|
371 | |
---|
372 | |
---|
373 | class ISampleContractEdit(ISampleContract): |
---|
374 | """Interface for editing sample contract data by customers. |
---|
375 | |
---|
376 | """ |
---|
377 | |
---|
378 | product_object = schema.Choice( |
---|
379 | title = _(u'Product'), |
---|
380 | source = ConCatProductSource(), |
---|
381 | required = True, |
---|
382 | ) |
---|
383 | |
---|
384 | document_object = schema.Choice( |
---|
385 | title = _(u'Document'), |
---|
386 | source = CustomerDocumentSource(), |
---|
387 | required = True, |
---|
388 | ) |
---|