List Info

Thread: Template IF statement with <,>,<=,>= (or equvalent)




Template IF statement with <,>,<=,>= (or equvalent)
user name
2006-02-24 12:09:51
Django Template engine seems to be very strate forward yet
powerful,
however I can't for the life of me figure out how to check
if variable1
is greater then or smaller then variable2.

Did a search on this group and looked at the templates doc
and still
can't figure it out. 

It is a Friday in the office; could someone shed some light
in my
direction pls?

-Alen


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Template IF statement with <,>,<=,>= (or equvalent)
user name
2006-02-25 15:56:22
alen.ribicgmail.com wrote:

>Django Template engine seems to be very strate forward
yet powerful,
>however I can't for the life of me figure out how to
check if variable1
>is greater then or smaller then variable2.
>  
>
You can't. Django's philosophy is that this is logic is
probably a small 
part of some buisness logic decision and should be done at
view level.

For less vague answer describe the whole problem: what
exactly are you 
trying to solve with this check?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Template IF statement with <,>,<=,>= (or equvalent)
user name
2006-02-27 08:12:22
Ok in a bit more detail as to what I'm trying to do.

I have a bank statement for a particular account that I wish
to display
as an HTML table.
I have a few statement attributes that come from my RDBMS.
One in
particular named 'amount' that can be a positive or
negative float
value. If its negative, it must show up in the debit column
of the
statement table otherwise must be displayed in the credit
column.

Now, this to me is very much view-based logic and not
business logic. I
say this because its only for the presentation purpose that
we need to
define debit and credit columns and not at business level.
In business
logic, amount is either positive or negative indicating
crediting or
debiting of the account respectively.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Template IF statement with <,>,<=,>= (or equvalent)
user name
2006-02-27 10:42:23
alen.ribicgmail.com wrote:

>I have a bank statement for a particular account that I
wish to display
>as an HTML table.
>I have a few statement attributes that come from my
RDBMS. One in
>particular named 'amount' that can be a positive or
negative float
>value. If its negative, it must show up in the debit
column of the
>statement table otherwise must be displayed in the
credit column.
>
>Now, this to me is very much view-based logic and not
business logic. I
>say this because its only for the presentation purpose
that we need to
>define debit and credit columns and not at business
level. In business
>logic, amount is either positive or negative indicating
crediting or
>debiting of the account respectively.
>  
>
Putting values in columns is indeed presentation logic. But
deciding 
what exactly is "debit" or "credit"
is a business one. Django templates 
pretty much require you to supply this exact distinction
without 
"implementation details" (<0, >=0) even if
these details are so small 
and obvious.

That said you can:

1. Create a list of dicts like [{'amount':0.5, 
'type':'credit'},{'amount':-0.5, 'type':'debit'}]
and then in template 
use {% ifequal item.type 'credit' %}

2. In the Amount class create a method returning its type:

    class Amount():
        def of_type(self):
            return self.value<0 and 'debit' or
'credit'

3. Create a template filter doing the same thing

    def of_type(value, arg):
        return value<0 and 'debit' or 'credit'

and then using it like {% ifequal item|of_type 'credit' %}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Template IF statement with <,>,<=,>= (or equvalent)
user name
2006-02-27 12:48:32
Ok, thanks for your reply again.
I now understand the Django's philosophy in a bit more
detail after
reading the following document:
http://www.djangoproject.com/documentation/design
_philosophies/

I decided to go for the option 1.

-Alen


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Template IF statement with <,>,<=,>= (or equvalent)
user name
2006-02-27 16:10:04
On Mon, Feb 27, 2006 at 01:42:23PM +0300, Ivan Sagalaev
wrote:
> Putting values in columns is indeed presentation logic.
But deciding 
> what exactly is "debit" or
"credit" is a business one. Django templates 
> pretty much require you to supply this exact
distinction without 
> "implementation details" (<0, >=0)
even if these details are so small 
> and obvious.

I was thinking about this too... in my case I've got an
event starting
date and ending date; in my views I want to be able to view
based on
criteria such as: hasn't happened yet, hasn't happened yet
but will happen
sometime this month / quarter / year, happened already this
month/quarter/year.

That sounds like a view criteria to me...   What approach
would you suggest
taking in a case like the one I've just described above?

Thanks.

-- 
Glenn Tenney

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Template IF statement with <,>,<=,>= (or equvalent)
user name
2006-02-27 16:34:26
Glenn Tenney wrote:

>I was thinking about this too... in my case I've got an
event starting
>date and ending date; in my views I want to be able to
view based on
>criteria such as: hasn't happened yet, hasn't happened
yet but will happen
>sometime this month / quarter / year, happened already
this month/quarter/year.
>  
>
You mean displaying events like this:

| Event     | When      |
|-----------|-----------|
| Event 1   | today     |
| Event 2   | next week |

or selecting them from DB like "get all events
starting next week"?

For display I wouldd give the Event model a method returning
a string:

class Event(meta.Model):
    def when(self):
        if self.start_date == datetime.date():
            return 'today'
        if self.start_date == datetime.date()+timedelta(1):
            return 'tomorrow'
        ...

and for selecting just call events.get_list() with
appropriate lookup 
args (http://www.djangoproject.com/documentation/db_ap
i/#field-lookups)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )