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
I have a database of entries that have a category. Categories can be nested. <snip>
a. I'm using a SQL database to store my categories (each has a category_id and category_parent_id )
I have a little rule of thumb that if your data is tabular, stick it in a RDB, if it's tree-like, stick it in an ODB. cheers, Chris
I have a little rule of thumb that if your data is tabular, stick it in a RDB, if it's tree-like, stick it in an ODB.
I have a little rule of thumb, if assistance starts with "I wouldn't start from here if I was you", stick it where the sun don't shine! :-) Tom p.s I'm not storing my data in a relational database out of wilfulness. p.p.s What is your data is part tabular and part tree-like (like most data), where does that leave your thumb? p.p.s Maybe I'd better rephrase my question, here goes... How do I make an iteractive DTML that calls itself AND passes all the namespaces (to things such as ZSQL methods)? Cheers all -- tom smith | tom@othermedia.com | http://www.othermedia.com/blog 0207 089 5959 | Floor 3, The Pavilion, Newhams Lane, London SE1 3UZ
tom smith wrote:
I have a little rule of thumb that if your data is tabular, stick it in a RDB, if it's tree-like, stick it in an ODB.
I have a little rule of thumb, if assistance starts with "I wouldn't start from here if I was you", stick it where the sun don't shine!
:-)
Tom
p.s I'm not storing my data in a relational database out of wilfulness. p.p.s What is your data is part tabular and part tree-like (like most data), where does that leave your thumb? p.p.s Maybe I'd better rephrase my question, here goes...
How do I make an iteractive DTML that calls itself AND passes all the namespaces (to things such as ZSQL methods)?
If you read ZSQL documentation you see that it gets it's args from a few places only so the best advice is to explicitly pass the args you need in your ZSQL-DTML. This is done for security. If you really need to pass some namespace, pass that namespace explicitly and use it from your DTML explicitly. About that tree question (if I remember it correctly) the argument really _has_ to be called parent id everywhere in the tree tag where the original example uses parent_id, so name your ZSQL method's argument parent_id :) btw, I have stopped using that method and have instead written a small class in an External Method that has all the required methods/properties a dtml-tree tag needs. It's not suitable for very deep trees as it read's all of the tree when used, but it can cache it's data so it is not as bad as it sounds in a general case. So even I did start from there when I was you, but I don't do it anymore ;) ------------------ Hannu
I have a little rule of thumb, if assistance starts with "I wouldn't start from here if I was you", stick it where the sun don't shine!
Your un-sunny place must be pretty full ;-)
p.p.s What is your data is part tabular and part tree-like (like most data), where does that leave your thumb?
Store the the tree in the ODB, store the table in a RDB. Wash your thumb afterwards.
How do I make an iteractive DTML that calls itself AND passes all the namespaces (to things such as ZSQL methods)?
Use Python Scripts for logic ;-) If you're a masochist: in my_method: <dtml-var my_method> ...should do it or: <dtml-var "my_method(_.None,_,some='other stuff')"> ...should you want to pass other parameters. Chris
tom smith writes:
... <dtml-var "tree(parent=category_parent_id)">
This works fine if it makes 1 iteration, but fails if it calls itself. I get..
Error Type: NameError Error Value: category_sql DTML objects have two positional parameters, called "client" and "REQUEST". If your DTML object is not trivial, you must pass at least one of them.
If you use a DTML object, say "o", as a "name" attribute to a DTML command, then, it will be called with: o(_.None,_) i.e. "client" is "None" and "REQUEST" is the DTML namespace. More information <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> Dieter
participants (4)
-
Chris Withers -
Dieter Maurer -
Hannu Krosing -
tom smith