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

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

Add interface and page for editing official use data. Adjust exporter.

  • Property svn:keywords set to Id
File size: 10.0 KB
Line 
1## $Id: interfaces.py 12500 2015-01-20 17:31:11Z 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, GenderSource, nats_vocab,
33    ConCatProductSource, CustomerDocumentSource,
34    ProductOptionSourceFactory)
35
36
37class ICustomersUtils(Interface):
38    """A collection of methods which are subject to customization.
39
40    """
41
42
43class 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
55class 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
67class 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
154class 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
164class 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
181class 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
204class 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
234class ICustomerDocumentsContainer(IDocumentsContainer):
235    """A container for customer document objects.
236
237    """
238
239
240class 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
255class ICustomerSampleDocument(ICustomerDocument):
256    """A customer sample document object.
257
258    """
259
260
261class ICustomerPDFDocument(ICustomerDocument):
262    """A customer pdf document object.
263
264    """
265
266# Customer contract interfaces
267
268class IContractsContainer(IIkobaObject):
269    """A container for customer aplication objects.
270
271    """
272
273    def addContract(contract):
274        """Add an contract object.
275        """
276
277
278class 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
323class IContractSelectProduct(Interface):
324    """Interface for for the ContractSelectProductPage.
325
326    """
327
328    product_object = schema.Choice(
329        title = _(u'Product'),
330        source = ConCatProductSource(),
331        required = True,
332        )
333
334
335class ISampleContract(IContract):
336    """A customer contract sample with document attached.
337
338    """
339
340    document_object = schema.Choice(
341        title = _(u'Document'),
342        source = CustomerDocumentSource(),
343        required = False,
344        )
345
346
347class ISampleContractOfficialUse(IIkobaObject):
348    """Interface for official use only.
349    """
350
351    comment = schema.Text(
352        title = _(u'Comment'),
353        required = False,
354        )
355
356
357class ISampleContractProcess(ISampleContract, ISampleContractOfficialUse):
358    """Interface for processing contract data.
359    """
360
361    product_options = schema.List(
362        title = _(u'Options/Fees'),
363        value_type = ProductOptionField(),
364        required = False,
365        readonly = False,
366        default = [],
367        )
368
369
370class ISampleContractEdit(ISampleContract):
371    """Interface for editing sample contract data by customers.
372
373    """
374
375    document_object = schema.Choice(
376        title = _(u'Document'),
377        source = CustomerDocumentSource(),
378        required = True,
379        )
Note: See TracBrowser for help on using the repository browser.