[Zope] Trying to get tree working

Dieter Maurer dieter@handshake.de
Wed, 5 Dec 2001 22:50:59 +0100


Frans C.H. Schneider writes:
 > > Frans C.H. Schneider writes:
 > >  > ...
 > >  > <dtml-let ps_comp=ps_par>
 > >  > <dtml-tree id=ps_comp
 > > branches_expr="ps_childLookup(ps_par=ps_comp)">
 > >  >  <b><dtml-var ps_comp></b> <dtml-var ps_start>
 > >  > </dtml-tree>
 > >  > </dtml-let>
 > >  >
 > >  >
 > >  > It works for the first time but when I try to expand it I
 > > get a key error on
 > >  > ps_par.
 > >  >
 > >  > What goes wrong??
 > > I do not have an answer for your question.
 > >
 > > But you should get a traceback and this traceback should tell you
 > > where the "KeyError" is detected. This may give you a hint...
 > ...
 > This is the traceback.
 > 
 > Error Type: KeyError
 > Error Value: ps_par
 > 
 > Traceback (innermost last):
 >   ....
 >     (Object: bmpsiq)
 >   File /opt/Zope-2.4.2-src/lib/python/DocumentTemplate/DT_Let.py, line 146,
 > in render
 >     (Object: ps_comp=ps_par)
 > KeyError: (see above)
 > 
 > I guess this has to do with the ps_par not being in the namespace the moment
 > I try to expend the tree: it was passed from the calling screen in the first
 > place. If I replace the line with dtml-let ps_comp=ps_par> with dtml-let
 > ps_comp="'partnumber I know'"> it works fine for the item I specify with the
 > partnumber.
I think, I understand:

  *  "ps_par" is a parameter that comes from the request.

  *  When you enter your DTML object for the first time,
     then the request contains a "ps_par" from the form

  *  When you expand a node in the tree, you create a new
     request, but this one is lacking the "ps_par" parameter...

Your options:

  *  There is an "urlparam_expr" patch for Zope's TreeTag
     somewhere on zope.org that would allow you to
     write:

	<dtml-tree .... urlparam_expr="'ps_par=%s' % ps_par" ...>

     to pass the parameter (this assumes, your "ps_par" does not
     contain characters invalid in query strings.
     Otherwise, you would need to "url_quote_plus" the value....

  *  You can use a cookie to pass the value around as I did
     it in my "DocFinder" product

       <http://www.dieter.handshake.de/pyprojects/zope>

     This assumes, your "ps_par" does not contain characters
     invalid in cookies...

  *  If you use sessions anyway, you can store your "ps_par"
     in a session object.


Dieter