[Zope] Extending Image via ZClass

Michel Pelletier michel@digicool.com
Wed, 19 Jan 2000 11:33:31 -0500


> -----Original Message-----
> From: James W. Howe [mailto:jwh@allencreek.com]
> Sent: Wednesday, January 19, 2000 11:12 AM
> To: zope@zope.org
> Subject: [Zope] Extending Image via ZClass
> 
> 
> I'm working on creating an extension to Image which will 
> allow a person to 
> include caption and attribution information for an image.  
> I'm calling this 
> a CaptionedImage for lack of a better name.  I've created the 
> ZClass and 
> added property sheets and defined some methods for my views.  
> What I don't 
> know how to do, however, is modify the way the object renders 
> itself by 
> default.  For example, if I use the following:
> 
> <dtml-var CaptionedImageObjectInstance>
> 
> I get an img tag for the image associated with my object.  
> What I want to 
> be able to do is generate my own tags so as to include caption and 
> attribution information in a standard format.  How can I do this?

Overload the __str__ method.  Unless there is some other product or
ZClass someone has made that allready does this, you will need to create
a Python base class and override __str__ there.

It's not a bad idea to have a P Base class anyway.

> Relatedly, does Zope support the notion of "super" in 
> determine which code 
> to evaluate.  For example, in my CaptionedImage object, I 
> would like to 
> override the default behavior of view_image_or_file, but only 
> if caption 
> information was specified.  If no caption information was 
> specified, I 
> would like to let the superclass version of the method be 
> executed.  Is 
> there a way to do this?

In Python, yes:

if caption:
  return self.view_image_or_file()
else:
  return Image.view_image_or_file(self)

In this case, you are explicitly saying you want to use the Image base
class's method.

-Michel