Ignore:
Timestamp:
18 Mar 2015, 08:45:41 (10 years ago)
Author:
Henrik Bettermann
Message:

Add RefereeSource? components and register IkobaSequenceWidget? for RefereeSource?.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
3 edited

Legend:

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

    r12585 r12785  
    2424import shutil
    2525from datetime import date
     26from zope.event import notify
    2627from zope.component.hooks import setSite
    2728from zope.component import queryUtility, createObject
    2829from hurry.workflow.interfaces import IWorkflowState
    2930from waeup.ikoba.app import Company
    30 from waeup.ikoba.interfaces import SUBMITTED
     31from waeup.ikoba.interfaces import SUBMITTED, APPROVED
    3132from waeup.ikoba.customers.vocabularies import (
    32     ConCatProductSource, ConCatActiveProductSource, CustomerDocumentSource)
     33    ConCatProductSource, ConCatActiveProductSource, CustomerDocumentSource,
     34    RefereeSourceFactory
     35    )
    3336from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
    3437
     
    133136        self.assertEqual(result, u'DOC1... - My Sample Document')
    134137
     138    def test_getValues_RefereeSourceFactory(self):
     139        source = RefereeSourceFactory()
     140        result = source.factory.getValues(object())
     141        self.assertFalse(self.customer in result)
     142        IWorkflowState(self.customer).setState(APPROVED)
     143        notify(grok.ObjectModifiedEvent(self.customer))
     144        result = source.factory.getValues(object())
     145        self.assertTrue(self.customer in result)
     146
     147    def test_getTitle_RefereeSourceFactory(self):
     148        source = RefereeSourceFactory()
     149        result = source.factory.getTitle(object(), self.customer)
     150        self.assertEqual(result, u'Bob Tester (K1000000)')
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/vocabularies.py

    r12770 r12785  
    2929from zc.sourcefactory.interfaces import IContextualSource
    3030from waeup.ikoba.sourcefactory import SmartBasicContextualSourceFactory
    31 from waeup.ikoba.interfaces import SimpleIkobaVocabulary, SUBMITTED, VERIFIED
     31from waeup.ikoba.interfaces import (
     32    SimpleIkobaVocabulary, SUBMITTED, VERIFIED, APPROVED
     33    )
    3234from waeup.ikoba.interfaces import MessageFactory as _
    3335from waeup.ikoba.utils.helpers import get_sorted_preferred
     
    167169        if not concat:
    168170            return products
    169        
    170171        resultlist = [
    171172            value for value in products
     
    238239        currency = ISO_4217_CURRENCIES[value.currency][1]
    239240        return "%s @ %s %s" % (value.title, value.fee, currency)
     241
     242
     243class IRefereeSource(IContextualSource):
     244    """A source operating in context.
     245
     246    This is a marker interface needed for the registration of the
     247    IkobaSequenceWidget when using the List-Choice-RefereeSourceFactory
     248    field combination primarily in ICustomer as a replacement for
     249    the SourceOrderedMultiSelectWidget.
     250    """
     251
     252
     253class RefereeSource(FactoredContextualSource):
     254
     255      implements(IRefereeSource)
     256
     257
     258class RefereeSourceFactory(BasicContextualSourceFactory):
     259    """A referee source delivers all registered and approved customers.
     260    """
     261
     262    source_class = RefereeSource
     263
     264    def getValues(self, context):
     265        user_id = getattr(getattr(context, 'customer', None), 'user_id', None)
     266        catalog = getUtility(ICatalog, name='customers_catalog')
     267        results = catalog.searchResults(state=(APPROVED, APPROVED))
     268        return list(results)
     269
     270    def getToken(self, context, value):
     271        return value.customer_id
     272
     273    def getTitle(self, context, value):
     274        return "%s (%s)" % (value.display_fullname, value.customer_id[:9])
  • main/waeup.ikoba/trunk/src/waeup/ikoba/widgets/overrides.zcml

    r12506 r12785  
    5252      permission="zope.Public"
    5353      />     
     54     
     55  <!-- Register IkobaSequenceWidget for RefereeSource -->
     56  <adapter
     57      for="zope.schema.interfaces.IList
     58           waeup.ikoba.customers.vocabularies.IRefereeSource
     59           zope.publisher.interfaces.browser.IBrowserRequest"
     60      provides="zope.formlib.interfaces.ISimpleInputWidget"
     61      factory="waeup.ikoba.widgets.sequencewidget.IkobaSequenceWidget"
     62      permission="zope.Public"
     63      />     
    5464
    5565  <!-- Register IkobaSourceOrderedMultiSelectWidget for IterableSource -->
Note: See TracChangeset for help on using the changeset viewer.