I know this is a FAQ, but I haven't found the question completely answered anywhere yet. I'm trying to generate a 2-level <dtml-tree> from a pair of SQL tables. I've read anthony's "Some Neat Tricks with dtml-tree" which suggests (with a single table) using a query that returns the children for the specified parent in branches_expr. I've extrapolated from this to make branches_expr a Python script that should query the appropriate table depending if we are trying to draw the children of the root, or their children: if int(parentId) == 0: return container.query.treeCategories() elif int(parentId) > 0: return container.query.treeSubCategories(category=(int(parentId)) (2 tables, category and subcategory) Both queries return 'id' and 'name' fields, where id is unique among sibling nodes (it's a primary key from the tables). However anthony's page mentions a missing 'tpId' attribute, but stops before explaining how to set this, or to spoof it. My tree expands very strangely - expanded branches always contain the top level Categories recursively, not the subcategories. I also saw Tino Wildenhain's posting http://mail.zope.org/pipermail/zope/2000-June/111642.html where he mentioned offsetting the ids to guarantee uniqueness. I thought this might mean all ids have to be unique in the entire tree, so I employed a similar strategy, but it hasn't got me anywhere yet. Can anyone explain how it should be done, or point me to a good example? Thanks in advance Will -- Will Stephenson
Will Stephenson wrote at 2003-11-19 17:28 +0000:
... However anthony's page mentions a missing 'tpId' attribute, but stops before explaining how to set this, or to spoof it. My tree expands very strangely - expanded branches always contain the top level Categories recursively, not the subcategories.
Look at the "id" attribute of "dtml-tree". More generally, read the "dtml-tree" documentation. -- Dieter
On Thursday 20 November 2003 18:37, Dieter Maurer wrote:
Will Stephenson wrote at 2003-11-19 17:28 +0000:
... However anthony's page mentions a missing 'tpId' attribute, but stops before explaining how to set this, or to spoof it. My tree expands very strangely - expanded branches always contain the top level Categories recursively, not the subcategories.
Look at the "id" attribute of "dtml-tree". More generally, read the "dtml-tree" documentation.
I had set id=objectid, but my level 2 query didn't return a field called 'objectid', <p>Category tree view (not working) <p> <dtml-let objectid="0"> <dtml-tree id=objectid branches_expr="makeTree(parentId=objectid)"> <b><dtml-var name></b> </dtml-tree> </dtml-let> I was confused and called it 'tpId'. So now I have a tree which appears to obtain level 2 branches correctly, because it only shows + expander signs next to the level 1 branches that have children. But when I try to expand these branches, I get a "Error Type: TypeError Error Value: object of type 'long int' is not callable" error. I'm running in debug mode but there isn't a backtrace in the error page as rendered or its source. I can see I'm passing an int to a method that requires a callable object, but I can't find out what the parameter name my queries' output is getting wrong is, or what the correct type for it is. How can I get a slightly more informative error? TIA Will makeTree: if int(parentId) == 0: return container.treeCats() elif int(parentId) > 0: return container.treeSubCats(category=int(parentId)) treeCats: select id as objectid, 0 as parent, concat('/viewCategory?category=', id) as tpURL, name from category treeSubCats: SELECT id + 1000 * <dtml-sqlvar category type=int> as objectid, name, <dtml-sqlvar category type=int> as parent, 'foo' as tpURL FROM subcategory WHERE <dtml-sqltest category type=int> -- Will Stephenson IRC: Bille
Will Stephenson wrote at 2003-11-23 09:55 +0000:
... But when I try to expand these branches, I get a "Error Type: TypeError Error Value: object of type 'long int' is not callable" error. I'm running in debug mode but there isn't a backtrace in the error page as rendered or its source.
From Zope 2.6 on, tracebacks can be found via
<http://<yourZope>/error_log> -- Dieter
On Sunday 23 November 2003 19:24, Dieter Maurer wrote:
Will Stephenson wrote at 2003-11-23 09:55 +0000:
... But when I try to expand these branches, I get a "Error Type: TypeError Error Value: object of type 'long int' is not callable" error. I'm running in debug mode but there isn't a backtrace in the error page as rendered or its source.
From Zope 2.6 on, tracebacks can be found via
Thanks again for all the help, Dieter. The traceback looks like this. <snip> * Module TreeDisplay.TreeTag, line 451, in tpRenderTABLE __traceback_info__: (['AAAAAAAAIi4=', [[1, []]]], {'childless_decoration': '', 'id': 'objectid', 'branches_expr': <method Eval.eval of Eval instance at 0x8e43e24>, 'url': 'tpURL'}, [['AAAAAAAAIi4=', [[1, []]]]], [['AAAAAAAAIi4=', [[1, []]]]]) * Module TreeDisplay.TreeTag, line 442, in tpRenderTABLE __traceback_info__: ([1, []], {'childless_decoration': '', 'id': 'objectid', 'branches_expr': <method Eval.eval of Eval instance at 0x8e43e24>, 'url': 'tpURL'}, [['AAAAAAAAIi4=', [[1, []]]]], [[1, []]]) tpRenderTABLE calls itself recursively and then dies atTreeDisplay.TreeTag, line 442: if not simple_type(type(id)): id=id() reading up, __traceback_info__=sub, args, state, substate, so the value of id at this point is 'objectid' - which according to my queries is an int. Why does this simple_type(...) function return false? I'm really grateful for any help. Will -- Will Stephenson
Will Stephenson wrote at 2003-11-24 08:27 +0000:
...
I get a "Error Type: TypeError
Error Value: object of type 'long int' is not callable" error.
...
tpRenderTABLE calls itself recursively and then dies atTreeDisplay.TreeTag, line 442:
if not simple_type(type(id)): id=id()
reading up, __traceback_info__=sub, args, state, substate, so the value of id at this point is 'objectid' - which according to my queries is an int.
Why does this simple_type(...) function return false?
"simple_type" forgets to handle "long int" as simple. Please file a bug report to "<http://www.zope.org/Collectors/Zope>". -- Dieter
participants (2)
-
Dieter Maurer -
Will Stephenson