From 67cf797c6ce81d30668b7bea07e05aac516c6fc4 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 22 Nov 2022 11:58:56 +0100 Subject: [PATCH 01/16] fixing name hardDrive in filter --- ereuse_devicehub/inventory/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 41505a8a..b86dca83 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -88,7 +88,7 @@ DEVICES = { ], "Drives & Storage": [ "All DataStorage", - "HardDrives", + "HardDrive", "SolidStageDrive", ], } From 7bf879bbcf608889095560df7f9eb462ac1f849f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 22 Nov 2022 11:59:31 +0100 Subject: [PATCH 02/16] add my_partner for get the partner of one device --- ereuse_devicehub/resources/device/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 0f398737..35e4d559 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -632,6 +632,14 @@ class Device(Thing): return self.binding.device.devicehub_id return self.devicehub_id + @property + def my_partner(self): + if self.placeholder and self.placeholder.binding: + return self.placeholder.binding + if self.binding: + return self.binding.device + return self + @property def get_updated(self): if self.placeholder and self.placeholder.binding: From 796f49f6cf17282ed71a93fa94ef61a8ec986509 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 22 Nov 2022 12:00:17 +0100 Subject: [PATCH 03/16] show correctly the ids in the templates --- ereuse_devicehub/templates/inventory/erasure_list.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html index adaec94f..7573bb4b 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -128,7 +128,7 @@ {% for ac in erasure %} - 0 %} + {% if ac.device.my_partner.lots | length > 0 %}
- {% for lot in ac.device.get_lots_for_template() %} + {% for lot in ac.device.my_partner.get_lots_for_template() %} {{ lot }} {% endfor %}
From a9504b0b717511de27727e89418475be07474ac6 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 23 Nov 2022 13:36:34 +0100 Subject: [PATCH 04/16] first step for pagination --- ereuse_devicehub/inventory/views.py | 7 + .../templates/inventory/erasure_list.html | 175 +++++++----------- 2 files changed, 79 insertions(+), 103 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 1d34a7b3..56eaab1d 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -128,6 +128,13 @@ class ErasureListView(DeviceListMixin): ) if orphans: erasure = [e for e in erasure if e.device.orphan] + + page = int(request.args.get('page', 1)) + per_page = int(request.args.get('per_page', 5)) + + erasure = erasure.paginate(page=page, per_page=per_page) + erasure.first = per_page * erasure.page - per_page + 1 + erasure.last = len(erasure.items) + erasure.first - 1 self.context['erasure'] = erasure diff --git a/ereuse_devicehub/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html index adaec94f..57f660b8 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -110,6 +110,37 @@ {% endif %}
+
+
+ +
+ +
@@ -125,7 +156,7 @@ - {% for ac in erasure %} + {% for ac in erasure.items %}
- {{ ac.snapshot.uuid }} + {{ ac.snapshot.uuid }} @@ -196,6 +227,38 @@
+
+
+ Showing {{ erasure.first }} to {{ erasure.last }} of {{ erasure.total }} entries +
+ +
{% if lot and not lot.is_temporary %}
@@ -225,103 +288,6 @@
-
-
Transfer
-
- {{ form_transfer.csrf_token }} - - {% for field in form_transfer %} - {% if field != form_transfer.csrf_token %} -
- {% if field != form_transfer.type %} - {{ field.label(class_="form-label") }} - {% if field == form_transfer.code %} - * - {% endif %} - {{ field }} - {{ field.description }} - {% if field.errors %} -

- {% for error in field.errors %} - {{ error }}
- {% endfor %} -

- {% endif %} - {% endif %} -
- {% endif %} - {% endfor %} - -
- Cancel - -
-
-
-
-
Delivery Note
-
- {{ form_delivery.csrf_token }} - - {% for field in form_delivery %} - {% if field != form_delivery.csrf_token %} -
- {% if field != form_delivery.type %} - {{ field.label(class_="form-label") }} - {{ field }} - {{ field.description }} - {% if field.errors %} -

- {% for error in field.errors %} - {{ error }}
- {% endfor %} -

- {% endif %} - {% endif %} -
- {% endif %} - {% endfor %} - - {% if lot.transfer and form_receiver.is_editable() %} -
- Cancel - -
- {% endif %} -
-
-
-
Receiver Note
-
- {{ form_receiver.csrf_token }} - - {% for field in form_receiver %} - {% if field != form_receiver.csrf_token %} -
- {% if field != form_receiver.type %} - {{ field.label(class_="form-label") }} - {{ field }} - {{ field.description }} - {% if field.errors %} -

- {% for error in field.errors %} - {{ error }}
- {% endfor %} -

- {% endif %} - {% endif %} -
- {% endif %} - {% endfor %} - - {% if lot.transfer and form_receiver.is_editable() %} -
- Cancel - -
- {% endif %} -
-
{% endif %} @@ -344,11 +310,14 @@ + {% if config['DEBUG'] %} {% else %} From 1efc650beaf12ab1b3dbcaa823d9a6fa29176fbe Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 23 Nov 2022 16:13:30 +0100 Subject: [PATCH 05/16] add simpledatatables --- ereuse_devicehub/templates/inventory/erasure_list.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ereuse_devicehub/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html index 57f660b8..be57db76 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -141,6 +141,7 @@ +
@@ -225,6 +226,7 @@ {% endfor %}
+
@@ -317,6 +319,12 @@ }); }); + {% if config['DEBUG'] %} From ade9fbd018760b554ee3e807c3dc5db7d31bde5a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 23 Nov 2022 19:22:26 +0100 Subject: [PATCH 06/16] add raw query --- ereuse_devicehub/inventory/views.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 56eaab1d..20b0663b 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -118,19 +118,33 @@ class ErasureListView(DeviceListMixin): def dispatch_request(self, orphans=0): self.get_context() self.get_devices(orphans) - if orphans: - self.context['orphans'] = True return flask.render_template(self.template_name, **self.context) def get_devices(self, orphans): + page = int(request.args.get('page', 1)) + per_page = int(request.args.get('per_page', 5)) + erasure = EraseBasic.query.filter_by(author=g.user).order_by( EraseBasic.created.desc() ) if orphans: - erasure = [e for e in erasure if e.device.orphan] - - page = int(request.args.get('page', 1)) - per_page = int(request.args.get('per_page', 5)) + schema = app.config.get('SCHEMA') + sql = f""" + select action.id from {schema}.action as action + inner join {schema}.erase_basic as erase + on action.id=erase.id + inner join {schema}.device as device + on device.id=action.parent_id + inner join {schema}.placeholder as placeholder + on placeholder.binding_id=device.id + where action.parent_id is null or placeholder.kangaroo=true + """ + ids = (e[0] for e in db.session.execute(sql)) + erasure = EraseBasic.query.filter(EraseBasic.id.in_(ids)).order_by( + EraseBasic.created.desc() + ) + self.context['orphans'] = True + # import pdb; pdb.set_trace() erasure = erasure.paginate(page=page, per_page=per_page) erasure.first = per_page * erasure.page - per_page + 1 From 925ce473e6b25f8125a9fea2e55e21e3f57d6443 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 23 Nov 2022 19:22:49 +0100 Subject: [PATCH 07/16] put the correct links --- .../templates/inventory/erasure_list.html | 67 ++++++++----------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/ereuse_devicehub/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html index be57db76..b7af4b97 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -109,8 +109,12 @@
{% endif %} + +
-
+
+ + + + + + + + + + + + + +
+
+
+ {% for f in form_filter %} + {{ f }} + {% endfor %} + +
+
+ +

+ Displaying devices of type + {{ form_filter.filter.data or "Computer" }} +

+ +
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + {% for dev in devices.items %} + {% if dev.placeholder and (not dev.parent_id or dev.parent.placeholder.kangaroo) %} + + + + + + + + + + + + + + + {% endif %} + {% endfor %} + +
SelectTitleDHIDPHIDTypeUnique IdentifiersLifecycle StatusAllocated StatusPhysical StatusUpdated inRegistered in
+ + + + {% if dev.get_type_logo() %} + + {% endif %} + {{ dev.verbose_name }} + + {% if dev.lots | length > 0 %} +
+ {% for lot in dev.get_lots_for_template() %} + {{ lot }} + {% endfor %} +
+ {% endif %} +
+ + {{ dev.devicehub_id }} + + + {{ dev.binding and dev.binding.phid or dev.placeholder and dev.placeholder.phid or '' }} + + {{ dev.is_abstract() }} + + {% for t in dev.tags | sort(attribute="id") %} + {{ t.id }} + {% if not loop.last %},{% endif %} + {% endfor %} + {% if dev.status %}{{ dev.status.type }}{% endif %}{% if dev.allocated_status %}{{ dev.allocated_status.type }}{% endif %}{% if dev.physical_status %}{{ dev.physical_status.type }}{% endif %}{{ dev.get_updated.strftime('%Y-%m-%d %H:%M:%S')}}{{ dev.created.strftime('%Y-%m-%d %H:%M:%S')}} + + + +
+
+
+ Showing {{ devices.first }} to {{ devices.last }} of {{ devices.total }} entries +
+ +
+
+ +
+
+ {% if lot and not lot.is_temporary %} +
+ + +
Documents
+ + + + + + + + + {% for doc in lot.documents %} + + + + + {% endfor %} + {% for doc in lot.trade.documents %} + + + + + {% endfor %} + +
FileUploaded on
+ {% if doc.get_url() %} + {{ doc.file_name}} + {% else %} + {{ doc.file_name}} + {% endif %} + + {{ doc.created.strftime('%Y-%m-%d %H:%M')}} +
+ {% if doc.get_url() %} + {{ doc.file_name}} + {% else %} + {{ doc.file_name}} + {% endif %} + + {{ doc.created.strftime('%Y-%m-%d %H:%M')}} +
+
+
+
Transfer
+
+ {{ form_transfer.csrf_token }} + + {% for field in form_transfer %} + {% if field != form_transfer.csrf_token %} +
+ {% if field != form_transfer.type %} + {{ field.label(class_="form-label") }} + {% if field == form_transfer.code %} + * + {% endif %} + {{ field }} + {{ field.description }} + {% if field.errors %} +

+ {% for error in field.errors %} + {{ error }}
+ {% endfor %} +

+ {% endif %} + {% endif %} +
+ {% endif %} + {% endfor %} + +
+ Cancel + +
+
+
+
+
Delivery Note
+
+ {{ form_delivery.csrf_token }} + + {% for field in form_delivery %} + {% if field != form_delivery.csrf_token %} +
+ {% if field != form_delivery.type %} + {{ field.label(class_="form-label") }} + {{ field }} + {{ field.description }} + {% if field.errors %} +

+ {% for error in field.errors %} + {{ error }}
+ {% endfor %} +

+ {% endif %} + {% endif %} +
+ {% endif %} + {% endfor %} + + {% if lot.transfer and form_receiver.is_editable() %} +
+ Cancel + +
+ {% endif %} +
+
+
+
Receiver Note
+
+ {{ form_receiver.csrf_token }} + + {% for field in form_receiver %} + {% if field != form_receiver.csrf_token %} +
+ {% if field != form_receiver.type %} + {{ field.label(class_="form-label") }} + {{ field }} + {{ field.description }} + {% if field.errors %} +

+ {% for error in field.errors %} + {{ error }}
+ {% endfor %} +

+ {% endif %} + {% endif %} +
+ {% endif %} + {% endfor %} + + {% if lot.transfer and form_receiver.is_editable() %} +
+ Cancel + +
+ {% endif %} +
+
+ {% 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 8f14446a..98894fe5 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -7,11 +7,7 @@