[12018] | 1 | ## $Id: interfaces.py 12324 2014-12-26 09:35:21Z 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 ( |
---|
[12260] | 25 | IIkobaObject, validate_email, ICSVExporter, validate_uuid) |
---|
[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 ( |
---|
[12103] | 31 | contextual_reg_num_source, GenderSource, nats_vocab, |
---|
[12324] | 32 | ConCatProductSource, CustomerDocumentSource, |
---|
| 33 | ProductOptionSource) |
---|
[11958] | 34 | |
---|
[11985] | 35 | |
---|
[11956] | 36 | class ICustomersUtils(Interface): |
---|
| 37 | """A collection of methods which are subject to customization. |
---|
| 38 | |
---|
| 39 | """ |
---|
| 40 | |
---|
[11985] | 41 | |
---|
[11956] | 42 | class ICustomersContainer(IIkobaObject): |
---|
| 43 | """A customers container contains company customers. |
---|
| 44 | |
---|
| 45 | """ |
---|
| 46 | def addCustomer(customer): |
---|
| 47 | """Add an ICustomer object and subcontainers. |
---|
| 48 | |
---|
| 49 | """ |
---|
| 50 | |
---|
| 51 | unique_customer_id = Attribute("""A unique customer id.""") |
---|
| 52 | |
---|
[11958] | 53 | |
---|
| 54 | class ICustomerNavigation(ICustomerNavigationBase): |
---|
| 55 | """Interface needed for custom navigation, logging, etc. |
---|
| 56 | |
---|
| 57 | """ |
---|
| 58 | customer = Attribute('Customer object of context.') |
---|
| 59 | |
---|
| 60 | def writeLogMessage(view, message): |
---|
| 61 | """Write a view specific log message into custom.log. |
---|
| 62 | |
---|
| 63 | """ |
---|
| 64 | |
---|
[11985] | 65 | |
---|
[11956] | 66 | class ICustomer(IIkobaObject): |
---|
| 67 | """Representation of a customer. |
---|
| 68 | |
---|
| 69 | """ |
---|
| 70 | |
---|
[11958] | 71 | history = Attribute('Object history, a list of messages') |
---|
| 72 | state = Attribute('Returns the registration state of a customer') |
---|
| 73 | password = Attribute('Encrypted password of a customer') |
---|
| 74 | temp_password = Attribute( |
---|
| 75 | 'Dictionary with user name, timestamp and encrypted password') |
---|
| 76 | fullname = Attribute('All name parts separated by hyphens') |
---|
| 77 | display_fullname = Attribute('The fullname of an applicant') |
---|
| 78 | |
---|
| 79 | suspended = schema.Bool( |
---|
| 80 | title = _(u'Account suspended'), |
---|
| 81 | default = False, |
---|
| 82 | required = False, |
---|
| 83 | ) |
---|
| 84 | |
---|
| 85 | suspended_comment = schema.Text( |
---|
| 86 | title = _(u"Reasons for Deactivation"), |
---|
| 87 | required = False, |
---|
| 88 | description = _( |
---|
| 89 | u'This message will be shown if and only if deactivated ' |
---|
| 90 | 'customers try to login.'), |
---|
| 91 | ) |
---|
| 92 | |
---|
| 93 | customer_id = schema.TextLine( |
---|
[11996] | 94 | title = _(u'Customer Id'), |
---|
[11958] | 95 | required = False, |
---|
| 96 | ) |
---|
| 97 | |
---|
| 98 | firstname = schema.TextLine( |
---|
| 99 | title = _(u'First Name'), |
---|
| 100 | required = True, |
---|
| 101 | ) |
---|
| 102 | |
---|
| 103 | middlename = schema.TextLine( |
---|
| 104 | title = _(u'Middle Name'), |
---|
| 105 | required = False, |
---|
| 106 | ) |
---|
| 107 | |
---|
| 108 | lastname = schema.TextLine( |
---|
| 109 | title = _(u'Last Name (Surname)'), |
---|
| 110 | required = True, |
---|
| 111 | ) |
---|
| 112 | |
---|
| 113 | sex = schema.Choice( |
---|
| 114 | title = _(u'Sex'), |
---|
| 115 | source = GenderSource(), |
---|
| 116 | required = True, |
---|
| 117 | ) |
---|
| 118 | |
---|
| 119 | reg_number = TextLineChoice( |
---|
| 120 | title = _(u'Registration Number'), |
---|
| 121 | required = True, |
---|
| 122 | readonly = False, |
---|
| 123 | source = contextual_reg_num_source, |
---|
| 124 | ) |
---|
| 125 | |
---|
| 126 | email = schema.ASCIILine( |
---|
| 127 | title = _(u'Email'), |
---|
| 128 | required = False, |
---|
| 129 | constraint=validate_email, |
---|
| 130 | ) |
---|
[12260] | 131 | |
---|
[11958] | 132 | phone = PhoneNumber( |
---|
| 133 | title = _(u'Phone'), |
---|
| 134 | description = u'', |
---|
| 135 | required = False, |
---|
| 136 | ) |
---|
| 137 | |
---|
| 138 | def setTempPassword(user, password): |
---|
| 139 | """Set a temporary password (LDAP-compatible) SSHA encoded for |
---|
| 140 | officers. |
---|
| 141 | |
---|
| 142 | """ |
---|
| 143 | |
---|
| 144 | def getTempPassword(): |
---|
| 145 | """Check if a temporary password has been set and if it |
---|
| 146 | is not expired. |
---|
| 147 | |
---|
| 148 | Return the temporary password if valid, |
---|
| 149 | None otherwise. Unset the temporary password if expired. |
---|
| 150 | """ |
---|
| 151 | |
---|
[11985] | 152 | |
---|
[11958] | 153 | class ICustomerUpdateByRegNo(ICustomer): |
---|
| 154 | """Representation of a customer. Skip regular reg_number validation. |
---|
| 155 | |
---|
| 156 | """ |
---|
| 157 | reg_number = schema.TextLine( |
---|
| 158 | title = _(u'Registration Number'), |
---|
| 159 | required = False, |
---|
| 160 | ) |
---|
| 161 | |
---|
[11985] | 162 | |
---|
[11958] | 163 | class ICSVCustomerExporter(ICSVExporter): |
---|
| 164 | """A regular ICSVExporter that additionally supports exporting |
---|
| 165 | data from a given customer object. |
---|
| 166 | """ |
---|
| 167 | def get_filtered(site, **kw): |
---|
| 168 | """Get a filtered set of customer. |
---|
| 169 | """ |
---|
| 170 | |
---|
[11967] | 171 | def export_customer(customer, filepath=None): |
---|
[11958] | 172 | """Export data for a given customer. |
---|
| 173 | """ |
---|
| 174 | |
---|
| 175 | def export_filtered(site, filepath=None, **kw): |
---|
| 176 | """Export filtered set of customers. |
---|
| 177 | """ |
---|
| 178 | |
---|
[11985] | 179 | |
---|
[12039] | 180 | class ICustomerRequestPW(IIkobaObject): |
---|
| 181 | """Representation of a customer for first-time password request. |
---|
[11967] | 182 | |
---|
| 183 | This interface is used when customers use the requestpw page to |
---|
| 184 | login for the the first time. |
---|
| 185 | """ |
---|
| 186 | number = schema.TextLine( |
---|
| 187 | title = _(u'Registration Number'), |
---|
| 188 | required = True, |
---|
| 189 | ) |
---|
| 190 | |
---|
| 191 | firstname = schema.TextLine( |
---|
| 192 | title = _(u'First Name'), |
---|
| 193 | required = True, |
---|
| 194 | ) |
---|
| 195 | |
---|
| 196 | email = schema.ASCIILine( |
---|
| 197 | title = _(u'Email Address'), |
---|
| 198 | required = True, |
---|
| 199 | constraint=validate_email, |
---|
| 200 | ) |
---|
[11989] | 201 | |
---|
| 202 | |
---|
[12039] | 203 | class ICustomerCreate(IIkobaObject): |
---|
| 204 | """Representation of an customer for account creation. |
---|
| 205 | |
---|
| 206 | This interface is used when customers use the createaccount page. |
---|
| 207 | """ |
---|
| 208 | |
---|
| 209 | firstname = schema.TextLine( |
---|
| 210 | title = _(u'First Name'), |
---|
| 211 | required = True, |
---|
| 212 | ) |
---|
| 213 | |
---|
| 214 | middlename = schema.TextLine( |
---|
| 215 | title = _(u'Middle Name'), |
---|
| 216 | required = False, |
---|
| 217 | ) |
---|
| 218 | |
---|
| 219 | lastname = schema.TextLine( |
---|
| 220 | title = _(u'Last Name (Surname)'), |
---|
| 221 | required = True, |
---|
| 222 | ) |
---|
| 223 | |
---|
| 224 | email = schema.ASCIILine( |
---|
| 225 | title = _(u'Email Address'), |
---|
| 226 | required = True, |
---|
| 227 | constraint=validate_email, |
---|
| 228 | ) |
---|
| 229 | |
---|
| 230 | |
---|
[11989] | 231 | # Customer document interfaces |
---|
| 232 | |
---|
| 233 | class ICustomerDocumentsContainer(IDocumentsContainer): |
---|
| 234 | """A container for customer document objects. |
---|
| 235 | |
---|
| 236 | """ |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | class ICustomerDocument(IDocument): |
---|
[12089] | 240 | """A customer document object. |
---|
[11989] | 241 | |
---|
| 242 | """ |
---|
| 243 | |
---|
[12166] | 244 | is_editable_by_customer = Attribute('Document editable by customer') |
---|
| 245 | is_editable_by_manager = Attribute('Document editable by manager') |
---|
[12053] | 246 | |
---|
[12260] | 247 | document_id = schema.TextLine( |
---|
| 248 | title = _(u'Document Id'), |
---|
| 249 | required = False, |
---|
| 250 | constraint=validate_uuid, |
---|
| 251 | ) |
---|
[12053] | 252 | |
---|
[12260] | 253 | |
---|
[12279] | 254 | class ICustomerSampleDocument(ICustomerDocument): |
---|
| 255 | """A customer sample document object. |
---|
| 256 | |
---|
| 257 | """ |
---|
| 258 | |
---|
| 259 | |
---|
[12260] | 260 | class ICustomerPDFDocument(ICustomerDocument): |
---|
[12279] | 261 | """A customer pdf document object. |
---|
[12053] | 262 | |
---|
[12089] | 263 | """ |
---|
| 264 | |
---|
[12097] | 265 | # Customer contract interfaces |
---|
[12089] | 266 | |
---|
[12097] | 267 | class IContractsContainer(IIkobaObject): |
---|
[12089] | 268 | """A container for customer aplication objects. |
---|
| 269 | |
---|
| 270 | """ |
---|
| 271 | |
---|
[12097] | 272 | def addContract(contract): |
---|
| 273 | """Add an contract object. |
---|
[12089] | 274 | """ |
---|
| 275 | |
---|
| 276 | |
---|
[12097] | 277 | class IContract(IIkobaObject): |
---|
| 278 | """A customer contract. |
---|
[12089] | 279 | |
---|
| 280 | """ |
---|
| 281 | history = Attribute('Object history, a list of messages') |
---|
[12097] | 282 | state = Attribute('Returns the contract state') |
---|
[12089] | 283 | translated_state = Attribute( |
---|
| 284 | 'Returns a translated, more verbose appliction state') |
---|
[12097] | 285 | class_name = Attribute('Name of the contract class') |
---|
[12092] | 286 | formatted_transition_date = Attribute( |
---|
| 287 | 'Last transition formatted date string') |
---|
[12097] | 288 | contract_category = Attribute('Category for the grouping of products') |
---|
[12094] | 289 | last_product_id = Attribute( |
---|
[12097] | 290 | 'Id of product recently stored with the contract') |
---|
[12167] | 291 | is_editable_by_customer = Attribute('Contract editable by customer') |
---|
[12144] | 292 | is_approvable = Attribute('Contract approvable by officer') |
---|
[12143] | 293 | translated_class_name = Attribute('Translatable class name') |
---|
[12289] | 294 | user_id = Attribute('Id of a user, actually the id of the customer') |
---|
[12089] | 295 | |
---|
[12258] | 296 | contract_id = schema.TextLine( |
---|
| 297 | title = _(u'Contract Id'), |
---|
| 298 | required = False, |
---|
[12260] | 299 | constraint=validate_uuid, |
---|
[12258] | 300 | ) |
---|
| 301 | |
---|
[12089] | 302 | title = schema.TextLine( |
---|
[12097] | 303 | title = _(u'Contract Title'), |
---|
[12089] | 304 | required = True, |
---|
| 305 | ) |
---|
| 306 | |
---|
[12119] | 307 | product_object = schema.Choice( |
---|
[12092] | 308 | title = _(u'Product'), |
---|
[12098] | 309 | source = ConCatProductSource(), |
---|
[12095] | 310 | required = False, |
---|
| 311 | ) |
---|
| 312 | |
---|
[12324] | 313 | product_options = schema.List( |
---|
| 314 | title = _(u'Options/Fees'), |
---|
| 315 | value_type = schema.Choice( |
---|
| 316 | source=ProductOptionSource(), |
---|
| 317 | required = True, |
---|
| 318 | ), |
---|
| 319 | required = False, |
---|
| 320 | readonly = False, |
---|
| 321 | default = [], |
---|
| 322 | ) |
---|
[12103] | 323 | |
---|
[12324] | 324 | |
---|
[12097] | 325 | class IContractEdit(IContract): |
---|
| 326 | """Interface for editing contract data by customers. |
---|
[12095] | 327 | |
---|
| 328 | """ |
---|
| 329 | |
---|
[12119] | 330 | product_object = schema.Choice( |
---|
[12095] | 331 | title = _(u'Product'), |
---|
[12098] | 332 | source = ConCatProductSource(), |
---|
[12094] | 333 | required = True, |
---|
[12103] | 334 | ) |
---|
| 335 | |
---|
| 336 | |
---|
| 337 | class ISampleContract(IContract): |
---|
| 338 | """A customer contract sample with document attached. |
---|
| 339 | |
---|
| 340 | """ |
---|
| 341 | |
---|
[12119] | 342 | document_object = schema.Choice( |
---|
[12103] | 343 | title = _(u'Document'), |
---|
| 344 | source = CustomerDocumentSource(), |
---|
| 345 | required = False, |
---|
| 346 | ) |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | class ISampleContractEdit(ISampleContract): |
---|
| 350 | """Interface for editing sample contract data by customers. |
---|
| 351 | |
---|
| 352 | """ |
---|
| 353 | |
---|
[12119] | 354 | product_object = schema.Choice( |
---|
[12103] | 355 | title = _(u'Product'), |
---|
| 356 | source = ConCatProductSource(), |
---|
| 357 | required = True, |
---|
| 358 | ) |
---|
| 359 | |
---|
[12119] | 360 | document_object = schema.Choice( |
---|
[12103] | 361 | title = _(u'Document'), |
---|
| 362 | source = CustomerDocumentSource(), |
---|
| 363 | required = True, |
---|
[12095] | 364 | ) |
---|