diff --git a/atst/app.py b/atst/app.py index d8a781ac..99279958 100644 --- a/atst/app.py +++ b/atst/app.py @@ -10,7 +10,7 @@ from flask_wtf.csrf import CSRFProtect from atst.database import db from atst.assets import environment as assets_environment - +from atst.filters import register_filters from atst.routes import bp from atst.routes.workspaces import bp as workspace_routes from atst.routes.requests import requests_bp @@ -40,6 +40,7 @@ def make_app(config): make_flask_callbacks(app) make_crl_validator(app) + register_filters(app) db.init_app(app) csrf.init_app(app) @@ -77,11 +78,6 @@ def make_flask_callbacks(app): "atat_permissions": [], } - @app.template_filter('iconSvg') - def _iconSvg(name): - with open('static/icons/'+name+'.svg') as contents: - return contents.read() - def map_config(config): return { diff --git a/atst/filters.py b/atst/filters.py new file mode 100644 index 00000000..83dd98fd --- /dev/null +++ b/atst/filters.py @@ -0,0 +1,16 @@ +def iconSvg(name): + with open('static/icons/'+name+'.svg') as contents: + return contents.read() + + +def dollars(value): + try: + numberValue = float(value) + except ValueError: + numberValue = 0 + return "${:,.0f}".format(numberValue) + + +def register_filters(app): + app.jinja_env.filters['iconSvg'] = iconSvg + app.jinja_env.filters['dollars'] = dollars diff --git a/templates/requests.html b/templates/requests.html index 53950e10..a22a884b 100644 --- a/templates/requests.html +++ b/templates/requests.html @@ -116,7 +116,7 @@