[Grok-dev] object relationships

Jeroen Michiel jmichiel at yahoo.com
Fri Jan 30 04:36:01 EST 2009

Martijn Faassen-2 wrote:
> You can do these registrations with the local_utility() directive on the 
> application object. This is nicer as it integrates properly with the 
> rest of the configuration system of Grok. I believe I left hints in the 
> doctest of z3c.relationfield on how to do that.
Guess I missed that one then. I'll try it out!

Martijn Faassen-2 wrote:
>> you also need an IObjectPath implementation, so I did this:
>> class ObjectPath(grok.GlobalUtility):
>>     grok.provides(IObjectPath)
>>     def path(self, obj):
>>         return path(grok.getSite(), obj)
>>     def resolve(self, path):
>>         return resolve(grok.getSite(), path)
> Yup. What's 'path' in this case? full Zope physical paths? That would 
> work or the z3c.objpath impelmentations will help. Perhaps you used 
> those looking at it, and that's good.
That's indeed z3c.objpath I'm using.
But I have a problem with it, if I want to delete my app. Apparently the
grok.getSite() returns the zope.app.folder.folder.Folder my app is part of,
but that doesn't seem to have a __name__ attribute (it's None) so the path
function of objpath raises
TypeError: sequence item 0: expected string, NoneType found
I thought getSite typically returned your Application object, but in this
case it doesn't.
Is this because the app is being destroyed?
How can I safely get to my app object in this case (there is no
grok.getApplication, but I wonder why?)

Martijn Faassen-2 wrote:
> You could mix IHasIncomingRelations into the interface as well, but this 
> works just fine too.

Well, I figured (although my interface is called ReferedData, but that's
just a name), this interface itself doens't have to know it's being refered
to (and how it is done), that's an implementation detail, but I might be
Of course, as the Relation field is part of my ITestData interface, it makes
sense there to mix in IHasOutgoingRelations in the interface. 
In that case I should subclass my interface from IHasOutgoingRelations and
not use the grok.implements directive, right? 

Martijn Faassen-2 wrote:
> This is unfortunately a bit of a workaround, generating the other widget 
> and ignoring the widget for 'rel'. I need to look into making this work 
> properly so you don't have to do this.
That would be wonderful!
Would using another existing widget by using 'custom_widget' possibly work?

Martijn Faassen-2 wrote:
> Here you are. I sure hope you'll stick around on grok-dev and figure 
> more stuff out! Perhaps with my hints included you could turn it into a 
> document we can include on grok.zope.org?

Well, I won't have much choice than to stick around: I chose Grok as a
framework for an internal project at work. So I hope to get some results
quickly, or my boss will start asking questions (well, he already does,
actually) ;-)
I was planning to make a how-to out of this in my free time sometime, to
help out some fellow beginners.
I'm already writing one for using zc.sourcefactory, but haven't finished it

Regards, Jeroen

View this message in context: http://www.nabble.com/object-relationships-tp21706997p21743836.html
Sent from the Grok mailing list archive at Nabble.com.

More information about the Grok-dev mailing list