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

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

pep8

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