[12018] | 1 | ## $Id: interfaces.py 12663 2015-03-05 07:28:31Z 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') |
---|
[12663] | 305 | fee_based = Attribute('Fee based contract') |
---|
[12089] | 306 | |
---|
[12258] | 307 | contract_id = schema.TextLine( |
---|
| 308 | title = _(u'Contract Id'), |
---|
| 309 | required = False, |
---|
[12260] | 310 | constraint=validate_uuid, |
---|
[12258] | 311 | ) |
---|
| 312 | |
---|
[12119] | 313 | product_object = schema.Choice( |
---|
[12092] | 314 | title = _(u'Product'), |
---|
[12098] | 315 | source = ConCatProductSource(), |
---|
[12095] | 316 | required = False, |
---|
| 317 | ) |
---|
| 318 | |
---|
[12324] | 319 | product_options = schema.List( |
---|
| 320 | title = _(u'Options/Fees'), |
---|
| 321 | value_type = schema.Choice( |
---|
[12329] | 322 | source=ProductOptionSourceFactory(), |
---|
[12324] | 323 | required = True, |
---|
| 324 | ), |
---|
| 325 | required = False, |
---|
| 326 | readonly = False, |
---|
| 327 | default = [], |
---|
| 328 | ) |
---|
[12103] | 329 | |
---|
[12324] | 330 | |
---|
[12486] | 331 | class IContractSelectProduct(Interface): |
---|
| 332 | """Interface for for the ContractSelectProductPage. |
---|
[12095] | 333 | |
---|
| 334 | """ |
---|
| 335 | |
---|
[12119] | 336 | product_object = schema.Choice( |
---|
[12095] | 337 | title = _(u'Product'), |
---|
[12585] | 338 | source = ConCatActiveProductSource(), |
---|
[12094] | 339 | required = True, |
---|
[12103] | 340 | ) |
---|
| 341 | |
---|
| 342 | |
---|
| 343 | class ISampleContract(IContract): |
---|
| 344 | """A customer contract sample with document attached. |
---|
| 345 | |
---|
| 346 | """ |
---|
| 347 | |
---|
[12119] | 348 | document_object = schema.Choice( |
---|
[12103] | 349 | title = _(u'Document'), |
---|
| 350 | source = CustomerDocumentSource(), |
---|
| 351 | required = False, |
---|
| 352 | ) |
---|
| 353 | |
---|
| 354 | |
---|
[12500] | 355 | class ISampleContractOfficialUse(IIkobaObject): |
---|
| 356 | """Interface for official use only. |
---|
| 357 | """ |
---|
| 358 | |
---|
| 359 | comment = schema.Text( |
---|
| 360 | title = _(u'Comment'), |
---|
| 361 | required = False, |
---|
| 362 | ) |
---|
| 363 | |
---|
| 364 | |
---|
| 365 | class ISampleContractProcess(ISampleContract, ISampleContractOfficialUse): |
---|
[12333] | 366 | """Interface for processing contract data. |
---|
| 367 | """ |
---|
| 368 | |
---|
[12633] | 369 | #title = schema.TextLine( |
---|
| 370 | # required = False, |
---|
| 371 | # ) |
---|
| 372 | |
---|
| 373 | #tc_dict = schema.Dict( |
---|
| 374 | # required = False, |
---|
| 375 | # default = {}, |
---|
| 376 | # ) |
---|
| 377 | |
---|
[12333] | 378 | product_options = schema.List( |
---|
| 379 | value_type = ProductOptionField(), |
---|
| 380 | required = False, |
---|
| 381 | readonly = False, |
---|
| 382 | default = [], |
---|
| 383 | ) |
---|
| 384 | |
---|
| 385 | |
---|
[12103] | 386 | class ISampleContractEdit(ISampleContract): |
---|
| 387 | """Interface for editing sample contract data by customers. |
---|
| 388 | |
---|
| 389 | """ |
---|
| 390 | |
---|
[12119] | 391 | document_object = schema.Choice( |
---|
[12103] | 392 | title = _(u'Document'), |
---|
| 393 | source = CustomerDocumentSource(), |
---|
| 394 | required = True, |
---|
[12095] | 395 | ) |
---|