new templatetags added

This commit is contained in:
Serghei Mihai 2014-10-09 10:28:12 +02:00
parent 1687bb23ba
commit 06692d683e
1 changed files with 30 additions and 0 deletions

View File

@ -1,4 +1,8 @@
from django import template
from django.template.defaultfilters import stringfilter
from datetime import datetime, date
from decimal import Decimal
register = template.Library()
@ -12,3 +16,29 @@ def user_in_group(context, group):
def user_in_group_prefix(context, group):
user = context['user']
return user.groups.filter(name__startswith=group).exists()
@register.filter
@stringfilter
def to_date(value, date_format='%Y-%m-%d'):
"""
converts date string into datetime object in order to be
used(for ex: reformated) in template
"""
return datetime.strptime(value, date_format)
@register.filter
def to_decimal(value):
"""
converts into Decimal object
"""
return Decimal(value)
@register.filter
def is_past(value):
"""
checks if date is in the past
"""
return value.date() < date.today()