From 56a7830569f8058d0166bc6d333c565b36fa9ff0 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 17 Apr 2020 19:21:58 +0200 Subject: [PATCH] misc: use mtime of schema as last update time (#41836) --- bijoe/schemas.py | 2 +- bijoe/templates/bijoe/cube.html | 1 + bijoe/templates/bijoe/homepage.html | 6 ++++-- bijoe/templates/bijoe/warehouse.html | 1 + bijoe/utils.py | 7 ++++++- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git bijoe/schemas.py bijoe/schemas.py index 1b4afda..fc75c5e 100644 --- bijoe/schemas.py +++ bijoe/schemas.py @@ -415,7 +415,7 @@ class Cube(Base): class Warehouse(Base): - __slots__ = ['name', 'slug', 'label', 'pg_dsn', 'search_path', 'cubes', 'path'] + __slots__ = ['name', 'slug', 'label', 'pg_dsn', 'search_path', 'cubes', 'path', 'timestamp'] __types__ = { 'name': str, 'slug': str, diff --git bijoe/templates/bijoe/cube.html bijoe/templates/bijoe/cube.html index b0b7845..1d0bf28 100644 --- bijoe/templates/bijoe/cube.html +++ bijoe/templates/bijoe/cube.html @@ -71,6 +71,7 @@ {% trans "Save" %} {% endblock %} +

{% trans "Last update" %} {{ warehouse.timestamp }}

{% else %}
{% trans "Please choose some measures and groupings." %}
{% endif %} diff --git bijoe/templates/bijoe/homepage.html bijoe/templates/bijoe/homepage.html index 2fe0b01..1b3de3b 100644 --- bijoe/templates/bijoe/homepage.html +++ bijoe/templates/bijoe/homepage.html @@ -21,14 +21,16 @@ {% if visualizations %} {% include "bijoe/visualizations_list.html" %} {% else %} - {% trans "No visualizations to display yet." %} + {% trans "No visualizations to display yet." %}) {% endif %} {% if warehouses %}

{% trans "Data sources" %}

{% endif %} diff --git bijoe/templates/bijoe/warehouse.html bijoe/templates/bijoe/warehouse.html index 6625292..7e4f34f 100644 --- bijoe/templates/bijoe/warehouse.html +++ bijoe/templates/bijoe/warehouse.html @@ -12,6 +12,7 @@ {% endblock %} {% block content %} +

{% trans "Last update " %} {{ warehouse.timestamp }}

diff --git bijoe/utils.py bijoe/utils.py index dcc3543..8203d3c 100644 --- bijoe/utils.py +++ bijoe/utils.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import datetime import os import glob import json @@ -21,6 +22,8 @@ import json from django.conf import settings from django.db import connection, transaction from django.utils.translation import ugettext as _ +from django.utils.timezone import utc + try: from functools import lru_cache except ImportError: @@ -41,8 +44,10 @@ def get_warehouses_paths(): @lru_cache() def get_warehouse_by_path_and_mtime(path, mtime): - warehouse = json.load(open(path)) + with open(path) as fd: + warehouse = json.load(fd) warehouse['path'] = path + warehouse['timestamp'] = datetime.datetime.fromtimestamp(os.path.getmtime(path), utc) return Warehouse.from_json(warehouse) -- 2.26.0