Re: [Zope3-Users] zc.relationship or hurry.query and global intid utility

2007-01-08 Thread Stephan Richter
On Sunday 07 January 2007 07:06, Shaar Gabriel wrote:
> > This utility is the one thing you should create before any other object
> > because objects created prior to this utility will never have a unique
> > ID.
>
> a debug session :
> daemon manager not running
> zopectl> start
> . --
> 2007-01-07T13:55:52 INFO root daemonizing the process
> daemon process started, pid=13163
> zopectl> stop
> . daemon process stopped
> zopectl> debug
> No handlers could be found for logger "ZODB.FileStorage"
>
> >>> from zope.component import getUtility
> >>> from zope.app.intid.interfaces import IIntIds
> >>> getUtility(IIntIds)
>
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/lib/zope-3.3.0/lib/python/zope/component/_api.py", line 207,
> in getUtility
>     raise ComponentLookupError(interface, name)
> zope.component.interfaces.ComponentLookupError: ( zope.app.intid.interfaces.IIntIds>, '')

In this case you are not in the context of the root site, which contains the 
registration. You have to get the root folder and do:

getUtility(IIntIds, context=rootFolder)

Alternatively, you can do the hooks.setSite trick I showed in the previous 
example.

BTW, instead of using debug sessions, I would write a quick functional test 
with a pdb.set_trace() call. This way you have everything documented as well.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] zc.relationship or hurry.query and global intid utility

2007-01-07 Thread Shaar Gabriel
Thanks.
this sorted out a few things in my understanding.

On Sunday 07 January 2007 02:56, Stephan Richter wrote:
> On Saturday 06 January 2007 13:14, Gabi Shaar wrote:
> > could somebody point me at a simple example of how to create the intid
> > utility these packages are looking for ?
>
> Here is some code registering the stuff programmatically. Frank already
> told you the correct solution for doing this via the ZMI.
>
> from zope.app import intid
> from zope.app.catalog import catalog
> from zope.app.component import hooks
> from zope.security.proxy import removeSecurityProxy
> from zc.catalog import index, catalogindex
>
>
> # Get the local site manager
> sm = removeSecurityProxy(self.context.getSiteManager())
>
> # Create an intid utility
> if 'ids' not in sm['default']:
> ids = intid.IntIds()
> sm['default']['ids' ] = ids
> sm.registerUtility(ids, intid.interfaces.IIntIds)
>
> # Create a catalog
> ctlg = catalog.Catalog()
> sm['default'][name] = ctlg
> sm.registerUtility(ctlg, zope.app.catalog.interfaces.ICatalog,
>name=name)
>
> # Set the site, so that the indices don't go crazy
> originalSite = hooks.getSite()
> hooks.setSite(self.context)
>
> # Add indices
> ctlg['name'] = catalogindex.ValueIndex('name', IContained)
> ctlg['interfaces'] = InterfacesIndex()
>
> # Reset the site
> hooks.setSite(originalSite)
>
> Regards,
> Stephan
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] zc.relationship or hurry.query and global intid utility

2007-01-07 Thread Shaar Gabriel
hi. thanks for the quick reply.

On Saturday 06 January 2007 21:40, FB wrote:
> On Sat, Jan 06, 2007 at 08:14:52PM +0200, Gabi Shaar wrote:
> > hi.
> > i am trying to use zope 3.3.0
> >
> > first somebody correct me if i'm wrong.
> >
> > getUtility(IIntIds) looks for an intid utility registerd in the global
> > site manager. if i supply a context, then it looks in the local site.
> >
> > i am trying to use zc.relationship and hurry.query. both seem to look for
> > a globally registered intid/catalog utility (at least as i understand
> > it). i can only wrap my brain around how to create a local intid/catalog
> > utility.
> >
> > could somebody point me at a simple example of how to create the intid
> > utility these packages are looking for ?
>
> Go to the site manager:
>
>  http://zopeserver/++etc+site/default
>
> create a IntId-Utility by selecting it from the "Add object" menu. Change
> to the newly create intid, select the "Registration" tab and add a
> registration.

did that. zmi now sais :
This object is registered: 
zope.app.intid.interfaces.IIntIds utility

>
> The next time, getUtility(IIntIds) should return that object.
>
> This utility is the one thing you should create before any other object
> because objects created prior to this utility will never have a unique ID.
>

a debug session :
daemon manager not running
zopectl> start
. --
2007-01-07T13:55:52 INFO root daemonizing the process
daemon process started, pid=13163
zopectl> stop
. daemon process stopped
zopectl> debug
No handlers could be found for logger "ZODB.FileStorage"
>>> from zope.component import getUtility
>>> from zope.app.intid.interfaces import IIntIds
>>> getUtility(IIntIds)
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/zope-3.3.0/lib/python/zope/component/_api.py", line 207, in 
getUtility
raise ComponentLookupError(interface, name)
zope.component.interfaces.ComponentLookupError: (, '')

> Regards,
>
> Frank
> ___
> Zope3-users mailing list
> Zope3-users@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] zc.relationship or hurry.query and global intid utility

2007-01-06 Thread Stephan Richter
On Saturday 06 January 2007 13:14, Gabi Shaar wrote:
> could somebody point me at a simple example of how to create the intid
> utility these packages are looking for ?

Here is some code registering the stuff programmatically. Frank already told 
you the correct solution for doing this via the ZMI.

from zope.app import intid
from zope.app.catalog import catalog
from zope.app.component import hooks
from zope.security.proxy import removeSecurityProxy
from zc.catalog import index, catalogindex


# Get the local site manager
sm = removeSecurityProxy(self.context.getSiteManager())

# Create an intid utility
if 'ids' not in sm['default']:
ids = intid.IntIds()
sm['default']['ids' ] = ids
sm.registerUtility(ids, intid.interfaces.IIntIds)

# Create a catalog
ctlg = catalog.Catalog()
sm['default'][name] = ctlg
sm.registerUtility(ctlg, zope.app.catalog.interfaces.ICatalog,
   name=name)

# Set the site, so that the indices don't go crazy
originalSite = hooks.getSite()
hooks.setSite(self.context)

# Add indices
ctlg['name'] = catalogindex.ValueIndex('name', IContained)
ctlg['interfaces'] = InterfacesIndex()

# Reset the site
hooks.setSite(originalSite)

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] zc.relationship or hurry.query and global intid utility

2007-01-06 Thread FB
On Sat, Jan 06, 2007 at 08:14:52PM +0200, Gabi Shaar wrote:
> hi.
> i am trying to use zope 3.3.0
> 
> first somebody correct me if i'm wrong.
> 
> getUtility(IIntIds) looks for an intid utility registerd in the global site 
> manager.
> if i supply a context, then it looks in the local site.
> 
> i am trying to use zc.relationship and hurry.query. both seem to look for a 
> globally 
> registered intid/catalog utility (at least as i understand it). i can only 
> wrap my brain 
> around how to create a local intid/catalog utility.
> 
> could somebody point me at a simple example of how to create the intid 
> utility these packages 
> are looking for ?

Go to the site manager:

 http://zopeserver/++etc+site/default

create a IntId-Utility by selecting it from the "Add object" menu. Change to the
newly create intid, select the "Registration" tab and add a registration.

The next time, getUtility(IIntIds) should return that object. 

This utility is the one thing you should create before any other object because
objects created prior to this utility will never have a unique ID.

Regards,

Frank
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users