Changeset 12100 for main


Ignore:
Timestamp:
1 Dec 2014, 05:51:58 (10 years ago)
Author:
Henrik Bettermann
Message:

We don't need a contains method since there are usually only a few products in the products container. Thus we can use the the BasicContextualSourceFactory? instead of the SmartBasicContextualSourceFactory?.

Add source factory for customer documents.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/vocabularies.py

    r12098 r12100  
    2626from zc.sourcefactory.basic import BasicSourceFactory
    2727from zc.sourcefactory.contextual import BasicContextualSourceFactory
    28 from waeup.ikoba.interfaces import SimpleIkobaVocabulary
     28from waeup.ikoba.interfaces import SimpleIkobaVocabulary, SUBMITTED, VERIFIED
    2929from waeup.ikoba.interfaces import MessageFactory as _
    3030from waeup.ikoba.utils.helpers import get_sorted_preferred
    3131from waeup.ikoba.utils.countries import COUNTRIES
    32 from waeup.ikoba.sourcefactory import SmartBasicContextualSourceFactory
    33 
    3432
    3533#: a tuple of tuples (<COUNTRY-NAME>, <ISO-CODE>) with Nigeria first.
     
    120118
    121119
    122 class ConCatProductSource(SmartBasicContextualSourceFactory):
    123     """An contract category product delivers all products
     120class ConCatProductSource(BasicContextualSourceFactory):
     121    """A contract category product source delivers all products
    124122    which belong to a certain contract_category.
    125123    """
    126     def contains(self, context, value):
    127         concat = getattr(context, 'contract_category', None)
    128         if value.contract_category == concat:
    129             return True
    130         return False
    131124
    132125    def getValues(self, context):
     
    144137    def getTitle(self, context, value):
    145138        return "%s - %s" % (value.product_id, value.title)
     139
     140
     141class CustomerDocumentSource(BasicContextualSourceFactory):
     142    """A customer document source delivers all submitted and verfified documents
     143    of the context customer.
     144    """
     145
     146    def getValues(self, context):
     147        documents = context.customer['documents'].values()
     148        resultlist = [
     149            value for value in documents if value.state in (SUBMITTED, VERIFIED)]
     150        return resultlist
     151
     152    def getToken(self, context, value):
     153        return value.document_id
     154
     155    def getTitle(self, context, value):
     156        return "%s - %s" % (value.document_id, value.title)
Note: See TracChangeset for help on using the changeset viewer.