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