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

Last change on this file since 12276 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
RevLine 
[12018]1## $Id: interfaces.py 12260 2014-12-19 08:11:12Z henrik $
[11956]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 _
[11958]24from waeup.ikoba.interfaces import (
[12260]25    IIkobaObject, validate_email, ICSVExporter, validate_uuid)
[11956]26from waeup.ikoba.schema import TextLineChoice, FormattedDate, PhoneNumber
[11958]27from waeup.ikoba.browser.interfaces import ICustomerNavigationBase
[11989]28from waeup.ikoba.documents.interfaces import IDocumentsContainer, IDocument
[11956]29
[11958]30from waeup.ikoba.customers.vocabularies import (
[12103]31    contextual_reg_num_source, GenderSource, nats_vocab,
32    ConCatProductSource, CustomerDocumentSource)
[11958]33
[11985]34
[11956]35class ICustomersUtils(Interface):
36    """A collection of methods which are subject to customization.
37
38    """
39
[11985]40
[11956]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
[11958]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
[11985]64
[11956]65class ICustomer(IIkobaObject):
66    """Representation of a customer.
67
68    """
69
[11958]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(
[11996]93        title = _(u'Customer Id'),
[11958]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        )
[12260]130
[11958]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
[11985]151
[11958]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
[11985]161
[11958]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
[11967]170    def export_customer(customer, filepath=None):
[11958]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
[11985]178
[12039]179class ICustomerRequestPW(IIkobaObject):
180    """Representation of a customer for first-time password request.
[11967]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        )
[11989]200
201
[12039]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
[11989]230# Customer document interfaces
231
232class ICustomerDocumentsContainer(IDocumentsContainer):
233    """A container for customer document objects.
234
235    """
236
237
238class ICustomerDocument(IDocument):
[12089]239    """A customer document object.
[11989]240
241    """
242
[12166]243    is_editable_by_customer = Attribute('Document editable by customer')
244    is_editable_by_manager = Attribute('Document editable by manager')
[12053]245
[12260]246    document_id = schema.TextLine(
247        title = _(u'Document Id'),
248        required = False,
249        constraint=validate_uuid,
250        )
[12053]251
[12260]252
253class ICustomerPDFDocument(ICustomerDocument):
[12053]254    """A customer document.
255
[12089]256    """
257
[12097]258# Customer contract interfaces
[12089]259
[12097]260class IContractsContainer(IIkobaObject):
[12089]261    """A container for customer aplication objects.
262
263    """
264
[12097]265    def addContract(contract):
266        """Add an contract object.
[12089]267        """
268
269
[12097]270class IContract(IIkobaObject):
271    """A customer contract.
[12089]272
273    """
274    history = Attribute('Object history, a list of messages')
[12097]275    state = Attribute('Returns the contract state')
[12089]276    translated_state = Attribute(
277        'Returns a translated, more verbose appliction state')
[12097]278    class_name = Attribute('Name of the contract class')
[12092]279    formatted_transition_date = Attribute(
280        'Last transition formatted date string')
[12097]281    contract_category = Attribute('Category for the grouping of products')
[12094]282    last_product_id = Attribute(
[12097]283        'Id of product recently stored with the contract')
[12167]284    is_editable_by_customer = Attribute('Contract editable by customer')
[12144]285    is_approvable = Attribute('Contract approvable by officer')
[12143]286    translated_class_name = Attribute('Translatable class name')
[12089]287
[12258]288    contract_id = schema.TextLine(
289        title = _(u'Contract Id'),
290        required = False,
[12260]291        constraint=validate_uuid,
[12258]292        )
293
[12089]294    title = schema.TextLine(
[12097]295        title = _(u'Contract Title'),
[12089]296        required = True,
297        )
298
[12119]299    product_object = schema.Choice(
[12092]300        title = _(u'Product'),
[12098]301        source = ConCatProductSource(),
[12095]302        required = False,
303        )
304
[12103]305
[12097]306class IContractEdit(IContract):
307    """Interface for editing contract data by customers.
[12095]308
309    """
310
[12119]311    product_object = schema.Choice(
[12095]312        title = _(u'Product'),
[12098]313        source = ConCatProductSource(),
[12094]314        required = True,
[12103]315        )
316
317
318class ISampleContract(IContract):
319    """A customer contract sample with document attached.
320
321    """
322
[12119]323    document_object = schema.Choice(
[12103]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
[12119]335    product_object = schema.Choice(
[12103]336        title = _(u'Product'),
337        source = ConCatProductSource(),
338        required = True,
339        )
340
[12119]341    document_object = schema.Choice(
[12103]342        title = _(u'Document'),
343        source = CustomerDocumentSource(),
344        required = True,
[12095]345        )
Note: See TracBrowser for help on using the repository browser.