[Zope] Get caller context

Dragos Chirila d.chirila at finsiel.ro
Thu Apr 8 03:56:05 EDT 2004


Hi again

The definition of the standard_html_header in my folderish object is like
this:

def standard_html_header(self, REQUEST=None, RESPONSE=None):
    ...

I noticed that the caller is/can be self.REQUEST.PARENTS[0]. Only if the
call is made from something folderish.

If I have for instance a DTMLDocument in my folderish object with the
following code:
<dtml-var standard_html_header>
<h2><dtml-var title_or_id></h2>
<p>
This is the <dtml-var id> Document.
</p>
<dtml-var standard_html_footer>

then self.REQUEST.PARENTS[0] is actually my folderish object.

So self.REQUEST.PARENTS[0] works only for folderish "callers".

Regards,
Dragos



> Hi
> Thanks for your answer.
>
> I think that my example was too general. Actually, in my case, myMethod is
> standard_html_header.
> So in my folderish object, standard_html_header is a python method - why I
> did this way?? it's a long story :)
>
> Your solution was one of my choices: whenever I call standard_html_header
> from other objects, to pass the object from where I make the call(like in
> your example).
> BUT, if I want to add other products instances in my folderish object and
> these are calling the standard_html_header normally (e.g. <dtml-var
> standard_html_header>) it will not work, because standard_html_header will
> be rendered in my folderish object's context. And I cannot modify any
> product that I use to make the call for standard_html_header with an extra
> parameter(e.g. caller form your example).
>
> I need a solution that will work in all cases, the call for
> standard_html_header to be made wihtout any extra parameter and the
> standard_html_header to be rendered in the context of the call.
>
> Regards,
> Dragos
>
>
> > I'd pass the caller explicitly, eg.:
> >
> >
> > in the Product:
> >
> > class MyClass(...):
> >
> >      def myMethod(self, caller=None, ...):
> >          if caller is None: caller = self
> >          # do stuff with caller, eg. get a property:
> >          v = caller.some_property
> >          # ...
> >
> >
> >
> > in folderMethod (ZPT):
> >
> > <span tal:replace="python:here.myObject(caller=container, ... )" />
> >
> >
> >
> >
> > Dragos Chirila wrote:
> > > Hi
> > >
> > > I want to identify the object from where the call is made.
> > >
> > > In my example the "caller" is the 'folder' object.
> > >
> > > Regards
> > > Dragos
> > >
> > >
> > >
> > >>Please clarify: do you want to call the myMethod() method or are you
> > >>talking of a HTTP Redirect?
> > >>
> > >>Referer != Caller
> > >>
> > >>
> > >>Dragos Chirila wrote:
> > >>
> > >>>Hi All
> > >>>
> > >>>I have a folderish python object that has a method.
> > >>>I want to be able to call this method using the context of the place
I
> > >
> > > call
> > >
> > >>>it from and not the place where the method is.
> > >>>
> > >>>Example:
> > >>>    ROOT
> > >>>        -----/ myObject (has a python method named myMethod)
> > >>>                       -----/ folder
> > >>>                                    ----/folderMethod (ZPT)
> > >>>
> > >>>I call myMethod of the myObject from the folderMethod of the folder
> > >
> > > object.
> > >
> > >>>I want to execute myMethod in the context of the folder object.
> > >>>
> > >>>I don't want to use REQUEST['HTTP_REFERER'].
> > >>>
> > >>>How can I identify the caller(referer) object of the myMethod?
> > >>>
> > >>>Thanks a lot,
> > >>>Dragos
> > >>>
> > >>>
> > >>>
> > >>>_______________________________________________
> > >>>Zope maillist  -  Zope at zope.org
> > >>>http://mail.zope.org/mailman/listinfo/zope
> > >>>**   No cross posts or HTML encoding!  **
> > >>>(Related lists -
> > >>> http://mail.zope.org/mailman/listinfo/zope-announce
> > >>> http://mail.zope.org/mailman/listinfo/zope-dev )
> > >>
> > >
> > >
> >
>
>
>
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )
>





More information about the Zope mailing list