[12018] | 1 | ## $Id: interfaces.py 12092 2014-11-29 17:37:58Z 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 |
---|
| 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 _ |
---|
[11958] | 24 | from waeup.ikoba.interfaces import ( |
---|
| 25 | IIkobaObject, application_sessions_vocab, validate_email, ICSVExporter) |
---|
[11956] | 26 | from waeup.ikoba.schema import TextLineChoice, FormattedDate, PhoneNumber |
---|
[11958] | 27 | from waeup.ikoba.browser.interfaces import ICustomerNavigationBase |
---|
[11989] | 28 | from waeup.ikoba.documents.interfaces import IDocumentsContainer, IDocument |
---|
[11956] | 29 | |
---|
[11958] | 30 | from waeup.ikoba.customers.vocabularies import ( |
---|
[12092] | 31 | contextual_reg_num_source, GenderSource, nats_vocab, AppCatProductSource) |
---|
[11958] | 32 | |
---|
[11985] | 33 | |
---|
[11956] | 34 | class ICustomersUtils(Interface): |
---|
| 35 | """A collection of methods which are subject to customization. |
---|
| 36 | |
---|
| 37 | """ |
---|
| 38 | |
---|
[11985] | 39 | |
---|
[11956] | 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 | unique_customer_id = Attribute("""A unique customer id.""") |
---|
| 50 | |
---|
[11958] | 51 | |
---|
| 52 | class ICustomerNavigation(ICustomerNavigationBase): |
---|
| 53 | """Interface needed for custom navigation, logging, etc. |
---|
| 54 | |
---|
| 55 | """ |
---|
| 56 | customer = Attribute('Customer object of context.') |
---|
| 57 | |
---|
| 58 | def writeLogMessage(view, message): |
---|
| 59 | """Write a view specific log message into custom.log. |
---|
| 60 | |
---|
| 61 | """ |
---|
| 62 | |
---|
[11985] | 63 | |
---|
[11956] | 64 | class ICustomer(IIkobaObject): |
---|
| 65 | """Representation of a customer. |
---|
| 66 | |
---|
| 67 | """ |
---|
| 68 | |
---|
[11958] | 69 | history = Attribute('Object history, a list of messages') |
---|
| 70 | state = Attribute('Returns the registration state of a customer') |
---|
| 71 | password = Attribute('Encrypted password of a customer') |
---|
| 72 | temp_password = Attribute( |
---|
| 73 | 'Dictionary with user name, timestamp and encrypted password') |
---|
| 74 | fullname = Attribute('All name parts separated by hyphens') |
---|
| 75 | display_fullname = Attribute('The fullname of an applicant') |
---|
| 76 | |
---|
| 77 | suspended = schema.Bool( |
---|
| 78 | title = _(u'Account suspended'), |
---|
| 79 | default = False, |
---|
| 80 | required = False, |
---|
| 81 | ) |
---|
| 82 | |
---|
| 83 | suspended_comment = schema.Text( |
---|
| 84 | title = _(u"Reasons for Deactivation"), |
---|
| 85 | required = False, |
---|
| 86 | description = _( |
---|
| 87 | u'This message will be shown if and only if deactivated ' |
---|
| 88 | 'customers try to login.'), |
---|
| 89 | ) |
---|
| 90 | |
---|
| 91 | customer_id = schema.TextLine( |
---|
[11996] | 92 | title = _(u'Customer Id'), |
---|
[11958] | 93 | required = False, |
---|
| 94 | ) |
---|
| 95 | |
---|
| 96 | firstname = schema.TextLine( |
---|
| 97 | title = _(u'First Name'), |
---|
| 98 | required = True, |
---|
| 99 | ) |
---|
| 100 | |
---|
| 101 | middlename = schema.TextLine( |
---|
| 102 | title = _(u'Middle Name'), |
---|
| 103 | required = False, |
---|
| 104 | ) |
---|
| 105 | |
---|
| 106 | lastname = schema.TextLine( |
---|
| 107 | title = _(u'Last Name (Surname)'), |
---|
| 108 | required = True, |
---|
| 109 | ) |
---|
| 110 | |
---|
| 111 | sex = schema.Choice( |
---|
| 112 | title = _(u'Sex'), |
---|
| 113 | source = GenderSource(), |
---|
| 114 | required = True, |
---|
| 115 | ) |
---|
| 116 | |
---|
| 117 | reg_number = TextLineChoice( |
---|
| 118 | title = _(u'Registration Number'), |
---|
| 119 | required = True, |
---|
| 120 | readonly = False, |
---|
| 121 | source = contextual_reg_num_source, |
---|
| 122 | ) |
---|
| 123 | |
---|
| 124 | email = schema.ASCIILine( |
---|
| 125 | title = _(u'Email'), |
---|
| 126 | required = False, |
---|
| 127 | constraint=validate_email, |
---|
| 128 | ) |
---|
| 129 | phone = PhoneNumber( |
---|
| 130 | title = _(u'Phone'), |
---|
| 131 | description = u'', |
---|
| 132 | required = False, |
---|
| 133 | ) |
---|
| 134 | |
---|
| 135 | def setTempPassword(user, password): |
---|
| 136 | """Set a temporary password (LDAP-compatible) SSHA encoded for |
---|
| 137 | officers. |
---|
| 138 | |
---|
| 139 | """ |
---|
| 140 | |
---|
| 141 | def getTempPassword(): |
---|
| 142 | """Check if a temporary password has been set and if it |
---|
| 143 | is not expired. |
---|
| 144 | |
---|
| 145 | Return the temporary password if valid, |
---|
| 146 | None otherwise. Unset the temporary password if expired. |
---|
| 147 | """ |
---|
| 148 | |
---|
[11985] | 149 | |
---|
[11958] | 150 | class ICustomerUpdateByRegNo(ICustomer): |
---|
| 151 | """Representation of a customer. Skip regular reg_number validation. |
---|
| 152 | |
---|
| 153 | """ |
---|
| 154 | reg_number = schema.TextLine( |
---|
| 155 | title = _(u'Registration Number'), |
---|
| 156 | required = False, |
---|
| 157 | ) |
---|
| 158 | |
---|
[11985] | 159 | |
---|
[11958] | 160 | class ICSVCustomerExporter(ICSVExporter): |
---|
| 161 | """A regular ICSVExporter that additionally supports exporting |
---|
| 162 | data from a given customer object. |
---|
| 163 | """ |
---|
| 164 | def get_filtered(site, **kw): |
---|
| 165 | """Get a filtered set of customer. |
---|
| 166 | """ |
---|
| 167 | |
---|
[11967] | 168 | def export_customer(customer, filepath=None): |
---|
[11958] | 169 | """Export data for a given customer. |
---|
| 170 | """ |
---|
| 171 | |
---|
| 172 | def export_filtered(site, filepath=None, **kw): |
---|
| 173 | """Export filtered set of customers. |
---|
| 174 | """ |
---|
| 175 | |
---|
[11985] | 176 | |
---|
[12039] | 177 | class ICustomerRequestPW(IIkobaObject): |
---|
| 178 | """Representation of a customer for first-time password request. |
---|
[11967] | 179 | |
---|
| 180 | This interface is used when customers use the requestpw page to |
---|
| 181 | login for the the first time. |
---|
| 182 | """ |
---|
| 183 | number = schema.TextLine( |
---|
| 184 | title = _(u'Registration Number'), |
---|
| 185 | required = True, |
---|
| 186 | ) |
---|
| 187 | |
---|
| 188 | firstname = schema.TextLine( |
---|
| 189 | title = _(u'First Name'), |
---|
| 190 | required = True, |
---|
| 191 | ) |
---|
| 192 | |
---|
| 193 | email = schema.ASCIILine( |
---|
| 194 | title = _(u'Email Address'), |
---|
| 195 | required = True, |
---|
| 196 | constraint=validate_email, |
---|
| 197 | ) |
---|
[11989] | 198 | |
---|
| 199 | |
---|
[12039] | 200 | class ICustomerCreate(IIkobaObject): |
---|
| 201 | """Representation of an customer for account creation. |
---|
| 202 | |
---|
| 203 | This interface is used when customers use the createaccount page. |
---|
| 204 | """ |
---|
| 205 | |
---|
| 206 | firstname = schema.TextLine( |
---|
| 207 | title = _(u'First Name'), |
---|
| 208 | required = True, |
---|
| 209 | ) |
---|
| 210 | |
---|
| 211 | middlename = schema.TextLine( |
---|
| 212 | title = _(u'Middle Name'), |
---|
| 213 | required = False, |
---|
| 214 | ) |
---|
| 215 | |
---|
| 216 | lastname = schema.TextLine( |
---|
| 217 | title = _(u'Last Name (Surname)'), |
---|
| 218 | required = True, |
---|
| 219 | ) |
---|
| 220 | |
---|
| 221 | email = schema.ASCIILine( |
---|
| 222 | title = _(u'Email Address'), |
---|
| 223 | required = True, |
---|
| 224 | constraint=validate_email, |
---|
| 225 | ) |
---|
| 226 | |
---|
| 227 | |
---|
[11989] | 228 | # Customer document interfaces |
---|
| 229 | |
---|
| 230 | class ICustomerDocumentsContainer(IDocumentsContainer): |
---|
| 231 | """A container for customer document objects. |
---|
| 232 | |
---|
| 233 | """ |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | class ICustomerDocument(IDocument): |
---|
[12089] | 237 | """A customer document object. |
---|
[11989] | 238 | |
---|
| 239 | """ |
---|
| 240 | |
---|
[12089] | 241 | is_editable = Attribute('Document editable by customer') |
---|
| 242 | translated_class_name = Attribute('Translatable class name') |
---|
[12053] | 243 | |
---|
| 244 | |
---|
| 245 | class ICustomerPDFDocument(IDocument): |
---|
| 246 | """A customer document. |
---|
| 247 | |
---|
[12089] | 248 | """ |
---|
| 249 | |
---|
| 250 | # Customer application interfaces |
---|
| 251 | |
---|
| 252 | class IApplicationsContainer(IIkobaObject): |
---|
| 253 | """A container for customer aplication objects. |
---|
| 254 | |
---|
| 255 | """ |
---|
| 256 | |
---|
| 257 | def addApplication(application): |
---|
| 258 | """Add an application object. |
---|
| 259 | """ |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | class IApplication(IIkobaObject): |
---|
| 263 | """A customer application. |
---|
| 264 | |
---|
| 265 | """ |
---|
| 266 | application_id = Attribute('Application Identifier') |
---|
| 267 | history = Attribute('Object history, a list of messages') |
---|
| 268 | state = Attribute('Returns the application state') |
---|
| 269 | translated_state = Attribute( |
---|
| 270 | 'Returns a translated, more verbose appliction state') |
---|
| 271 | class_name = Attribute('Name of the application class') |
---|
[12092] | 272 | formatted_transition_date = Attribute( |
---|
| 273 | 'Last transition formatted date string') |
---|
| 274 | application_category = Attribute('Category for the grouping of products') |
---|
[12089] | 275 | |
---|
| 276 | title = schema.TextLine( |
---|
| 277 | title = _(u'Application Title'), |
---|
| 278 | required = True, |
---|
| 279 | ) |
---|
| 280 | |
---|
| 281 | last_transition_date = schema.Datetime( |
---|
| 282 | title = _(u'Last Transition Date'), |
---|
| 283 | required = False, |
---|
| 284 | readonly = False, |
---|
| 285 | ) |
---|
[12092] | 286 | |
---|
| 287 | product = schema.Choice( |
---|
| 288 | title = _(u'Product'), |
---|
| 289 | source = AppCatProductSource(), |
---|
| 290 | required = False, |
---|
| 291 | ) |
---|