From 59d4351565835c5c752f7b0d7e146555b2b9cf6c Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Wed, 22 Sep 2010 00:52:15 -0400 Subject: [PATCH] Math filters that've been in use for a bit now --- analyzer/templatetags/math.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 analyzer/templatetags/math.py diff --git a/analyzer/templatetags/math.py b/analyzer/templatetags/math.py new file mode 100644 index 0000000..f08ce57 --- /dev/null +++ b/analyzer/templatetags/math.py @@ -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