Re: [Zope-dev] more __call__ ...

2000-09-27 Thread Chris Withers

Jim Fulton wrote:
  http://a.site/folder/object/myobject
 
  myobject contains dtml-var standard_html_header
  standard_html_header contains dtml-var mynavigator
 
 Is myobject a DTMLMethod? Some kind of container?

Sorry... a good example for myobject would be a DTML Document.

 I don't see how it can contain a var tag if it's not
 DTML.  If it is DTML, I don't see where mynavigator
 fits in.

It is DTML, containing the line dtml-var standard_html_header
standard_html_header is a DTML Method containing dtml-var mynavigator
mynavigator is an object of meta_type 'Navigator' and it's the __call__
method of the Navigator product that I'm having trouble writing :-S

So, if I give my product a class attribute of isDocTemp=1, what
signature should I give my product's __call__ method so it picks up the
DTML namespace?
  
 def __call__(self, ignored, md): ...

This, of coruse, begs the question as to what 'ignored' is, but I
probably don't want to know ;-)

 No: self.nav_header(None, md)

ok..

  In any case, what is self in __call__(self, ...) and what should it be
  in nav_header(self, ...)?
 
 Python method signatures always begin with an argument that is the instance
 to which they are bound.

Okay, so in the __call__ case, self will be the mynavigator object?

Anyway, the isDocTemp thing seems to be getting somewhere.

md is a TemplateDict, and that's a stack of InstanceDict's, right?
Now, from what I've seen from playing, the object I've been looking for
all along is the one whose InstanceDict is on the top of the md stack.

So, two questions:

1. How can I get the top most InstanceDict out of md? is _pop the only
way? If so, I would guess I do:

x = md._pop(1)
md._push(x)

   to get the InstanceDict without disturting the namespace stack?

2. How would I turn the InstanceDict, x, back into an object? From
reading pDocumentTemplate.py, I would guess:

obj = x.self

   Is that right?

well, thanks for all the help, I _think_ the end is in sight now ;-)

cheers,

Chris

PS: Once I've got that object, can I still use aq_chain(obj,1) to get
the list of obj and its containing parents? (In essence, the PARENTS'y
type thing I've been looking for all along ;-)

___
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] more __call__ ...

2000-09-26 Thread Toby Dickenson

On Tue, 26 Sep 2000 16:11:50 +0100, Chris Withers [EMAIL PROTECTED]
wrote:

So, if I give my product a class attribute of isDocTemp=1, what
signature should I give my product's __call__ method so it picks up the
DTML namespace?

Interestingly, Ive just put a HowTo that does this
http://www.zope.org/Members/htrd/howto/FunctionTemplate

This is a wrapper that that lets an old dtml file be replaced with a
python function, without having to update all the old dtml files that
call it.

In other words, Internalized External Methods ;-)

Why? Because Ive only just realized how error-prone non-trivial dtml
can be.(and how ugly error-free dtml is)

hth,



Toby Dickenson
[EMAIL PROTECTED]

___
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] more __call__ ...

2000-09-26 Thread Jim Fulton

Chris Withers wrote:
 
 Jim Fulton wrote:
   So, if I give my product a class attribute of isDocTemp=1, what
   signature should I give my product's __call__ method so it picks up the
   DTML namespace?
 
def __call__(self, ignored, md): ...
 
 Right, now if I call other DTML methods from my __call__ method, can I
 just call them with:

 self.nav_header(self, ignored, md)?

No: self.nav_header(None, md)
 
 In any case, what is self in __call__(self, ...) and what should it be
 in nav_header(self, ...)?

Python method signatures always begin with an argument that is the instance
to which they are bound.
 
(snip)
   In either case, what do I need to go to get hold of what would be
   PARENTS[0-1], if you see what I mean?
 
  I don't see what you mean.
 
 http://a.site/folder/object/myobject
 
 myobject contains dtml-var standard_html_header
 standard_html_header contains dtml-var mynavigator

Is myobject a DTMLMethod? Some kind of container?
I don't see how it can contain a var tag if it's not
DTML.  If it is DTML, I don't see where mynavigator
fits in.
 
 __call__ is a method of the Navigator product, of which mynavigator is
 an instance.
 
 Anyway, in that __call__, self.REQUEST.PARENTS =
 [zope-app,folder,object] (roughly)
 
 By PARENTS[0-1], I meant the myobject object, itself.

Uh OK. 
 
 Hurm, I'm finding this hard to explain clearly, let me know if I'm
 getting closer :-S

OK, you've snipped the orignal question, so I'm off the hook. :)
(I don't really know if you want me to comment on anything
else here.)
 
  I think that if you say:
 
dtml-var expr="foo.bar"
 
  that foo's namespace should take precedence over
  the DTML namespace,
 
 Okay, I see what you mean now :-)
 
   render?
 
  Well, a number of people have suggested that there should
  be a separate render (ie call as subtemlpate) interface.
  Maybe that's what what you meant.
 
 Nope... DT_Var.py line 258:
 def render(self, md):
 ...is what I think the people who mentioned it to me were talking about.

Ok, well that's that's part of the DTML tag interface, which I assume
you aren't interested in.
 
(snip)
   If there's an easier way to get this from within the __call__ method of
   a python product, someone PLEASE tell me! ;-)
 
  aq_chain(x, 1)[-1:] should give this to you, I believe, or
  be very close. :)
 
 Won't that just return x? (hmm... does aq_chain return
 [child,...,parent] or [parent,...,child]?)

[child ... parent]
 
 I think the hard part fo the problem I'm trying to solve is finding out
 what x is from within the __call__ method.
 
 Any help muchly appreciated, sorry this is takign such a long time to
 sort out in my head... ;-)

The Zope debugger is your friend. It's a good way to 
find out some details like this.

Jim

--
Jim Fulton   mailto:[EMAIL PROTECTED]
Technical Director   (888) 344-4332  Python Powered!
Digital Creationshttp://www.digicool.com http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.

___
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 )