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