source: main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py @ 14292

Last change on this file since 14292 was 14022, checked in by Henrik Bettermann, 8 years ago

Use defaultFactory.

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