[Zope] - Image object enhancements (patch included!)
Phillip J. Eby
pje@telecommunity.com
Tue, 08 Dec 1998 09:05:10 -0500
At 08:58 PM 12/7/98 -0600, Ty Sarna wrote:
>Phillip J. Eby wrote:
>> My ImageFile class for ASDF has a __repr__ method that returns a
>> (more-or-less) absolute URL, and it doesn't break anything,
>> acquisition-wise. I wouldn't worry about it breaking in ZOPE. I define
>> __str__ roughly the same way as in ZOPE (i.e., <IMG SRC="id">), but have
>> __repr__ just return the URL. This makes it easy to do <IMG SRC="<!--#var
>> "`image`"-->" WIDTH=...> stuff.
>
>Cool! Do you mind revealing your technique for getting the URL?
>
I don't mind, but it won't help you unless you're developing in ASDF, and
since I haven't released the source yet... :)
Seriously, there is a relatively easy way to build up an absolute URL for
Zope objects (or at least, this used to work in Principia). So let me give
you that instead. :)
theObject = self
myURL = theObject.id
while hasattr(theObject,'aq_parent') and hasattr(theObject.aq_parent,'id'):
theObject=theObject.aq_parent
myURL = "%s/%s" % (theObject.id,myURL)
Adding on the appropriate REQUEST.BASEx, etc. is left as an exercise for
the reader. :)