[Zope-dev] Re: Renderable Base ZClass

Michel Pelletier michel@digicool.com
Mon, 25 Oct 1999 11:22:47 -0400


> -----Original Message-----
> From: Lalo Martins [mailto:lalo@webcom.com]
> Sent: Sunday, October 24, 1999 3:29 PM
> To: Dave Wood
> Cc: zope-dev@zope.org
> Subject: [Zope-dev] Re: Renderable Base ZClass
> 
> 
> On Sun, Oct 24, 1999 at 11:40:05AM -0300, Dave Wood wrote:
> > Hi,
> > 
> 
> More technical view, if anyone cares:
> 
> What Renderable does is basically define a __str__ method, so
> that we can control what is displayed when we do <dtml-var obj>
> (and obj is of a class derived from Renderable).
> 
> But __str__ is a pure-python feature, so it doesn't get a
> context (REQUEST etc).

As you've discovered, you cannot pass arguments to __str__, therefore
you can't pass REQUEST.

You can, however, try to acquire a context by checking yourself for
REQUEST:

def __str__(self):
  try:
    url = self.REQUEST['URL']
  except:
    raise 'No Context', 'I cant acquire!!'

This works becuase the instance of your ZClass is an
Acquisition.Implicit acquirer.

-Michel