From abc773fe6e9e16fa14749403ee77f65370791333 Mon Sep 17 00:00:00 2001
From: Cayo Puigdefabregas
Date: Fri, 25 Nov 2022 18:56:56 +0100
Subject: [PATCH 1/4] add pagination in all list of devices
---
ereuse_devicehub/inventory/views.py | 20 +-
.../templates/inventory/all_device_list.html | 671 ------------------
.../templates/inventory/device_list.html | 119 +++-
3 files changed, 125 insertions(+), 685 deletions(-)
delete mode 100644 ereuse_devicehub/templates/inventory/all_device_list.html
diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py
index 7e4d8ef8..59e66e07 100644
--- a/ereuse_devicehub/inventory/views.py
+++ b/ereuse_devicehub/inventory/views.py
@@ -64,9 +64,17 @@ class DeviceListMixin(GenericMixin):
def get_context(self, lot_id=None, all_devices=False):
super().get_context()
+ page = int(request.args.get('page', 1))
+ per_page = int(request.args.get('per_page', PER_PAGE))
+ filter = request.args.get('filter', "All+Computers")
+ # import pdb; pdb.set_trace()
+
lots = self.context['lots']
form_filter = FilterForm(lots, lot_id, all_devices=all_devices)
- devices = form_filter.search()
+ devices = form_filter.search().paginate(page=page, per_page=per_page)
+ devices.first = per_page * devices.page - per_page + 1
+ devices.last = len(devices.items) + devices.first - 1
+
lot = None
form_transfer = ''
form_delivery = ''
@@ -95,6 +103,7 @@ class DeviceListMixin(GenericMixin):
'tags': self.get_user_tags(),
'list_devices': self.get_selected_devices(form_new_action),
'all_devices': all_devices,
+ 'filter': filter,
}
)
@@ -161,17 +170,8 @@ class DeviceListView(DeviceListMixin):
class AllDeviceListView(DeviceListMixin):
- template_name = 'inventory/all_device_list.html'
-
def dispatch_request(self):
self.get_context(all_devices=True)
- # import pdb; pdb.set_trace()
- page = int(request.args.get('page', 1))
- per_page = int(request.args.get('per_page', PER_PAGE))
- devices = self.context['devices'].paginate(page=page, per_page=per_page)
- devices.first = per_page * devices.page - per_page + 1
- devices.last = len(devices.items) + devices.first - 1
- self.context['devices'] = devices
return flask.render_template(self.template_name, **self.context)
diff --git a/ereuse_devicehub/templates/inventory/all_device_list.html b/ereuse_devicehub/templates/inventory/all_device_list.html
deleted file mode 100644
index 79ff81cd..00000000
--- a/ereuse_devicehub/templates/inventory/all_device_list.html
+++ /dev/null
@@ -1,671 +0,0 @@
-{% extends "ereuse_devicehub/base_site.html" %}
-{% block main %}
-
-
-
Inventory
-
-
-
-
-
-
-
-
-
- {% if lot %}
-
-
-
-
-
-
-
- {% if lot.is_temporary or not lot.transfer.closed %}
-
- {% if lot and lot.is_temporary %}
-
- Create Outgoing Lot
-
-
- Create Incoming Lot
-
- {% endif %}
-
- Delete Lot
-
-
- {% endif %}
-
-
-
- {% endif %}
-
-
- {% if lot %}
-
-
- -
-
-
-
- {% if lot and not lot.is_temporary %}
- -
-
-
-
- {% if lot.transfer %}
- -
-
-
- -
-
-
- -
-
-
- {% endif %}
- {% endif %}
-
-
- {% endif %}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- If this text is showing is because there are an error
-
-
-
-
-
-
- Displaying devices of type
- {{ form_filter.filter.data or "Computer" }}
-
-
-
-
-
-
-
-
-
-
-
-
-
- Showing {{ devices.first }} to {{ devices.last }} of {{ devices.total }} entries
-
-
-
-
-
-
-
- {% if lot and not lot.is_temporary %}
-
-
-
-
Documents
-
-
-
- File |
- Uploaded on |
-
-
-
- {% for doc in lot.documents %}
-
-
- {% if doc.get_url() %}
- {{ doc.file_name}}
- {% else %}
- {{ doc.file_name}}
- {% endif %}
- |
-
- {{ doc.created.strftime('%Y-%m-%d %H:%M')}}
- |
-
- {% endfor %}
- {% for doc in lot.trade.documents %}
-
-
- {% if doc.get_url() %}
- {{ doc.file_name}}
- {% else %}
- {{ doc.file_name}}
- {% endif %}
- |
-
- {{ doc.created.strftime('%Y-%m-%d %H:%M')}}
- |
-
- {% endfor %}
-
-
-
-
-
-
- {% endif %}
-
-
-
-
-
-
-
-
-
-
-
-{% include "inventory/lot_delete_modal.html" %}
-{% include "inventory/actions.html" %}
-{% include "inventory/allocate.html" %}
-{% include "inventory/data_wipe.html" %}
-{% include "inventory/trade.html" %}
-{% include "inventory/alert_export_error.html" %}
-{% include "inventory/alert_lots_changes.html" %}
-
-
-
-
-{% if config['DEBUG'] %}
-
-{% else %}
-
-{% endif %}
-
-
-{% endblock main %}
diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html
index 98894fe5..78c3e39d 100644
--- a/ereuse_devicehub/templates/inventory/device_list.html
+++ b/ereuse_devicehub/templates/inventory/device_list.html
@@ -7,7 +7,11 @@
- Inventory
{% if not lot %}
- - Unassigned
+ {% if all_devices %}
+ - All devices
+ {% else %}
+ - Unassigned
+ {% endif %}
{% elif lot.is_temporary %}
- Temporary Lot
- {{ lot.name }}
@@ -226,10 +230,17 @@
-
+ {% if not all_devices %}
Devices Lots Spreadsheet
+ {% else %}
+
+
+ Devices Lots Spreadsheet
+
+ {% endif %}
-
@@ -324,6 +335,8 @@
{% for f in form_filter %}
{{ f }}
{% endfor %}
+
+
@@ -333,6 +346,38 @@
{{ form_filter.filter.data or "Computer" }}
+
+
+
+
+
+
+
+
@@ -351,7 +396,7 @@
- {% for dev in devices %}
+ {% for dev in devices.items %}
{% if dev.placeholder and (not dev.parent_id or dev.parent.placeholder.kangaroo) %}
@@ -410,6 +455,57 @@
{% endfor %}
|
+
+
+ Showing {{ devices.first }} to {{ devices.last }} of {{ devices.total }} entries
+
+
+
+
@@ -581,10 +677,25 @@
{% include "inventory/alert_lots_changes.html" %}
+
{% if config['DEBUG'] %}
From 5e2dd3344b073413c33fe9af15046a3e44d806eb Mon Sep 17 00:00:00 2001
From: Cayo Puigdefabregas
Date: Mon, 28 Nov 2022 11:58:42 +0100
Subject: [PATCH 2/4] 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 %}
From f9d679547fafe767c37f15f46bf22d8f94081030 Mon Sep 17 00:00:00 2001
From: Cayo Puigdefabregas
Date: Mon, 28 Nov 2022 12:30:02 +0100
Subject: [PATCH 3/4] pagination in placeholder logs
---
ereuse_devicehub/inventory/views.py | 42 ++--------
.../inventory/placeholder_log_list.html | 80 ++++++++++++++++++-
2 files changed, 85 insertions(+), 37 deletions(-)
diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py
index 69387ab8..fe1c37e7 100644
--- a/ereuse_devicehub/inventory/views.py
+++ b/ereuse_devicehub/inventory/views.py
@@ -1222,41 +1222,6 @@ class SnapshotListView(GenericMixin):
snapshots_log.last = len(snapshots_log.items) + snapshots_log.first - 1
return snapshots_log
- logs = {}
- for snap in snapshots_log:
- try:
- system_uuid = snap.snapshot.device.system_uuid or ''
- except AttributeError:
- system_uuid = ''
-
- if snap.snapshot_uuid not in logs:
- logs[snap.snapshot_uuid] = {
- 'sid': snap.sid,
- 'snapshot_uuid': snap.snapshot_uuid,
- 'version': snap.version,
- 'device': snap.get_device(),
- 'system_uuid': system_uuid,
- 'status': snap.get_status(),
- 'severity': snap.severity,
- 'created': snap.created,
- 'type_device': snap.get_type_device(),
- 'original_dhid': snap.get_original_dhid(),
- 'new_device': snap.get_new_device(),
- }
- continue
-
- if snap.created > logs[snap.snapshot_uuid]['created']:
- logs[snap.snapshot_uuid]['created'] = snap.created
-
- if snap.severity > logs[snap.snapshot_uuid]['severity']:
- logs[snap.snapshot_uuid]['severity'] = snap.severity
- logs[snap.snapshot_uuid]['status'] = snap.get_status()
-
- result = sorted(logs.values(), key=lambda d: d['created'])
- result.reverse()
-
- return result
-
class SnapshotDetailView(GenericMixin):
template_name = 'inventory/snapshot_detail.html'
@@ -1385,10 +1350,17 @@ class PlaceholderLogListView(GenericMixin):
return flask.render_template(self.template_name, **self.context)
def get_placeholders_log(self):
+ page = int(request.args.get('page', 1))
+ per_page = int(request.args.get('per_page', PER_PAGE))
+
placeholder_log = PlaceholdersLog.query.filter(
PlaceholdersLog.owner == g.user
).order_by(PlaceholdersLog.created.desc())
+ placeholder_log = placeholder_log.paginate(page=page, per_page=per_page)
+ placeholder_log.first = per_page * placeholder_log.page - per_page + 1
+ placeholder_log.last = len(placeholder_log.items) + placeholder_log.first - 1
+
return placeholder_log
diff --git a/ereuse_devicehub/templates/inventory/placeholder_log_list.html b/ereuse_devicehub/templates/inventory/placeholder_log_list.html
index aaff827d..bc16ccab 100644
--- a/ereuse_devicehub/templates/inventory/placeholder_log_list.html
+++ b/ereuse_devicehub/templates/inventory/placeholder_log_list.html
@@ -22,6 +22,38 @@
+
+
+
+
+
+
+
+
@@ -34,7 +66,7 @@
- {% for log in placeholders_log %}
+ {% for log in placeholders_log.items %}
{{ log.phid }}
@@ -58,6 +90,38 @@
{% endfor %}
|
+
+
+ Showing {{ placeholders_log.first }} to {{ placeholders_log.last }} of {{ placeholders_log.total }} entries
+
+
+
@@ -75,6 +139,18 @@
+
{% endblock main %}
From 3757873b0255d80bc3a1ebe7d127064e53ecde0e Mon Sep 17 00:00:00 2001
From: Cayo Puigdefabregas
Date: Mon, 28 Nov 2022 13:12:14 +0100
Subject: [PATCH 4/4] fix bug Title tag in erasure list
---
ereuse_devicehub/templates/inventory/erasure_list.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ereuse_devicehub/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html
index ffae9b16..2f36de71 100644
--- a/ereuse_devicehub/templates/inventory/erasure_list.html
+++ b/ereuse_devicehub/templates/inventory/erasure_list.html
@@ -22,7 +22,7 @@
- All hard drivers
+ All hard drives