[Grok-dev] Create index catalog in Zope3 management interface
Kevin Teague
kevin at bud.ca
Thu Nov 12 21:56:16 EST 2009
On Nov 12, 2009, at 9:05 AM, Simon Jagoe wrote:
> I have recently started using Grok 1.0 to develop an application. I am
> now looking into indexing items in the ZODB, and one thing I was
> trying to do is add and manipulate catalogs through the Zope3
> management interface at http://localhost:8080/app/++etc++site/ .
>
> I have created a new catalog through the interface, but when I try to
> create index fields to this catalog, I get the traceback below
> (ForbiddenAttribute on the keys() method of my grok.Application) in
> the console. If I use the app.keys() method in my application,
> everything seems to be OK (the zope.manager user does have access to
> this attribute). Do I need to add some rules to the ZCML or is there
> some other way to build indexes after the application has been
> created?
It's easier to just manipulate catalogs programmatically than use the
Zope 3 management interface. The Z3MI isn't being maintained anymore,
so I suspect it will be going away at some point (it's being removed
from the Zope Toolkit, isn't it?)
If you are creating indexes, you can pass a setup callable when you
make a catalog local utility to create the indexes:
def setup_catalog(catalog):
"Configure Indexes upon catalog creation"
catalog['somefield'] = FieldIndex('somefield', ISomeField)
class App(grok.Application, grok.Container):
grok.local_utility(Catalog, provides=ICatalog, name='my_catalog',
setup=setup_catalog)
One nice thing about using Grok vs. ZCML-based apps is that it's easy
to create a View that you can use to try out assorted code as you're
learning or exploring some package. I'll usually plunk in something
like this:
class test(grok.View):
grok.context(App)
def render(self):
# do something here
# then return results via print or set a trace so you can
continue probing some APIs, etc.
import pdb; pdb.set_trace()
More information about the Grok-dev
mailing list