I propose to add the vocabulary directive back
because of the following use case.


original vocabulary ZCML
------------------------

<vocabulary
  name="available tiks languages"
  factory=".vocabulary.LanguagesVocabulary"
  domain="tiks"
  />


new vocabulary ZCML
-------------------

<utility
  name="available tiks languages"
  component=".vocabulary.LanguagesVocabularyFactory"
  />


The real truth can you see in the new way of define the factory part

original vocabulary.py
----------------------

from zope.interface.declarations import implements
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary
from zope.app.zapi import getUtility
from zope.app.i18n.interfaces import ILocalTranslationDomain
from tiks.language.negotiator import InLanguagesVocabulary


class LanguagesVocabulary(SimpleVocabulary):
    """... languages from a translation domain."""

    implements(ILanguagesVocabulary)

    def __init__(self, context, domain='zope'):
        terms = []

        # collect languages from translation domain
        trans_domain = getUtility(ILocalTranslationDomain, domain)
        languages = trans_domain.getAvailableLanguages()

        for lang in languages:
            terms.append(SimpleTerm(lang, lang, lang))

        terms.sort(lambda lhs, rhs: cmp(lhs.title, rhs.title))
        super(LanguagesVocabulary, self).__init__(terms)


new vocabulary.py
-----------------

from zope.interface.declarations import implements
from zope.interface import classProvides
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary
from zope.app.i18n.interfaces import ILocalTranslationDomain
from zope.app.schema.interfaces import IVocabularyFactory
from zope.app.zapi import getUtility
from tiks.language.negotiator import ILanguagesVocabulary


class LanguagesVocabulary(SimpleVocabulary):
    """... languages from a translation domain."""

    implements(ILanguagesVocabulary)

    def __init__(self, context, domain='zope'):
        terms = []

        # collect languages from translation domain
        trans_domain = getUtility(ILocalTranslationDomain, domain)
        languages = trans_domain.getAvailableLanguages()

        for lang in languages:
            terms.append(SimpleTerm(lang, lang, lang))

        terms.sort(lambda lhs, rhs: cmp(lhs.title, rhs.title))
        super(LanguagesVocabulary, self).__init__(terms)


class LanguagesVocabularyFactory(LanguagesVocabulary):
    """The new style vocabulary factory."""

    classProvides(IVocabularyFactory)
    domain = 'tiks'


Fazit
-----
This means that I win one line in the ZCML and I have to
write a own factory which isn't reusable. Means additional
4 lines of code in the factory and additional 2 imports for doing this.

I could live with that, but I don't understand why I loose additional
to this the reusablility and also the readability in ZCML?


Philipp can you tell me why this is better if we loose the concept for
quick adding a new utility providing kws like the 'domain' attribute in example.

So this means if I need another LanguageVocabulary utility for a new domain, I have to write new factory, just for use another domain='foobar' attribute.

Should we add the vocabulary directive to a higher level namespace
or should we add it back to where it was. Note the option to go
the new (simply but not reusable pure python) way is there in both concept.

And,
what should we do with the factory and implement sub class directive
before they get (re)moved?  I whould like to discuss this and close
this pending topic after that.


Regards
Roger Ineichen

_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to