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

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

Validate document and contract ids properly.

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