Re: Registering an indexer for multiple types

Alec Mitchell <[email protected]>
Newsgroups gmane.comp.web.zope.plone.devel
Message-ID <CAMW6WS=0YuvM4e-wZA5Kn=gH2S6wVFJ_hG65=RNgX2zAxLC5vA@mail.gmail.com>
If you're going to have a custom zcml registration, shouldn't that also do
the wrapping?  I guess that would get rid of the "advantage" of only one
zcml registration, but it would also avoid the need to use the decorator at
all.  Perhaps both a zcml configuration and a corresponding grok directive
would satisfy both those who want to do the registration from python and
those who wish to keep it separate.

On Fri, Oct 24, 2014 at 1:39 AM, Jens W. Klein <jens-/[email protected]>
wrote:

> On 2014-10-23 16:27, Alec Mitchell wrote:
> > I don't think this is a bug per se, nor is it likely easily fixable.
> > Note that actual adapter registration is done in zcml, the decorator
> > simply wraps the function and add a _default_ context interface for the
> > adapter.  To get adapters registered for different interfaces you will
> > always need to perform multiple zcml (or grok) registrations, performing
> > multiple function wrappings is neither useful nor necessary for this
> > purpose.  You should be able to simplify a bit though:
> >
> > in python:
> >
> > @indexer(IATDocument)
> > def country_indexer(context):
> >      return _country_indexer(context)
> >
> > in zcml:
> >
> > <adapter name="getCountry" factory=".extender.country_indexer" />
> > <adapter name="getCountry" factory=".extender.country_indexer"
> >   for="Products.ATContentType.interfaces. IATFile" />
> > …
> >
> indeed.
>
> in order to make this work with one node in zcml it would need an own
> zcml-directive registering multiple adapters and a different way to
> annotate the interfaces to be adapted:
>
> @indexer(IATDocument)
> @indexer(IATNewsItem)
> def country_indexer(context):
>       return _country_indexer(context)
>
> in zcml:
>
> <indexer:register
>      name="getCountry"
>      factory=".extender.country_indexer" />
>
> OR
>
> @indexer(IATDocument, 'getCountry')
> @indexer(IATNewsItem, 'getCountry')
> def country_indexer(context):
>       return _country_indexer(context)
>
> (second parameter could be optional and default to the function name)
>
> in zcml:
>
> <indexer:register factory=".extender.country_indexer" />
>
>
> Jens
> --
> Klein & Partner KG, member of BlueDynamics Alliance
>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Plone-developers mailing list
> Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/plone-developers
>

------------------------------------------------------------------------------

_______________________________________________
Plone-developers mailing list
Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/plone-developers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.