[Zope] Renderable Base ZClass

Kevin Howe ap619@chebucto.ns.ca
Mon, 1 Nov 1999 17:26:25 -0400


Below is a forward of a discussion about the Renderable Base ZClass Product
and how it could be integrated into the ZOPE Core.

I'd like to see it incorporated into ZClasses - Under the "Basic" tab of the
ZClass, having a selectlist labelled "Render Method" from which you'd choose
the DTML method to be be displayed when the object is called as <!--#var
myObject-->.

Can anyone offer suggestions or comments as to a better way to accomplish
this?

Kevin

-----Original Message-----
From: Alexander Staubo <alex@mop.no>
To: 'Kevin Howe' <ap619@chebucto.ns.ca>
Date: October 31, 1999 10:42 PM
Subject: RE: ZOPE Advice


>I believe __bobo_traverse__() is used exclusively for URL traversal --
>it is, strictly speaking, not involved in acquisition or parent/child
>management, but serves as the means to resolve object paths.
>
>If there is no way to pass REQUEST to __str__(), I believe this is a
>minor shortcoming and should be remedied in the Zope DTML core. Such as
>by testing for the presence of an alternative method called
>__render__(), for example, and using that instead.
>
>Of course, you don't need to use the "with" construct to do what you
>want. You can easily do something like:
>
> <dtml-var "myobject.render(REQUEST = REQUEST)">
>
>if your object needs to get at this.
>
>--
>Alexander Staubo             http://www.mop.no/~alex/
>"In the end, we all assume room temperature." --John Maynard Keynes
>
>> -----Original Message-----
>> From: Kevin Howe [mailto:ap619@chebucto.ns.ca]
>> Sent: 31. oktober 1999 21:31
>> To: alex@mop.no
>> Subject: ZOPE Advice
>>
>>
>> Hi,
>>
>> There was a simple Product named "Renderable Base ZClass"
>> posted on the ZOPE
>> site not long ago, which allows you to print an object like so:
>>
>>     <dtml-var myobject>
>>
>> instead of:
>>
>>     <dtml-with myobject>
>>         <dtml-var render>
>>     </dtml-with>
>>
>> The "render" method is automatically returned if found.
>>
>> It works by using the Python __str__ method to override what
>> gets printed.
>> The problem with this method is that you can't pass REQUEST to it, and
>> therefore can't return "render" as a valid DTML method.
>>
>> I had heard that you could hack the __bobo_traverse__ method to return
>> whatever method you needed, but don't have the ZOPE
>> experience to get it
>> working correctly.
>> I picture it going something of like the code listed below.
>>
>> class Renderable:
>>       def __init__(self):
>>           self.steps=[]
>>
>>      def __bobo_traverse__(self, request, name=''):
>>          if hasattr (self, 'render'):
>>                  self.steps.append('render')
>>                  return self
>>          elif hasattr (self, 'index_html'):
>>                  self.steps.append('index_html')
>>                  return self
>>          else:
>>                   return '<a href=%s>%s</a>' % (self.__name__,
>> self.title_or_id())