[Zope3-Users] Absolute url of an object

Alen Stanisic alen.stanisic at gmail.com
Fri Feb 10 20:03:38 EST 2006


On Fri, 2006-02-10 at 14:48 -0800, Paulus Zegwaard wrote: 
> But although I understand Zope 3 has something like that too, I'm 
> unclear how to achieve that every object provides an absolute_url 

Objects that are contained provide ILocation interface 

__name__ - object name
__parent__ - container name 

it is container's responsibility to set these and it all happens behind
the scenes and contained objects themselves shouldn't have to worry
about it too much. 

For example if you had something like this

class IPerson(Interface):
	surname = TextLine(title=_(u"Surname"))
	firstName = TextLine(title=_(u"First Name"))

when implementing this interface you would just say it is persistent and
contained:

class Person(Persistent):
	implements(IPerson)

	__name__ = None
	__parent__ = None
	surname = u''
	firstName = u''

OR

from zope.app.container.contained import Contained
class Person(Persistent, Contained):
	implements(IPerson)

	surname = u''
	firstName = u''
	
(This way Contained implements the location stuff - the name and
parent.)

And that should be it. To get absolute url I would do something like 

from zope.app import zapi
zapi.absoluteURL(obj, request)

there is also 

zapi.getPath(obj)

which will return path of the object

For a better explanation of the location concept look up 'location' in
the index of Philipp's book once it arrives.

> A related questions is: is there an obvious way to get the site url (or 
> object) other then just knowing the name?
> 

Not sure about this..


Alen




More information about the Zope3-users mailing list