Math filters that've been in use for a bit now
This commit is contained in:
parent
80516e21d5
commit
59d4351565
1 changed files with 27 additions and 0 deletions
27
analyzer/templatetags/math.py
Normal file
27
analyzer/templatetags/math.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
from django.template import Library
|
||||||
|
|
||||||
|
register = Library()
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def mult(value, arg):
|
||||||
|
"Multiplies the arg and the value"
|
||||||
|
return int(value) * int(arg)
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def sub(value, arg):
|
||||||
|
"Subtracts the arg from the value"
|
||||||
|
return int(value) - int(arg)
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def div(value, arg):
|
||||||
|
"Divides the value by the arg"
|
||||||
|
return int(value) / int(arg)
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def getsum(value):
|
||||||
|
if type(value) == dict:
|
||||||
|
return sum(value.values())
|
||||||
|
elif type(value) == list:
|
||||||
|
return sum(value)
|
||||||
|
else:
|
||||||
|
return 0
|
Loading…
Reference in a new issue