Re: Recursion in templates... again

2007-03-05 Thread Aidas Bendoraitis

It's not so hard to do recursion using templates as well as without them.

1. Write a template tag that takes one menu item as a parameter. I
don't have enough time to write the whole tag this time, but the
example usage should be like this:
{% load recursive_menu %}
{% menu root_category %}
2. It should return the list of its children parsed in an HTML
template or an empty string, if it has no children.
3. The HTML template should include the same template tag for each child.
{% load recursive_menu %}
{% if category.child_set.count %}

{% for item in category.child_set.all() %}
{{ item }}
{% menu item %}
{% endfor %}

{% endif %}

Regards,
Aidas Bendoraitis [aka Archatas]


On 3/5/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> On Mon, 2007-03-05 at 10:31 +0100, Jens Diemer wrote:
> > Chris Moffitt schrieb:
> > > I've implemented a similar hierarchy for categories in Satchmo using
> > > elementtree.  You can see my example here-
> > > http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/shop/templatetags/category_display.py
> >
> > But you have html code in your programm. (The  und  Tags). I
> > don't want to put this in the programm code. All html thing should be
> > stored in the template.
> >
> > To generate a tree menu without a template is very easy ;)
>
> It is not possible to satisfy everybody's wishes and always have both
> "no html in code" and "no full programming language in template system".
> We have chosen the latter, which sometimes means you have to compromise
> on the former. PHP, for example, does it the other way around.
>
> You might say that this situation could be handled "if only we had
> template recursion", but then there would be other cases which are not
> handled and before you know it, the template language is Turing
> complete.
>
> Regards,
> Malcolm
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Recursion in templates... again

2007-03-05 Thread Malcolm Tredinnick

On Mon, 2007-03-05 at 10:31 +0100, Jens Diemer wrote:
> Chris Moffitt schrieb:
> > I've implemented a similar hierarchy for categories in Satchmo using 
> > elementtree.  You can see my example here-
> > http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/shop/templatetags/category_display.py
> 
> But you have html code in your programm. (The  und  Tags). I 
> don't want to put this in the programm code. All html thing should be 
> stored in the template.
> 
> To generate a tree menu without a template is very easy ;)

It is not possible to satisfy everybody's wishes and always have both
"no html in code" and "no full programming language in template system".
We have chosen the latter, which sometimes means you have to compromise
on the former. PHP, for example, does it the other way around.

You might say that this situation could be handled "if only we had
template recursion", but then there would be other cases which are not
handled and before you know it, the template language is Turing
complete.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Recursion in templates... again

2007-03-05 Thread Jens Diemer

Chris Moffitt schrieb:
> I've implemented a similar hierarchy for categories in Satchmo using 
> elementtree.  You can see my example here-
> http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/shop/templatetags/category_display.py

But you have html code in your programm. (The  und  Tags). I 
don't want to put this in the programm code. All html thing should be 
stored in the template.

To generate a tree menu without a template is very easy ;)

-- 
Mfg.

Jens Diemer



CMS in pure Python CGI: http://www.pylucid.org


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Recursion in templates... again

2007-03-02 Thread Chris Moffitt

I've implemented a similar hierarchy for categories in Satchmo using 
elementtree.  You can see my example here-
http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/shop/templatetags/category_display.py

-Chris

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Recursion in templates... again

2007-03-02 Thread Adrián Ribao Martínez

Sorry, I didn't find a perfect solution, but I think that it can be done.
You can use the "unordered list" filter in the template and fill an array in 
the view using recursive methods. Then you pass the array to the filter and 
it's done. You can also create your own filter tag, is not difficult, you can 
find some info in the section "extending the template system"
http://www.djangoproject.com/documentation/templates_python/#extending-the-template-system
and in the several files under the django installation path:
 They're in django/template/defaultfilters.py and 
django/template/defaulttags.py, respectively.

I hope this help you.

Adrian Ribao.

El Viernes, 2 de Marzo de 2007 15:14, Jens Diemer escribió:
> Grupo Django schrieb:
> > Hello, I have been looking around about some information about how to
> > do recursion in templates but what I found didn't help me.
> > ...
> >
> > And the plan is to create a menu like this:
> > - Entry 1
> > -- Subentry 1_1
> > -- Subentry 1_2
> >  sub_Subentry 1_2_1
> > - Entry 2
> > ...
>
> I have the same Problem:
> http://groups.google.com/group/django-users/browse_thread/thread/3bd2812a3d
>0f7700/e97a9cd4348b0471?#e97a9cd4348b0471
>
> Did you find a solution?
>
>
> I found this:
> https://svn.greenpeace.org/projects/custard/browser/production/trunk/melt/a
>pps/custard/templatetags/customtags.py But the code is for an older django
> version. I don't know how to update it...
>
>
> So, if there is no solution, i must use jinja...

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Recursion in templates... again

2007-03-02 Thread Jens Diemer

Grupo Django schrieb:
> Hello, I have been looking around about some information about how to
> do recursion in templates but what I found didn't help me.
> ...
> 
> And the plan is to create a menu like this:
> - Entry 1
> -- Subentry 1_1
> -- Subentry 1_2
>  sub_Subentry 1_2_1
> - Entry 2
> ...

I have the same Problem:
http://groups.google.com/group/django-users/browse_thread/thread/3bd2812a3d0f7700/e97a9cd4348b0471?#e97a9cd4348b0471

Did you find a solution?


I found this:
https://svn.greenpeace.org/projects/custard/browser/production/trunk/melt/apps/custard/templatetags/customtags.py
But the code is for an older django version. I don't know how to update 
it...


So, if there is no solution, i must use jinja...


-- 
Mfg.

Jens Diemer



CMS in pure Python CGI: http://www.pylucid.org


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Recursion in templates... again

2007-02-27 Thread Grupo Django

Hello, I have been looking around about some information about how to
do recursion in templates but what I found didn't help me.
This is the case:

class Menu(models.Model):
id = models.AutoField('id', primary_key=True)
parent = models.ForeignKey('self','id',null=True,blank=True)
name = models.CharField(maxlength=200)

And the plan is to create a menu like this:
- Entry 1
-- Subentry 1_1
-- Subentry 1_2
 sub_Subentry 1_2_1
- Entry 2
...

I have created a custom tag to manage this but so far I only have this
in the template:

{% for entry in menu_list %}
 {{ entry }} 
{% endfor %}


and the customtag def is:

def menu(pos):
menu_list = Menu.objects.all()
return {menu_list': menu_list}

I have no idea how can I solve this problem, I have seen some posts
about this,  but no clean solution.
Thank you!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---