RE: [Zope-dev] Rendering of objects in DTML

2003-01-16 Thread Leonardo Rochael Almeida
For the record, by following the same pattern it should be possible to
implement a class that responds to  too, by
implementing __getitem__

On Wed, 2003-01-15 at 06:00, Bjorn Stabell wrote:
> Thanks Leo, this is very helpful.  It should probably be in a HOWTO
> somewhere. :)
> 
> > -Original Message-
> > From: Leonardo Rochael Almeida [mailto:[EMAIL PROTECTED]] 
> > 
> > On Tue, 2003-01-14 at 01:01, Bjorn Stabell wrote:
> > > > Bjorn Stabell wrote:
> > > 
> > > I would like
> > > 
> > >   
> > >   ...
> > >   
> > > 
> > > to call different functions.  The first renders the object, 
> > the second 
> > > returns a mapping of the content's attributes/properties, the third 
> > > checks for "trueness" of the content.  Rendering a content 
> > could be an 
> > > expensive operation and I don't want to do it when doing 
> > dtml-with and 
> > > dtml-if.
> > 
> > 
> > you can do that by having your object be non-callable (or 
> > returning self on __call__) and implementing __str__ where 
> > you can have access to the REQUEST thru self.REQUEST. 
> >  works as expected because you're getting 
> > the object itself. To make  work you should 
> > implement __len__ (if your object implements sequence or 
> > mapping, which it probably doesn't) or __nonzero__. Read the 
> > python docs for details on the implementation of these methods.
> > 
> > Cheers, Leo
> > 
> > -- 
> > Ideas don't stay in some minds very long because they don't 
> > like solitary confinement.
> 
> ___
> Zope-Dev maillist  -  [EMAIL PROTECTED]
> http://lists.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope )
> 
-- 
Ideas don't stay in some minds very long because they don't like
solitary confinement.


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



RE: [Zope-dev] Rendering of objects in DTML

2003-01-14 Thread Bjorn Stabell
Thanks Leo, this is very helpful.  It should probably be in a HOWTO
somewhere. :)

> -Original Message-
> From: Leonardo Rochael Almeida [mailto:[EMAIL PROTECTED]] 
> 
> On Tue, 2003-01-14 at 01:01, Bjorn Stabell wrote:
> > > Bjorn Stabell wrote:
> > 
> > I would like
> > 
> >   
> >   ...
> >   
> > 
> > to call different functions.  The first renders the object, 
> the second 
> > returns a mapping of the content's attributes/properties, the third 
> > checks for "trueness" of the content.  Rendering a content 
> could be an 
> > expensive operation and I don't want to do it when doing 
> dtml-with and 
> > dtml-if.
> 
> 
> you can do that by having your object be non-callable (or 
> returning self on __call__) and implementing __str__ where 
> you can have access to the REQUEST thru self.REQUEST. 
>  works as expected because you're getting 
> the object itself. To make  work you should 
> implement __len__ (if your object implements sequence or 
> mapping, which it probably doesn't) or __nonzero__. Read the 
> python docs for details on the implementation of these methods.
> 
>   Cheers, Leo
> 
> -- 
> Ideas don't stay in some minds very long because they don't 
> like solitary confinement.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



RE: [Zope-dev] Rendering of objects in DTML

2003-01-14 Thread Leonardo Rochael Almeida
On Tue, 2003-01-14 at 01:01, Bjorn Stabell wrote:
> > Bjorn Stabell wrote:
> 
> I would like
> 
>   
>   ...
>   
> 
> to call different functions.  The first renders the object, the second
> returns a mapping of the content's attributes/properties, the third
> checks for "trueness" of the content.  Rendering a content could be an
> expensive operation and I don't want to do it when doing dtml-with and
> dtml-if.


you can do that by having your object be non-callable (or returning self
on __call__) and implementing __str__ where you can have access to the
REQUEST thru self.REQUEST.  works as expected because
you're getting the object itself. To make  work you
should implement __len__ (if your object implements sequence or mapping,
which it probably doesn't) or __nonzero__. Read the python docs for
details on the implementation of these methods.

Cheers, Leo

-- 
Ideas don't stay in some minds very long because they don't like
solitary confinement.


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Rendering of objects in DTML

2003-01-14 Thread Chris Withers
Bjorn Stabell wrote:

I would like

  
  ...
  

to call different functions.  The first renders the object, the second
returns a mapping of the content's attributes/properties, the third
checks for "trueness" of the content.  Rendering a content could be an
expensive operation and I don't want to do it when doing dtml-with and
dtml-if.


That kind of implicit weirdage is not something python encourages.

 ...should render



...is much better.

cheers,

Chris


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope )


RE: [Zope-dev] Rendering of objects in DTML

2003-01-13 Thread Bjorn Stabell
> Bjorn Stabell wrote:
> > Hello,
> > 
> > When a content is rendered by the Zpublisher, its index_html() is 
> > called.  When it is rendered in DTML, e.g., as  content>, its 
> > __call__ method is called.  The __call__ method is also 
> called if the 
> > object appears in  or .  Is it 
> > possible to render these two cases differently from  > content>?
> 
> Which two cases?
> What do you mean by 'differently'?
> 
> cheers,
> 
> Chris

I would like

  
  ...
  

to call different functions.  The first renders the object, the second
returns a mapping of the content's attributes/properties, the third
checks for "trueness" of the content.  Rendering a content could be an
expensive operation and I don't want to do it when doing dtml-with and
dtml-if.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Rendering of objects in DTML

2003-01-13 Thread Chris Withers
Bjorn Stabell wrote:

Hello,

When a content is rendered by the Zpublisher, its index_html() is
called.  When it is rendered in DTML, e.g., as , its
__call__ method is called.  The __call__ method is also called if the
object appears in  or .  Is it
possible to render these two cases differently from ?


Which two cases?
What do you mean by 'differently'?

cheers,

Chris


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope )