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

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

Add browser components for customers. Tests will follow.

File size: 6.4 KB
Line 
1## $Id: interfaces.py 11589 2014-04-22 07:13:16Z 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, application_sessions_vocab, validate_email, ICSVExporter)
26from waeup.ikoba.schema import TextLineChoice, FormattedDate, PhoneNumber
27from waeup.ikoba.browser.interfaces import ICustomerNavigationBase
28
29from waeup.ikoba.customers.vocabularies import (
30    contextual_reg_num_source, GenderSource, nats_vocab)
31
32class ICustomersUtils(Interface):
33    """A collection of methods which are subject to customization.
34
35    """
36
37class ICustomersContainer(IIkobaObject):
38    """A customers container contains company customers.
39
40    """
41    def addCustomer(customer):
42        """Add an ICustomer object and subcontainers.
43
44        """
45
46    def archive(id=None):
47        """Create on-dist archive of customers.
48
49        If id is `None`, all customers are archived.
50
51        If id contains a single id string, only the respective
52        customers are archived.
53
54        If id contains a list of id strings all of the respective
55        customers types are saved to disk.
56        """
57
58    def clear(id=None, archive=True):
59        """Remove customers of type given by 'id'.
60
61        Optionally archive the customers.
62
63        If id is `None`, all customers are archived.
64
65        If id contains a single id string, only the respective
66        customers are archived.
67
68        If id contains a list of id strings all of the respective
69        customer types are saved to disk.
70
71        If `archive` is ``False`` none of the archive-handling is done
72        and respective customers are simply removed from the
73        database.
74        """
75
76    unique_customer_id = Attribute("""A unique customer id.""")
77
78
79class ICustomerNavigation(ICustomerNavigationBase):
80    """Interface needed for custom navigation, logging, etc.
81
82    """
83    customer = Attribute('Customer object of context.')
84
85    def writeLogMessage(view, message):
86        """Write a view specific log message into custom.log.
87
88        """
89
90class ICustomer(IIkobaObject):
91    """Representation of a customer.
92
93    """
94
95    history = Attribute('Object history, a list of messages')
96    state = Attribute('Returns the registration state of a customer')
97    password = Attribute('Encrypted password of a customer')
98    temp_password = Attribute(
99        'Dictionary with user name, timestamp and encrypted password')
100    fullname = Attribute('All name parts separated by hyphens')
101    display_fullname = Attribute('The fullname of an applicant')
102
103    suspended = schema.Bool(
104        title = _(u'Account suspended'),
105        default = False,
106        required = False,
107        )
108
109    suspended_comment = schema.Text(
110        title = _(u"Reasons for Deactivation"),
111        required = False,
112        description = _(
113            u'This message will be shown if and only if deactivated '
114            'customers try to login.'),
115        )
116
117    customer_id = schema.TextLine(
118        title = _(u'Student Id'),
119        required = False,
120        )
121
122    firstname = schema.TextLine(
123        title = _(u'First Name'),
124        required = True,
125        )
126
127    middlename = schema.TextLine(
128        title = _(u'Middle Name'),
129        required = False,
130        )
131
132    lastname = schema.TextLine(
133        title = _(u'Last Name (Surname)'),
134        required = True,
135        )
136
137    sex = schema.Choice(
138        title = _(u'Sex'),
139        source = GenderSource(),
140        required = True,
141        )
142
143    reg_number = TextLineChoice(
144        title = _(u'Registration Number'),
145        required = True,
146        readonly = False,
147        source = contextual_reg_num_source,
148        )
149
150    email = schema.ASCIILine(
151        title = _(u'Email'),
152        required = False,
153        constraint=validate_email,
154        )
155    phone = PhoneNumber(
156        title = _(u'Phone'),
157        description = u'',
158        required = False,
159        )
160
161    def setTempPassword(user, password):
162        """Set a temporary password (LDAP-compatible) SSHA encoded for
163        officers.
164
165        """
166
167    def getTempPassword():
168        """Check if a temporary password has been set and if it
169        is not expired.
170
171        Return the temporary password if valid,
172        None otherwise. Unset the temporary password if expired.
173        """
174
175class ICustomerUpdateByRegNo(ICustomer):
176    """Representation of a customer. Skip regular reg_number validation.
177
178    """
179    reg_number = schema.TextLine(
180        title = _(u'Registration Number'),
181        required = False,
182        )
183
184class ICSVCustomerExporter(ICSVExporter):
185    """A regular ICSVExporter that additionally supports exporting
186      data from a given customer object.
187    """
188    def get_filtered(site, **kw):
189        """Get a filtered set of customer.
190        """
191
192    def export_customer(customer, filepath=None):
193        """Export data for a given customer.
194        """
195
196    def export_filtered(site, filepath=None, **kw):
197        """Export filtered set of customers.
198        """
199
200class ICustomerRequestPW(ICustomer):
201    """Representation of an customer for first-time password request.
202
203    This interface is used when customers use the requestpw page to
204    login for the the first time.
205    """
206    number = schema.TextLine(
207        title = _(u'Registration Number'),
208        required = True,
209        )
210
211    firstname = schema.TextLine(
212        title = _(u'First Name'),
213        required = True,
214        )
215
216    email = schema.ASCIILine(
217        title = _(u'Email Address'),
218        required = True,
219        constraint=validate_email,
220        )
221
Note: See TracBrowser for help on using the repository browser.