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