On Mon, Jun 3, 2013, Russell Keith-Magee <russ...@keith-magee.com> wrote:

>> But this is another common pattern:
>>
>> {% if my_bonnet.bees %}
>>     <ul>
>>         {% for bee in my_bonnet.bees %}
>>             <li>{{ bee }}
>>             ...
>>
>> The problem here is that my_bonnet.bees gets asked for twice, and it could
>> be my.bonnet(), some very expensive function.

>Any other syntax I can think of requires introducing another indentation
>level. Have you got a specific suggestion for how to address this?

Not really. I wasn't even sure if would be considered much of an issue.

But I can think of two:

* introducing a template syntax that means "don't re-fetch"
 
perhaps: !my_bonnet.bees or: my_bonnet.bees.cached

I don't know if the latter would even be possible.


* managing it at the function level

The template author might not even know which functions are expensive. So 
perhaps it should be the function writer's responsibility to make take care of 
this:

    @expensive
    def bees(self):

which will tell the template system not to re-evaluate it while serving the 
same request.


I think I like this second suggestion better, because it keeps templates as 
simple as possible. And this way, the template author won't have to worry about 
keeping up-to-date with re-written functions that have become more expensive or 
less expensive.

Daniele

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to