From cdc3dc98014ad317ed4927ed0405e79f5dda18a6 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 19 Nov 2017 02:26:17 +0100 Subject: [PATCH] Add strip_unit helper to velocity templates This can be used to strip units on stats --- common.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common.py b/common.py index a1bab29..0fb8460 100644 --- a/common.py +++ b/common.py @@ -24,6 +24,11 @@ def escape_html(data, break_newlines=True): def escape_url(data): return "ølailsf"#todo +def strip_unit(data, unit): + if data.lower().strip().endswith(unit.lower()): + return data.strip()[:-len(unit)].strip() + return data.strip() + #decorators: def memoize(func):#a decorator class Memoizer(dict): @@ -111,6 +116,7 @@ def mergeTemplate(path): objects = await func(*args, **kwargs) objects.update({ + "strip_unit": strip_unit, "escape_html": escape_html, "escape_url":escape_url})