On Sun, Aug 24, 2008 at 07:30:24PM +0100, Martin Aspeli wrote:
> I'm trying to build a widget that allows for auto-complete of items in a 
> vocabulary, but also allows additional (string) values to be added. To 
> understand how that works, I am digging into z3c.formwidget.query, and 
> it looks to me like it's making incorrect assumptions about its own 
> interfaces.
> class IBaseVocabulary(ISource):
>      def getTerm(value):
>          """Return the ITerm object for the term 'value'.
>          If 'value' is not a valid term, this method raises LookupError.
>          """
> class IVocabularyTokenized(IVocabulary):
>      def getTermByToken(token):
>          """Return an ITokenizedTerm for the passed-in token.
>          If `token` is not represented in the vocabulary, `LookupError`
>          is raised.
>          """
> However, more importantly, in the README.txt of z3c.formwidget.query we 
> have this:
>    ...     def getTermByValue(self, value):
>    ...         return self.vocabulary.by_value[value]
> and similarly, in widget.py:
>          map(terms.add,
>              map(source.getTermByValue,
>                  filter(lambda value: value and value not in values, 
> selection)))
> If I'm not reading this wrong, it seems to me that z3c.formwidget.query 
> is using getTermByValue() (which I can't find anywhere else) instead of 
> getTermByToken() as defined by IVocabularyTokenized.

That does look like a bug.  However, without looking very deeply at the
code,the fix would be to use getTerm, not getTermByToken.

I wouldn't mind seeing getTerm renamed to getTermByValue, but that's
probably difficult to do without breaking backwards-compatibility.

Marius Gedminas
I used to think I was indecisive, but now I'm not so sure.

Attachment: signature.asc
Description: Digital signature

Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to