On Sep 30, 2005, at 6:33 PM, Duncan McGreggor wrote:
I have a multiple sites on a zope3 instance (folders at the top
level that have their own site managers). In one of them, there is
page content object with a custom view for portraying search
results from its (local) catalog. However, I have had a great deal
of difficulty getting the catalog I want. Here is the pertinent
code for three attempts, the last of which "worked".
Attempt #1
class HomePageView(BrowserView):
def inventoryInStock(self):
catalog = zapi.getUtility(ICatalog,
name='accumac_catalog',
context=self.context)
return catalog.searchResults(equipment_in_stock=[True])
Attempt #2
class HomePageView(BrowserView):
def inventoryInStock(self):
sm = zapi.traverse(self.context, '++etc++site')
catalog = sm['default']['accumac_catalog']
return catalog.searchResults(equipment_in_stock=[True])
Attempt #3
class HomePageView(BrowserView):
def inventoryInStock(self):
sm = zapi.traverse(self.context, '/accumac/++etc++site')
catalog = sm['default']['accumac_catalog']
return catalog.searchResults(equipment_in_stock=[True])
The first attempt got the catalog at the root of the zope 3
instance if I passed no name; if I passed the name of the local
catalog, I got the following error:
ComponentLookupError: (<InterfaceClass
zope.app.catalog.interfaces.ICatalog>, 'accumac_catalog')
A clue as to why this happened may be in attempt #2. The error for
attempt #2 was:
TraversalError: (<accumacsite.homepage.HomePage object at
0x2e688f0>, 'site')
And this might be a clue; it made me think that if the HomePage
content object was traversable, in both attempt #1 and #2, the
correct catalog would have been found.
In attempt #3, I had zope traverse to the absolute location of the
local site manager, and from there got the correct catalog, with
the results being returned properly. However, this last attempt
seems rather hackish, as it uses a path and hard-coded names. I'd
really like to do this the right way.
Does anyone have advice on this?
Hi Duncan. I tried following up on some of the later replies, but I
think it's easier to reply to your first email.
I think that what is tripping you up is the idea of registration
names versus container names.
You can put a utility in any site package, and call it whatever you
want. This will not register it at all, let alone for any given name.
What you need to do next is to actually register the utility with the
placeful (i.e., local to a site in the ZODB, not global in memory)
site manager, so the component architecture will find it. When you
register it, you provide another name, unrelated to the first, that
is the *registration* name.
For instance, if I create a catalog in a site manager in the default
package, I might call it 'site_catalog'). After creation, so far the
only way I can address it is by walking to it through the ZODB (say,
with the container API, or with traversal as you found). I next need
to register this catalog to perform the role of ICatalog in the
site. I can provide a name or not, for this registration; whatever
name I use is the name that will be used for lookup with a getUtility
or queryUtility call.
See http://mail.zope.org/pipermail/zope3-users/2005-September/
001078.html for my attempt at detailed instructions.
Gary
_______________________________________________
Zope3-users mailing list
[email protected]
http://mail.zope.org/mailman/listinfo/zope3-users