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