Re: Not calling things twice in templates

2013-06-05 Thread Elyézer Mendes Rezende
On Wed, Jun 5, 2013 at 5:59 AM, Sebastian Goll wrote: > As an alternative to the explicit way, how about making the context > dictionary memoizable, i.e. let Django cache each value's object > transparently the first time it is retrieved? I think that caching is a

Re: Not calling things twice in templates

2013-06-05 Thread Sebastian Goll
On Tue, 4 Jun 2013 17:44:36 +0100 "Daniele Procida" wrote: > What about my earlier suggestion that this be dealt with in Python, not in > templates - that the Python programmer decides, for a particular method (or > class, because I guess a class could have an expensive

Re: Not calling things twice in templates

2013-06-05 Thread Tino de Bruijn
I think Shai correctly seperates the concerns. On Tue, Jun 4, 2013 at 11:03 PM, Shai Berger wrote: > But I think that most suggestions focused more on the other issue: How to > enable the only-do-pre-and-post-if-body-not-empty semantics with a > succinct, > clear syntax. >

Re: Not calling things twice in templates

2013-06-04 Thread Shai Berger
On Tuesday 04 June 2013, Daniele Procida wrote: > > [...] the {% with expensive.method as variable %} way of doing things > already exists, [...] What about my earlier suggestion that this be dealt > with in Python, not in templates [...] This thread, from its start, has mixed two separate

Re: Not calling things twice in templates

2013-06-04 Thread Daniele Procida
On Tue, Jun 4, 2013, Andre Terra wrote: >I'm mostly concerned with ambiguous behaviour for the clauses which include >other operands. For example, Looking at the various solutions that have been proposed, I am not at all sure that this is something that the template

Re: Not calling things twice in templates

2013-06-04 Thread Andre Terra
On Mon, Jun 3, 2013 at 7:03 PM, Shai Berger wrote: > > {% with my_bonnet.bees as bees if my_bonnet.bees %} > > {% if my_bonnet.bees with my_bonnet.bees as bees %} > > The only problem I see with these is the repetition -- we could just allow > "as" on {% if %}: > > {% if

Re: Not calling things twice in templates

2013-06-04 Thread Jonathan Slenders
We don't even have to change the for-syntax: {% for bee in my_bonnet.bees %} {% loop %} {{ bee }} {% endloop %} {% empty %} No bees! {% endfor %} Le mardi 4 juin 2013 00:03:12 UTC+2, Shai Berger a écrit : > > > {% for my_bonnet.bees %} > >

Re: Not calling things twice in templates

2013-06-03 Thread Shai Berger
Hi, On Monday 03 June 2013, Andre Terra wrote: > Well, Russ, you asked for suggestions, so here's a couple half-hearted > attempts. > ... and here's a couple of other ones, mostly inspired by those: > {% with my_bonnet.bees as bees if my_bonnet.bees %} > {% if my_bonnet.bees with

Re: Not calling things twice in templates

2013-06-03 Thread Jonathan Slenders
By the way, this could also be implemented using just files. The way {% include %} works for macros. If that's preferred. That becomes: {% decorate "my_special_for.html" data %} {{ i.value }} {% enddecorate %} Le lundi 3 juin 2013 13:38:29 UTC+2, Jonathan Slenders a écrit : > > Hi all.

Re: Not calling things twice in templates

2013-06-03 Thread Jonathan Slenders
Hi all. In the past, I once proposed a decorate template tag, but it was disapproved back then. This would be another solution, to make the template language a lot more powerful. 1. First you define a decorator, for the behaviour you'd like to have. The "data" parameter indicates the receiving

Re: Not calling things twice in templates

2013-06-03 Thread Patryk Zawadzki
2013/6/3 Andre Terra : > Well, Russ, you asked for suggestions, so here's a couple half-hearted > attempts. > > Perhaps we could allow for if clauses in the with block or vice-versa? It > could be argued that it would reduce readability and/or induce confusion > with

Re: Not calling things twice in templates

2013-06-03 Thread Daniele Procida
On Mon, Jun 3, 2013, Russell Keith-Magee wrote: >> But this is another common pattern: >> >> {% if my_bonnet.bees %} >> >> {% for bee in my_bonnet.bees %} >> {{ bee }} >> ... >> >> The problem here is that my_bonnet.bees gets asked

Re: Not calling things twice in templates

2013-06-03 Thread Russell Keith-Magee
On Mon, Jun 3, 2013 at 1:20 PM, Shai Berger wrote: > On Monday 03 June 2013, Russell Keith-Magee wrote: > > Alternatively, add new sub tags to {% for %}: > > > > {% for bee in my_bonnet.bees %} > > {% pre %} > > > > {% body %} > > {{ bee }} > > {% post %} > > > > {%

Re: Not calling things twice in templates

2013-06-02 Thread Shai Berger
On Monday 03 June 2013, Russell Keith-Magee wrote: > Alternatively, add new sub tags to {% for %}: > > {% for bee in my_bonnet.bees %} > {% pre %} > > {% body %} > {{ bee }} > {% post %} > > {% empty %} > No bees in your bonnet. > {% endfor %} > > but that's starting to get verbose, and

Re: Not calling things twice in templates

2013-06-02 Thread Andre Terra
Well, Russ, you asked for suggestions, so here's a couple half-hearted attempts. Perhaps we could allow for if clauses in the with block or vice-versa? It could be argued that it would reduce readability and/or induce confusion with conditional expressions[0], and I would have to agree. {% with

Re: Not calling things twice in templates

2013-06-02 Thread Russell Keith-Magee
On Mon, Jun 3, 2013 at 5:36 AM, Daniele Procida wrote: > The for ... empty pattern in templates is common and useful: < > https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for-empty> > > But this is another common pattern: > > {% if my_bonnet.bees %} > >

Re: Not calling things twice in templates

2013-06-02 Thread Jeremy Dunck
I've had this issue and have used {% with %} or moved the my.bonnet() call into the view/context.I agree, not ideal, but I was never moved to make it better in general. If you're suggesting a general caching layer in the template such that a given expression is only called once in the course

Not calling things twice in templates

2013-06-02 Thread Daniele Procida
The for ... empty pattern in templates is common and useful: But this is another common pattern: {% if my_bonnet.bees %} {% for bee in my_bonnet.bees %} {{ bee }} ... In other words,