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