[Zope] SQL tree-crawling and DTML
tom smith
tom@othermedia.com
Sun, 09 Sep 2001 18:56:16 +0100
Hi,
I have a database of entries that have a category. Categories can be nested.
I'm trying to create a method which iteratively calls itself to create a
breadcrumbs trail, like this...
Home / Measurement / Metres/ Centimeters /
... The only problem seems to be
a. I'm using a SQL database to store my categories (each has a
category_id and category_parent_id )
b. (I think ) the namespace doesn't get passed to a DTML method when it
calls itself...
The method is called "tree" and is called like this
"http://myserver.com/myfolder/tree?parent=30" ...
<dtml-if parent>
<dtml-if " parent == '0' ">
<a href="index_html"> Home</a> /
<dtml-else>
<dtml-try>
<dtml-in "category_sql(category_id=parent)">
<dtml-var category_parent_id><a href="category?category_id=<dtml-var
category_id>"><dtml-var category_name></a> /
<dtml-var "tree(parent=category_parent_id)">
</dtml-in>
</dtml-try>
</dtml-if>
</dtml-if>
This works fine if it makes 1 iteration, but fails if it calls itself. I
get..
Error Type: NameError
Error Value: category_sql
Traceback (innermost last):
File G:\zope2.3\lib\python\ZPublisher\Publish.py, line 223, in
publish_module
File G:\zope2.3\lib\python\ZPublisher\Publish.py, line 187, in publish
File G:\zope2.3\lib\python\Zope\__init__.py, line 221, in
zpublisher_exception_hook
(Object: Traversable)
File G:\zope2.3\lib\python\ZPublisher\Publish.py, line 171, in publish
File G:\zope2.3\lib\python\ZPublisher\mapply.py, line 160, in mapply
(Object: tree)
File G:\zope2.3\lib\python\ZPublisher\Publish.py, line 112, in call_object
(Object: tree)
File G:\zope2.3\lib\python\OFS\DTMLMethod.py, line 189, in __call__
(Object: tree)
File G:\zope2.3\lib\python\DocumentTemplate\DT_String.py, line 540, in
__call__
(Object: tree)
File G:\zope2.3\lib\python\DocumentTemplate\DT_Try.py, line 215, in render
File G:\zope2.3\lib\python\DocumentTemplate\DT_Try.py, line 224, in
render_try_except
File G:\zope2.3\lib\python\DocumentTemplate\DT_In.py, line 719, in
renderwob
(Object: category_sql(category_id=parent))
File G:\zope2.3\lib\python\DocumentTemplate\DT_Util.py, line 339, in eval
(Object: tree(parent=category_parent_id))
(Info: tree)
File <string>, line 0, in ?
File G:\zope2.3\lib\python\OFS\DTMLMethod.py, line 182, in __call__
(Object: tree)
File G:\zope2.3\lib\python\DocumentTemplate\DT_String.py, line 540, in
__call__
(Object: tree)
File G:\zope2.3\lib\python\DocumentTemplate\DT_Try.py, line 215, in render
File G:\zope2.3\lib\python\DocumentTemplate\DT_Try.py, line 224, in
render_try_except
File G:\zope2.3\lib\python\DocumentTemplate\DT_In.py, line 655, in
renderwob
(Object: category_sql(category_id=parent))
File G:\zope2.3\lib\python\DocumentTemplate\DT_Util.py, line 339, in eval
(Object: category_sql(category_id=parent))
(Info: category_sql)
File <string>, line 0, in ?
NameError: (see above)
All the objects are in the same Zope folder.
Can anyone help or suggest things to try?
Tom
P.s please cc me as well as replying to the list, thanks...
--
tom smith | tom@othermedia.com | http://www.othermedia.com/blog
0207 089 5959 | Floor 3, The Pavilion, Newhams Lane, London SE1 3UZ