[12018] | 1 | ## $Id: interfaces.py 12119 2014-12-02 14:38: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 ( |
---|
[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 | |
---|
[12089] | 242 | is_editable = Attribute('Document editable by customer') |
---|
| 243 | translated_class_name = Attribute('Translatable class name') |
---|
[12053] | 244 | |
---|
| 245 | |
---|
| 246 | class ICustomerPDFDocument(IDocument): |
---|
| 247 | """A customer document. |
---|
| 248 | |
---|
[12089] | 249 | """ |
---|
| 250 | |
---|
[12097] | 251 | # Customer contract interfaces |
---|
[12089] | 252 | |
---|
[12097] | 253 | class IContractsContainer(IIkobaObject): |
---|
[12089] | 254 | """A container for customer aplication objects. |
---|
| 255 | |
---|
| 256 | """ |
---|
| 257 | |
---|
[12097] | 258 | def addContract(contract): |
---|
| 259 | """Add an contract object. |
---|
[12089] | 260 | """ |
---|
| 261 | |
---|
| 262 | |
---|
[12097] | 263 | class IContract(IIkobaObject): |
---|
| 264 | """A customer contract. |
---|
[12089] | 265 | |
---|
| 266 | """ |
---|
[12097] | 267 | contract_id = Attribute('Contract Identifier') |
---|
[12089] | 268 | history = Attribute('Object history, a list of messages') |
---|
[12097] | 269 | state = Attribute('Returns the contract state') |
---|
[12089] | 270 | translated_state = Attribute( |
---|
| 271 | 'Returns a translated, more verbose appliction state') |
---|
[12097] | 272 | class_name = Attribute('Name of the contract class') |
---|
[12092] | 273 | formatted_transition_date = Attribute( |
---|
| 274 | 'Last transition formatted date string') |
---|
[12097] | 275 | contract_category = Attribute('Category for the grouping of products') |
---|
[12094] | 276 | last_product_id = Attribute( |
---|
[12097] | 277 | 'Id of product recently stored with the contract') |
---|
[12089] | 278 | |
---|
| 279 | title = schema.TextLine( |
---|
[12097] | 280 | title = _(u'Contract Title'), |
---|
[12089] | 281 | required = True, |
---|
| 282 | ) |
---|
| 283 | |
---|
| 284 | last_transition_date = schema.Datetime( |
---|
| 285 | title = _(u'Last Transition Date'), |
---|
| 286 | required = False, |
---|
| 287 | readonly = False, |
---|
| 288 | ) |
---|
[12092] | 289 | |
---|
[12119] | 290 | product_object = schema.Choice( |
---|
[12092] | 291 | title = _(u'Product'), |
---|
[12098] | 292 | source = ConCatProductSource(), |
---|
[12095] | 293 | required = False, |
---|
| 294 | ) |
---|
| 295 | |
---|
[12103] | 296 | |
---|
[12097] | 297 | class IContractEdit(IContract): |
---|
| 298 | """Interface for editing contract data by customers. |
---|
[12095] | 299 | |
---|
| 300 | """ |
---|
| 301 | |
---|
[12119] | 302 | product_object = schema.Choice( |
---|
[12095] | 303 | title = _(u'Product'), |
---|
[12098] | 304 | source = ConCatProductSource(), |
---|
[12094] | 305 | required = True, |
---|
[12103] | 306 | ) |
---|
| 307 | |
---|
| 308 | |
---|
| 309 | class ISampleContract(IContract): |
---|
| 310 | """A customer contract sample with document attached. |
---|
| 311 | |
---|
| 312 | """ |
---|
| 313 | |
---|
[12119] | 314 | document_object = schema.Choice( |
---|
[12103] | 315 | title = _(u'Document'), |
---|
| 316 | source = CustomerDocumentSource(), |
---|
| 317 | required = False, |
---|
| 318 | ) |
---|
| 319 | |
---|
| 320 | |
---|
| 321 | class ISampleContractEdit(ISampleContract): |
---|
| 322 | """Interface for editing sample contract data by customers. |
---|
| 323 | |
---|
| 324 | """ |
---|
| 325 | |
---|
[12119] | 326 | product_object = schema.Choice( |
---|
[12103] | 327 | title = _(u'Product'), |
---|
| 328 | source = ConCatProductSource(), |
---|
| 329 | required = True, |
---|
| 330 | ) |
---|
| 331 | |
---|
[12119] | 332 | document_object = schema.Choice( |
---|
[12103] | 333 | title = _(u'Document'), |
---|
| 334 | source = CustomerDocumentSource(), |
---|
| 335 | required = True, |
---|
[12095] | 336 | ) |
---|