## $Id: interfaces.py 12809 2015-03-21 13:31:16Z henrik $ ## ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## #from datetime import datetime from zope.component import getUtility from zope.interface import Attribute, Interface from zope import schema from zc.sourcefactory.contextual import BasicContextualSourceFactory from waeup.ikoba.interfaces import MessageFactory as _ from waeup.ikoba.interfaces import ( IIkobaObject, validate_email, ICSVExporter, validate_uuid) from waeup.ikoba.schema import TextLineChoice, FormattedDate, PhoneNumber from waeup.ikoba.browser.interfaces import ICustomerNavigationBase from waeup.ikoba.documents.interfaces import IDocumentsContainer, IDocument from waeup.ikoba.products.productoptions import ProductOptionField from waeup.ikoba.customers.vocabularies import ( contextual_reg_num_source, contextual_email_source, GenderSource, nats_vocab, ConCatProductSource, ConCatActiveProductSource, CustomerDocumentSource, ProductOptionSourceFactory) # Define a validation method for product options class CurrencyMismatch(schema.ValidationError): __doc__ = u"Currency mismatch" def unique_currency(value): currencies = set([x.currency for x in value]) if len(currencies) > 1: raise CurrencyMismatch(value) return True class ICustomersUtils(Interface): """A collection of methods which are subject to customization. """ class ICustomersContainer(IIkobaObject): """A customers container contains company customers. """ def addCustomer(customer): """Add an ICustomer object and subcontainers. """ unique_customer_id = Attribute("""A unique customer id.""") class ICustomerNavigation(ICustomerNavigationBase): """Interface needed for custom navigation, logging, etc. """ customer = Attribute('Customer object of context.') def writeLogMessage(view, message): """Write a view specific log message into custom.log. """ class ICustomer(IIkobaObject): """Representation of a customer. """ history = Attribute('Object history, a list of messages') state = Attribute('Returns the registration state of a customer') password = Attribute('Encrypted password of a customer') temp_password = Attribute( 'Dictionary with user name, timestamp and encrypted password') fullname = Attribute('All name parts separated by hyphens') display_fullname = Attribute('The fullname of an applicant') title = Attribute('A title used for email notifications only') suspended = schema.Bool( title = _(u'Account suspended'), default = False, required = False, ) suspended_comment = schema.Text( title = _(u"Reasons for Deactivation"), required = False, description = _( u'This message will be shown if and only if deactivated ' 'customers try to login.'), ) customer_id = schema.TextLine( title = _(u'Customer Id'), required = False, ) firstname = schema.TextLine( title = _(u'First Name'), required = True, ) middlename = schema.TextLine( title = _(u'Middle Name'), required = False, ) lastname = schema.TextLine( title = _(u'Last Name (Surname)'), required = True, ) sex = schema.Choice( title = _(u'Sex'), source = GenderSource(), required = True, ) reg_number = TextLineChoice( title = _(u'Registration Number'), required = True, readonly = False, source = contextual_reg_num_source, ) email = TextLineChoice( title = _(u'Email'), required = True, constraint = validate_email, source = contextual_email_source, ) phone = PhoneNumber( title = _(u'Phone'), description = u'', required = False, ) def setTempPassword(user, password): """Set a temporary password (LDAP-compatible) SSHA encoded for officers. """ def getTempPassword(): """Check if a temporary password has been set and if it is not expired. Return the temporary password if valid, None otherwise. Unset the temporary password if expired. """ class ICustomerUpdateByRegNo(ICustomer): """Representation of a customer. Skip regular reg_number validation. """ reg_number = schema.TextLine( title = _(u'Registration Number'), required = False, ) class ICSVCustomerExporter(ICSVExporter): """A regular ICSVExporter that additionally supports exporting data from a given customer object. """ def get_filtered(site, **kw): """Get a filtered set of customer. """ def export_customer(customer, filepath=None): """Export data for a given customer. """ def export_filtered(site, filepath=None, **kw): """Export filtered set of customers. """ class ICustomerRequestPW(IIkobaObject): """Representation of a customer for first-time password request. This interface is used when customers use the requestpw page to login for the the first time. """ number = schema.TextLine( title = _(u'Registration Number'), required = True, ) firstname = schema.TextLine( title = _(u'First Name'), required = True, ) email = schema.TextLine( title = _(u'Email Address'), required = True, constraint = validate_email, ) class ICustomerCreate(IIkobaObject): """Representation of an customer for account creation. This interface is used when customers use the createaccount page. """ firstname = schema.TextLine( title = _(u'First Name'), required = True, ) middlename = schema.TextLine( title = _(u'Middle Name'), required = False, ) lastname = schema.TextLine( title = _(u'Last Name (Surname)'), required = True, ) email = TextLineChoice( title = _(u'Email'), required = True, constraint = validate_email, source = contextual_email_source, ) # Customer document interfaces class ICustomerDocumentsContainer(IDocumentsContainer): """A container for customer document objects. """ class ICustomerDocument(IDocument): """A customer document object. """ is_editable_by_customer = Attribute('Document editable by customer') is_editable_by_manager = Attribute('Document editable by manager') document_id = schema.TextLine( title = _(u'Document Id'), required = False, constraint = validate_uuid, ) class ICustomerSampleDocument(ICustomerDocument): """A customer sample document object. """ class ICustomerPDFDocument(ICustomerDocument): """A customer pdf document object. """ # Customer contract interfaces class IContractsContainer(IIkobaObject): """A container for customer aplication objects. """ def addContract(contract): """Add an contract object. """ class IContract(IIkobaObject): """A customer contract. """ history = Attribute('Object history, a list of messages') state = Attribute('Returns the contract state') translated_state = Attribute( 'Returns a translated, more verbose appliction state') class_name = Attribute('Name of the contract class') formatted_transition_date = Attribute( 'Last transition formatted date string') contract_category = Attribute('Category for the grouping of products') last_product_id = Attribute( 'Id of product recently stored with the contract') is_editable = Attribute('Contract editable by customer and manager') is_approvable = Attribute('Contract approvable by officer') translated_class_name = Attribute('Translatable class name') customer = Attribute('Customer object of context.') user_id = Attribute('Id of a user, actually the id of the customer') title = Attribute('Title generated by the associated product') tc_dict = Attribute('Multilingual "Terms and Conditions" dict') valid_from = Attribute('Contract valid from') valid_to = Attribute('Contract valid to') fee_based = Attribute('Fee based contract') contract_id = schema.TextLine( title = _(u'Contract Id'), required = False, constraint = validate_uuid, ) product_object = schema.Choice( title = _(u'Product'), source = ConCatProductSource(), required = False, ) product_options = schema.List( title = _(u'Options/Fees'), value_type = schema.Choice( source = ProductOptionSourceFactory(), required = True, ), constraint = unique_currency, required = False, readonly = False, default = [], ) class IContractSelectProduct(Interface): """Interface for for the ContractSelectProductPage. """ product_object = schema.Choice( title = _(u'Product'), source = ConCatActiveProductSource(), required = True, ) class ISampleContract(IContract): """A customer contract sample with document attached. """ document_object = schema.Choice( title = _(u'Document'), source = CustomerDocumentSource(), required = False, ) class ISampleContractOfficialUse(IIkobaObject): """Interface for official use only. """ comment = schema.Text( title = _(u'Comment'), required = False, ) class ISampleContractProcess(ISampleContract, ISampleContractOfficialUse): """Interface for processing contract data. """ #title = schema.TextLine( # required = False, # ) #tc_dict = schema.Dict( # required = False, # default = {}, # ) product_options = schema.List( value_type = ProductOptionField(), constraint = unique_currency, required = False, readonly = False, default = [], ) class ISampleContractEdit(ISampleContract): """Interface for editing sample contract data by customers. """ document_object = schema.Choice( title = _(u'Document'), source = CustomerDocumentSource(), required = True, )