[Zope] Debugging and DTML

Hung Jung Lu hungjunglu@hotmail.com
Sat, 08 Jan 2000 08:46:31 PST


administrato-@consotec.de wrote:
original article:http://www.egroups.com/group/zope/?start=20553
>I'm developing a product for ZOPE. Because changes in
>the python and dtml files are not detected I need to
>restart the ZOPE server all the time. Is there a way get around this?

(1) For the python external methods, you have
    click on the method in the management screen,
    and then click on the "Edit" button. You have
    to do this every time you make a change to
    the external python file. I know, the button
    shouldn't be named "Edit": "Update" would be
    more a more appropriate name.

(2) DTML changes are detected. Just make sure
    you click on the "Change" button.

>How can I list a dictionary (e.g the REQUEST) with dtml.
>In python I would do the following:
>for i in REQUEST.keys():
>   print "%s=%s"%(i,REQUEST[i])

(3) <dtml-var REQUEST> prints out all the items. No
    need to iterate. But if you really want to iterate,
    you can do:

    <dtml-in "REQUEST.keys()">

    <dtml-var sequence-item>
    <dtml-var "REQUEST[_['sequence-item']]"><br>

    </dtml-in>

>And with DTML? Here is the peace of dtml I came up with.
>But it doesn't work! I look in documenation but ...
>What is wrong?

(4) "piece", not "peace". :)

><dtml-in "REQUEST.keys()">
>   <b><dtml-var sequence-item>=<dtml-var "REQUEST[sequence-item]" ></b><br>
></dtml-in>

(5) Arghh... see, Zope designers wrote in Python,
    but deep down they were still thinking in Perl.
    Which explains the many bizarre behavior of
    the DTML syntax.

    Anyway, the short answer is: sequence-item is
    not a valid name after you put it in between
    quotes. That is,

    "...   sequence-item ..." is equivalent to
    "...   sequence - item ..."

    So you were performing a subtraction operation,
    without knowing it. :)

    The way out is to access the sequence-item with
    the namespace variable "_". In your case:

    <dtml-in "REQUEST.keys()">
    <b><dtml-var sequence-item> =
       <dtml-var "REQUEST[_['sequence-item']]"</b><br>
    </dtml-in>

    The "_" behaves like a dictionary. But you cannot
    always treat it as an ordinary dictionary. For
    instance, the expressions

    <dtml-var _>
    <dtml-var "_">
    <dtml-in "_.keys()">

    will not work.

    DTML is pretty messy the way it is today.
    It smells like Perl, quacks like Perl,
    waddles like Perl. But... then... it is also free.
    I just wish it were free and as good as Python. :)
    Is that too much to ask? :) (No need to answer,
    it is.) :)

regards,

Hung Jung

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com