[Grok-dev] Using catalog to search for objects of a certain type

jure jcerjak at termitnjak.si
Wed Sep 29 16:05:16 EDT 2010


  At first I was a little confused by your answer, since I'm just 
beginning to grasp the zca concepts, but this was actually pretty 
straightforward, thanks!


jure


import grok
from zope import interface

class IObjectProvidesAdapter(interface.Interface):
     object_provides = interface.Attribute("Provided interfaces")

class ObjectProvidesAdapter(grok.Adapter):
     grok.context(interface.Interface)
     grok.implements(IObjectProvidesAdapter)

     @property
     def object_provides(self):
         return [i.__identifier__ for i in 
interface.providedBy(self.context).flattened()]

class ObjectProvidesIndex(grok.Indexes):
     grok.site(IMySite)
     grok.context(IObjectProvidesAdapter)
     object_provides = index.Text()



On 09/29/2010 08:17 PM, Sebastian Ware wrote:
> You can index methods on an adapter that return the name of the interface or any other calculated data. The interface of the adapter is the context of your index. Have the adapter adapter the objects you want indexed.
>
> Mvh Sebastian
>
> Sent from my iPad
>
> On 29 sep 2010, at 19.55, jure<jcerjak at termitnjak.si>  wrote:
>
>>   Hi,
>>
>> is it possible in Grok to search for objects based on the interface they
>> provide and their location? Something similar to plone's object_provides
>> and path indices:
>>
>>       return catalog(object_provides=ISession.__identifier__,
>>                         path='/'.join(context.getPhysicalPath()),
>>                          ...)
>>
>>
>> Cheers,
>>
>> jure
>> _______________________________________________
>> Grok-dev mailing list
>> Grok-dev at zope.org
>> https://mail.zope.org/mailman/listinfo/grok-dev


More information about the Grok-dev mailing list