From 68faf9f208f550beb20864e3b09afd8939de42b5 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@esss.se> Date: Fri, 6 Jul 2018 10:09:43 +0200 Subject: [PATCH] Display host creation date and user Add new jinja2 filter to format datetime --- app/factory.py | 3 +++ app/templates/network/view_host.html | 4 ++++ app/utils.py | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/app/factory.py b/app/factory.py index 566091d..d1f7ae5 100644 --- a/app/factory.py +++ b/app/factory.py @@ -27,6 +27,7 @@ from .api.user import bp as user_api from .api.inventory import bp as inventory_api from .api.network import bp as network_api from .commands import register_cli +from . import utils def create_app(config=None): @@ -37,6 +38,8 @@ def create_app(config=None): app.config.from_envvar('LOCAL_SETTINGS', silent=True) app.config.update(config or {}) + app.jinja_env.filters['datetimeformat'] = utils.format_datetime + if not app.debug: import logging # Send ERROR via mail diff --git a/app/templates/network/view_host.html b/app/templates/network/view_host.html index 6489328..72e97a9 100644 --- a/app/templates/network/view_host.html +++ b/app/templates/network/view_host.html @@ -34,6 +34,10 @@ {% endif %} <dt class="col-sm-3">Description</dt> <dd class="col-sm-9">{{ host.description }}</dd> + <dt class="col-sm-3">Created by</dt> + <dd class="col-sm-9">{{ host.user }}</dd> + <dt class="col-sm-3">Created at</dt> + <dd class="col-sm-9">{{ host.created_at | datetimeformat }}</dd> </dl> </div> {% if host.device_type.name.startswith('Virtual') and current_user.is_admin %} diff --git a/app/utils.py b/app/utils.py index 86d9806..bcff931 100644 --- a/app/utils.py +++ b/app/utils.py @@ -210,3 +210,11 @@ def pluralize(singular): return singular + 's' else: return singular + 'es' + + +def format_datetime(value, format='%Y-%m-%d %H:%M'): + """Format a datetime to string + + Function used as a jinja2 filter + """ + return value.strftime(format) -- GitLab