From 5e2dd3344b073413c33fe9af15046a3e44d806eb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 28 Nov 2022 11:58:42 +0100 Subject: [PATCH] add pagination to snapshots logs --- ereuse_devicehub/inventory/views.py | 9 ++ ereuse_devicehub/parser/models.py | 6 ++ .../templates/inventory/snapshots_list.html | 94 +++++++++++++++++-- 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 59e66e07..69387ab8 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1210,9 +1210,18 @@ class SnapshotListView(GenericMixin): return flask.render_template(self.template_name, **self.context) def get_snapshots_log(self): + page = int(request.args.get('page', 1)) + per_page = int(request.args.get('per_page', PER_PAGE)) + snapshots_log = SnapshotsLog.query.filter( SnapshotsLog.owner == g.user ).order_by(SnapshotsLog.created.desc()) + + snapshots_log = snapshots_log.paginate(page=page, per_page=per_page) + snapshots_log.first = per_page * snapshots_log.page - per_page + 1 + snapshots_log.last = len(snapshots_log.items) + snapshots_log.first - 1 + return snapshots_log + logs = {} for snap in snapshots_log: try: diff --git a/ereuse_devicehub/parser/models.py b/ereuse_devicehub/parser/models.py index 4d298af0..bdd13f73 100644 --- a/ereuse_devicehub/parser/models.py +++ b/ereuse_devicehub/parser/models.py @@ -78,6 +78,12 @@ class SnapshotsLog(Thing): snapshots.append(s) return snapshots and 'Update' or 'New Device' + def get_system_uuid(self): + try: + return self.snapshot.device.system_uuid or '' + except AttributeError: + return '' + class PlaceholdersLog(Thing): """A Placeholder log.""" diff --git a/ereuse_devicehub/templates/inventory/snapshots_list.html b/ereuse_devicehub/templates/inventory/snapshots_list.html index 4c35f44e..1804f364 100644 --- a/ereuse_devicehub/templates/inventory/snapshots_list.html +++ b/ereuse_devicehub/templates/inventory/snapshots_list.html @@ -22,6 +22,38 @@
+
+
+ +
+ +
+
@@ -39,7 +71,7 @@ - {% for snap in snapshots_log %} + {% for snap in snapshots_log.items %}
{% if snap.sid and snap.snapshot_uuid %} @@ -59,26 +91,26 @@ {{ snap.version }} - {% if snap.device %} + {% if snap.get_device() %} - {{ snap.device }} + {{ snap.get_device() }} {% endif %} - {{ snap.system_uuid }} + {{ snap.get_system_uuid() }} - {{ snap.status }} + {{ snap.get_status() }} - {{ snap.new_device }} + {{ snap.get_new_device() }} - {{ snap.type_device }} + {{ snap.get_type_device() }} - {{ snap.original_dhid }} + {{ snap.get_original_dhid() }} {{ snap.created.strftime('%Y-%m-%d %H:%M') }} @@ -93,6 +125,38 @@
+
+
+ Showing {{ snapshots_log.first }} to {{ snapshots_log.last }} of {{ snapshots_log.total }} entries +
+ +
@@ -109,6 +173,18 @@ + {% endblock main %}