[Zope3-Users] multivalued fields and sources

Sam Stainsby sam at stainsby.id.au
Sat Apr 15 23:36:24 EDT 2006


I have a feeling that this has been answered somewhere here, but can't
find it. Apologies if this is the case ...

Consider the following interfaces:

class IUnitsVocabularySingleSelector(Interface):
    unitsVocabularies = Choice(
        title=u'Allowed Units',
        source=u'SA UnitsContainer Contents Source', required=False,
    )
    
class IUnitsVocabularyMultiSelector(Interface):
    unitsVocabularies = List(
        title=u'Allowed Units',
        value_type=Choice(
            source=u'SA UnitsContainer Contents Source', required=False,
        ),
    )
    
class IInventory(IContainer, IUnitsVocabularySingleSelector):
    """An inventory of items."""
    contains('.IItem', '.IUnitsContainer')

class IInventory2(IContainer, IUnitsVocabularySingleSelector):
    """An inventory of items."""
    contains('.IItem', '.IUnitsContainer')


The 'selector' interfaces are used to select sub-folders containing the
'units' (kg, hours, etc.) that I want my inventory to use. I was using
vocabularies and this was working well. I then I decided to switch to
sources. In the IInventory2 case, I was expecting to get a nice in-out
ordered list widget like I did with vocabularies (an
OrderedMultiSelectWidget I'm guessing from the ZOpe  3 code). Instead I
got an error about not finding an adapters supporting ISourceQueriables.
When I made my source provide ISourceQueriablessupport, I
eliminated the error, but instead just got a blank label with the 'Allowed
Units' title.

The source I'm using is this (initially I wasn't implementing
ISourceQueriables):

class ContentsSource(object):
    """A source of items in a folder."""
    implements(IIterableSource, ISourceQueriables)
    adapts(IContainer)

    def __init__(self, context, **kw):
        self.items = []
        interface = None
        if 'interface' in kw:
            interfaceName = kw['interface']
            interface = resolve(interfaceName)
        for key in context.keys():
            item = removeSecurityProxy(context[key])
            if not interface or (interface and interface.providedBy(item)):
                self.items.append(item) 
                
    def __iter__(self):
        return self.items.__iter__()

    def __len__(self):
        return len(self.items)

    def __contains__(self, value):
        return self.items.__contains__(value)

    def getQueriables(self):
        return []
        

>From looking the Zope 3 code, I suspect that the full set of widgets is
not yet available for sources? Or have I got that wrong? I see there are
some simpler widgets there that build the widgets used by vocabularies.
I'm happy to try my hand at adding to that set of widget if noone else is
doing it. Maybe this is being done a different way for sources?



More information about the Zope3-users mailing list