On Tue, May 3, 2011 at 4:46 AM, Phui Hock <phuih...@gmail.com> wrote:
> On May 3, 7:43 am, Russell Keith-Magee <russ...@keith-magee.com>
> wrote:
>> This stems back to the design motivation of Django's template language
>> -- you shouldn't be doing math in the template. Instead, you should be
>> doing your math in the view, and providing the template with a
>> pre-calculated result.
>>
>> So, my inclination would be to say no, this doesn't have a place in
>> the default list of tags.
>>
>> Yours,
>> Russ Magee %-)
>
> The example I provided is a bad one, but the math tag is general
> purpose. It can potentially reduce the number of custom filters or
> amount of work needed in the view function.
>
> Here's another take:
> {% load mathtag %}
>  {% with x=request.GET.x y=request.GET.y z=request.GET.z %}
>    if x = {{ x }}, y = {{ y }}, {{ x }} + {{ y }} = {% math x y "$1 *
> $2" as result %}{{ result }}<br/>
>    if x = {{ x }}, y = {{ y }}, {{ x }} * {{ y }} = {% math x y "$1 *
> $2" as result %}{{ result }}<br/>
>    if x = {{ x }}, y = {{ y }}, z = {{ z }}, ({{ x }}^{{ z }}) *
> ({{ y }}^{{ z }}) = {% math x y z "($1**$3) * ($2**$3)" as result %}
> {{ result }}<br/>
>    if x = {{ x }}, y = {{ y }}, z = {{ z }}, ({{ x }} + {{ y }}) /
> {{ z }} = {% math x y z "($1 + $2) / $3" as result %}{{ result }}<br/>
>  {% endwith %}
>
>
> Given the frequency of such request by other users warrants a re-look
> IMO.
>

Or, in a sane world:

if x = {{ x }}, y = {{ y }},  {{ x }} + {{ y }} = {{ x_plus_y_res }}
if x = {{ x }}, y = {{ y }}, {{ x }} * {{ y }} = {{ x_star_y_res }}

and so on.

There is a reason for view functions, we can express the icky logic
that determines what to display on the page in a nice, concise manner,
and leave the formatting and display of that information to the view
layer.

>From another POV, there is no chance for the designer to screw the
template up and calculate the wrong value, if he is only allowed to
output data.


Cheers

Tom

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

Reply via email to