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

Last change on this file since 12537 was 12537, checked in by Henrik Bettermann, 10 years ago

Email address must be required.

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