[Zope] <dtml-tree> from multiple SQL tables

Will Stephenson lists at stevello.free-online.co.uk
Wed Nov 19 12:28:15 EST 2003


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



More information about the Zope mailing list