Hi everyone,
I have been using django with great pleasure and there is a slight
extension to the {% for ... in ... %} default tag I would like to
propose.
I find it useful to have the {% for %} tag syntax extended so that one
can write:
{% for a,b in L %} meaning the obvious thing
Also (maybe more contentious):
{% for i in L1,L2 %} meaning what one would write in python as:
for i in zip(L1,L2)
It is actually a trivial patch to the original ForNode and do_for in
django.template.defaulttags.py to extend {% for ... %} so that it
would accept anything of the form
{% for a_1,a_2,...,a_k in L %} (implying that L is a list of k-uples)
or
{% for a in L1,L2,...,L_n %} (then at each iteration, a will be an n-
uple)
or
{% for a_1,a_2,...a_k in L_1,L_2,...,L_k %} (where each a_i iterates
over L_i in 'parallel')
Provided that no space is allowed between commas and variables (i.e.
a,b NOT a, b) the modification is very simple (only 4 or 5 lines to be
changed). But I have noticed this sort of restriction is already in
place for other tags such as {% cycle ... %} so it would not be an
issue.
This new 'for' does not actually process data, just rearranges them so
that they correspond better to the desired layout. This would allow
transfering some such manipulations from views to templates where I
feel they belong more naturally.
If there is an interest for this I can provide the patch and follow
what procedure is customary for django (which I am not familiar with
yet ;)
--
Arnaud
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---