I just tried to create a Python Base class for the purpose of overriding Images __str__ method and things didn't quite work as I would have expected. I subclassed Image as follows (using the Renderable product as an example): import Acquisition from OFS import Image class RenderableImage: def __str__ (self): Request = self.REQUEST if Request: try: Method = getattr (self, 'render') except AttributeError: return Image.__str__(self) return Method (self, Request) else: return "Renderable error: no request" I defined a __init__ method to make the class a base class. I then went into my Product and create a new ZClass which used RenderableImage as a base class. Since I was just testing things, I immediately went and tried to create a new instance. No problem creating the object. The problem (or my confusion) was the fact that my RenderableImage didn't inherit any of the views which an Image would normally have (i.e. Edit, Upload, Properties, View, Security). My question is why didn't they show up? I would have thought that absent any other changes to my Image subclass, that the default Image views would show up as the views of my new ZClass. Thanks. James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
On Wed, 19 Jan 2000, James W. Howe wrote:
import Acquisition from OFS import Image
class RenderableImage: def __str__ (self): Request = self.REQUEST if Request: try: Method = getattr (self, 'render') except AttributeError: return Image.__str__(self) return Method (self, Request) else: return "Renderable error: no request"
My question is why didn't they show up? I would have thought that absent any other changes to my Image subclass, that the default Image views would show up as the views of my new ZClass.
If your ZClass is subclassing RenderableImage directly, then I think this is your problem: class RenderableImage: should be: class RenderableImage(Image): The way things stand, your RenderableImage class is not a subclass of Image. Changing the line to read as above fixes that, and will (hopefully) fix the associated problem you describe.
Thanks.
Hope this helps.
James W. Howe
--Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff@goingv.com Going Virtual, L.L.C. http://www.goingv.com/
At 01:20 PM 1/19/00 -0500, you wrote:
I just tried to create a Python Base class for the purpose of overriding Images __str__ method and things didn't quite work as I would have expected. [...] I defined a __init__ method to make the class a base class. I then went into my Product and create a new ZClass which used RenderableImage as a base class. Since I was just testing things, I immediately went and tried to create a new instance. No problem creating the object. The problem (or my confusion) was the fact that my RenderableImage didn't inherit any of the views which an Image would normally have (i.e. Edit, Upload, Properties, View, Security). My question is why didn't they show up? I would have thought that absent any other changes to my Image subclass, that the default Image views would show up as the views of my new ZClass.
I figured it out. It would help to actually subclass from Image. Instead of class RenderableImage: I need to use something like: class RenderableImage(Image): I've done this and things almost work they way I want. The only problem I have now is that when I select a base class for my ZClass, I see two "Image" entries. I currently have the following in my __init__.py file: from RenderableImage import RenderableImage def initialize (context): context.registerBaseClass (RenderableImage) What do I need to do to have the name "RenderableImage" in my base class list instead of two "Image" entries? Thanks. James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
participants (2)
-
James W. Howe -
Jeff K. Hoffman