Has anyone else experienced this? Does anyone else have any experience
to share on tree views? Otherwise I guess its time for a major refactor...
--
--Max Battcher--
http://www.worldmaker.net/
I use a custon template tag to make a tree-like navigation menu by
turning the tree into a straight list with depth information on each
item. My tree structure comes from Flatpages URLs though and not a
recursive model. Anyway I thought it's wise to do all the complex stuff
(be it recursion or otherwise) in Python in the view and have the
template deal with just a straight list.
I was using this already.
> http://code.djangoproject.com/wiki/ModifiedPreorderTreeTraversal
Thanks. That's a start. I was hoping for something a bit wiser and
more generic, though... something to produce nice semantic XHTML
(<ul>s). I'll ponder on this subject a bit more later.
<ul>
{% for node in node_tree %}
<li style="margin-left:{% widthratio node.stack 20 100 %}%">
{{ node.body }}
</li>
{% endfor %}
</ul>
Screenshot of (a more styleshed) output here:
http://static.flickr.com/42/95381035_a51eb622dc_o.png
--
Julio Nobrega - http://www.inerciasensorial.com.br
It's still not semantic (uses presentation style instead of nested
<ul>s). It's looking like if I really want a true list view I need to
build a custom tag. Right now I think I'm just going to spread the tree
out across the URL space.
You might want to take a look at the {% recurse %} tag from the
Custard (Greenpeace) project: https://svn.greenpeace.org/viewvc/
viewcvs.py/custard/production/trunk/melt/apps/custard/templatetags/
customtags.py?rev=539&view=markup
Jacob