The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From:
Jens Diemer <python_gm... @jensdiemer.de>
Date: Tue, 27 Feb 2007 10:52:42 +0100
Local: Tues, Feb 27 2007 4:52 am
Subject: Generate a tree List...
I wand generate a tree menu/sitemap.
How can i make a recursive loop in a template???
In jinja i can use the tag "recurse": http://wsgiarea.pocoo.org/jinja/docs/loops.html#recursion
Here a jinja example: ------------------------------------------------------------------------ context = {'sitemap': [{'href': u'/Index/', 'subitems': [{'href': u'/Index/PhpBBadmin/', 'title': u'phpBBadmin'}], 'title': u'index'}, {'href': u'/ExamplePages/', 'subitems': [{'href': u'/ExamplePages/TextileExample/', 'title': u'complete tinyTextile examples'}, {'href': u'/ExamplePages/Testpage/', 'title': u'a testpage ;)'}, {'href': u'/ExamplePages/SourceCode/', 'title': u'SourceCode'}, {'href': u'/ExamplePages/Contact/', 'title': u'contact'}, {'href': u'/ExamplePages/SiteMap/', 'title': u'SiteMap'}], 'title': u'example pages'}, {'href': u'/Test/', 'title': u'test'}]}
template = """ <h1>Sitemap</h1> <ul> {% for item in sitemap %} <li> <a href="{{ item.href }}">{{ item.title|escapexml }}</a> {% if item.subitems %} <ul>{% recurse item.subitems %}</ul> {% endif %} </li> {% endfor %} </ul> """ ------------------------------------------------------------------------
recurse used the for loop again with the subitems. So i can easy create a recursion.
How can i do this in django?
-- Mfg.
Jens Diemer
---- CMS in pure Python CGI: http://www.pylucid.org
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Joseph Heck" <joseph.h... @gmail.com>
Date: Wed, 28 Feb 2007 13:12:50 -0800
Local: Wed, Feb 28 2007 4:12 pm
Subject: Re: Generate a tree List...
The templates don't support that kind of functionality directly. You'll probably want to create your own template tag that will do for you - you can recurse to your heart's content in Python.
Check out the docs at http://www.djangoproject.com/documentation/templates_python/ for a good overview. Making one is really pretty straightfoward.
On 2/27/07, Jens Diemer <python_gm... @jensdiemer.de> wrote:
> I wand generate a tree menu/sitemap. > How can i make a recursive loop in a template???
> In jinja i can use the tag "recurse": > http://wsgiarea.pocoo.org/jinja/docs/loops.html#recursion
> Here a jinja example: > ------------------------------------------------------------------------ > context = {'sitemap': [{'href': u'/Index/', > 'subitems': [{'href': u'/Index/PhpBBadmin/', > 'title': u'phpBBadmin'}], > 'title': u'index'}, > {'href': u'/ExamplePages/', > 'subitems': [{'href': u'/ExamplePages/TextileExample/', > 'title': u'complete tinyTextile examples'}, > {'href': u'/ExamplePages/Testpage/', > 'title': u'a testpage ;)'}, > {'href': u'/ExamplePages/SourceCode/', > 'title': u'SourceCode'}, > {'href': u'/ExamplePages/Contact/', > 'title': u'contact'}, > {'href': u'/ExamplePages/SiteMap/', > 'title': u'SiteMap'}], > 'title': u'example pages'}, > {'href': u'/Test/', 'title': u'test'}]}
> template = """ > <h1>Sitemap</h1> > <ul> > {% for item in sitemap %} > <li> > <a href="{{ item.href }}">{{ item.title|escapexml }}</a> > {% if item.subitems %} > <ul>{% recurse item.subitems %}</ul> > {% endif %} > </li> > {% endfor %} > </ul> > """ > ------------------------------------------------------------------------
> recurse used the for loop again with the subitems. So i can easy create > a recursion.
> How can i do this in django?
> -- > Mfg.
> Jens Diemer
> ---- > CMS in pure Python CGI: http://www.pylucid.org
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Jeremy Dunck" <jdu... @gmail.com>
Date: Wed, 28 Feb 2007 16:29:25 -0600
Local: Wed, Feb 28 2007 5:29 pm
Subject: Re: Generate a tree List...
On 2/27/07, Jens Diemer <python_gm
... @jensdiemer.de> wrote:
...
> recurse used the for loop again with the subitems. So i can easy create > a recursion.
While I agree with Joseph that writing your own template tag to handle
this is pretty easy, it's worth noting that Jinja spun off of Django's
templating specifically to add things like recursion.
It won't be added to Django core, AFAIK.
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Jens Diemer <python_gm... @jensdiemer.de>
Date: Thu, 01 Mar 2007 09:48:09 +0100
Local: Thurs, Mar 1 2007 3:48 am
Subject: Re: Generate a tree List...
Joseph Heck schrieb:
I don't think this is so easy :(
I found this: https://svn.greenpeace.org/projects/custard/browser/production/trunk/...
But i don't know how i can use this.
Jeremy Dunck schrieb: > It won't be added to Django core, AFAIK. Why? Everyone need this function, if you would like to build a sitemap with a tree.
I think this feature should not be missing in the core. It's a very useful function
-- Mfg.
Jens Diemer
---- CMS in pure Python CGI: http://www.pylucid.org
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Jeremy Dunck" <jdu... @gmail.com>
Date: Thu, 1 Mar 2007 08:35:12 -0600
Local: Thurs, Mar 1 2007 9:35 am
Subject: Re: Generate a tree List...
On 3/1/07, Jens Diemer <python_gm
... @jensdiemer.de> wrote:
Yeah, I'd be careful about the license. I don't see one.
You might contact one of these folks:
https://svn.greenpeace.org/projects/custard/browser/doc/copyright.html But it looks like something like this would do:
x = { 'value':1, 'children': [ { 'value': 2, 'children': []}, {'value' : 3, 'children': [ { 'value':4, 'children':[] } ]} ]} ---- {% recurse through children as node starting with x %} ...do something with node. {% endrecurse %}
> Jeremy Dunck schrieb: > > It won't be added to Django core, AFAIK. > Why? > Everyone need this function, if you would like to build a sitemap with a > tree.
No, not everyone needs this.
http://www.djangobook.com/en/beta/chapter04/#cn210 If you do, consider using Jinja with Django. The HttpResponse just wants a string which Jinja is (of course) capable of creating.
> I think this feature should not be missing in the core. It's a very > useful function
As a programmer, I agree. But the Django templating language is not
only for me, nor am I limited to the Django templating language.
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Jens Diemer <python_gm... @jensdiemer.de>
Date: Fri, 02 Mar 2007 08:29:24 +0100
Local: Fri, Mar 2 2007 2:29 am
Subject: Re: Generate a tree List...
Jeremy Dunck schrieb:
No problem, the source is under the GPL and PyLucid is under GPL, too ;)
> But it looks like something like this would do:
> x = { 'value':1, 'children': [ > { 'value': 2, 'children': []}, > {'value' : 3, 'children': [ > { 'value':4, 'children':[] } > ]} > ]} > ---- > {% recurse through children as node starting with x %} > ...do something with node. > {% endrecurse %}
Thank you for your help! Now, i try it to use it ;)
-- Mfg.
Jens Diemer
---- CMS in pure Python CGI: http://www.pylucid.org
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Jens Diemer <python_gm... @jensdiemer.de>
Date: Fri, 02 Mar 2007 09:03:43 +0100
Local: Fri, Mar 2 2007 3:03 am
Subject: Re: Generate a tree List...
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Jens Diemer <python_gm... @jensdiemer.de>
Date: Fri, 02 Mar 2007 10:21:01 +0100
Local: Fri, Mar 2 2007 4:21 am
Subject: Re: Generate a tree List...
Jeremy Dunck schrieb:
Hm :(
The code is for an older django version.
-- Mfg.
Jens Diemer
---- CMS in pure Python CGI: http://www.pylucid.org
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Jeremy Dunck" <jdu... @gmail.com>
Date: Fri, 2 Mar 2007 08:00:35 -0600
Local: Fri, Mar 2 2007 9:00 am
Subject: Re: Generate a tree List...
On 3/2/07, Jens Diemer <python_gm
... @jensdiemer.de> wrote:
If you want recursion in templates, why not just use Jinja?
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Jens Diemer <python_gm... @jensdiemer.de>
Date: Fri, 02 Mar 2007 15:17:51 +0100
Local: Fri, Mar 2 2007 9:17 am
Subject: Re: Generate a tree List...
Jeremy Dunck schrieb:
> If you want recursion in templates, why not just use Jinja?
Jinja is super cool. But I would like to keep the PyLucid package small.
I thought with django i would choose a full features framework :(
-- Mfg.
Jens Diemer
---- CMS in pure Python CGI: http://www.pylucid.org
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Jeremy Dunck" <jdu... @gmail.com>
Date: Fri, 2 Mar 2007 08:24:07 -0600
Local: Fri, Mar 2 2007 9:24 am
Subject: Re: Generate a tree List...
On 3/2/07, Jens Diemer <python_gm
... @jensdiemer.de> wrote:
> I thought with django i would choose a full features framework :(
It works pretty well for me and many others. Writing a template tag
is a reasonable solution, IMHO. :-/
You must
Sign in before you can post messages.
You do not have the permission required to post.