From 47736c8679bedc2972553cd8a4c991a061941f29 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 21 Sep 2022 11:35:31 +0200 Subject: [PATCH] add new export actions erasure --- ereuse_devicehub/inventory/views.py | 37 +++++++++++++++++++ .../static/js/main_inventory.build.js | 13 +++++++ ereuse_devicehub/static/js/main_inventory.js | 11 ++++++ .../templates/inventory/erasure_list.html | 5 ++- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 95f140c3..c186b469 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -901,6 +901,43 @@ class ExportsView(View): def actions_erasures(self): data = StringIO() + cw = csv.writer( + data, + delimiter=';', + lineterminator="\n", + quotechar='"', + quoting=csv.QUOTE_ALL, + ) + + cw.writerow( + [ + 'Data Storage Serial', + 'Snapshot ID', + 'Type of Erasure', + 'PHID Erasure Host', + 'Result', + 'Time', + ] + ) + + args = request.args.get('ids') + ids = args.split(',') if args else [] + + query = EraseBasic.query.filter_by(author=g.user) + query = query.filter(EraseBasic.id.in_(ids)) + query = query.order_by(EraseBasic.created.desc()) + + for ac in query: + row = [ + ac.device.serial_number.upper(), + ac.snapshot.uuid, + ac.type, + ac.get_phid(), + ac.severity, + ac.created.strftime('%Y-%m-%d %H:%M:%S'), + ] + cw.writerow(row) + return self.response_csv(data, "Erasures.csv") def build_erasure_certificate(self): diff --git a/ereuse_devicehub/static/js/main_inventory.build.js b/ereuse_devicehub/static/js/main_inventory.build.js index 0ae433c1..f323fa78 100644 --- a/ereuse_devicehub/static/js/main_inventory.build.js +++ b/ereuse_devicehub/static/js/main_inventory.build.js @@ -322,6 +322,19 @@ function export_file(type_file) { } } +function export_actions_erasure(type_file) { + const actions = TableController.getSelectedDevices(); + const actions_id = $.map(actions, (x) => $(x).attr("data-action-erasure")).join(","); + + if (actions_id) { + const url = `/inventory/export/${type_file}/?ids=${actions_id}`; + window.location.href = url; + } else { + $("#exportAlertModal").click(); + } +} + + class lotsSearcher { static enable() { if (this.lotsSearchElement) this.lotsSearchElement.disabled = false; diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 061c82e0..e9600273 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -308,6 +308,17 @@ function export_file(type_file) { } } +function export_actions_erasure(type_file) { + const actions = TableController.getSelectedDevices(); + const actions_id = $.map(actions, (x) => $(x).attr("data-action-erasure")).join(","); + if (actions_id) { + const url = `/inventory/export/${type_file}/?ids=${actions_id}`; + window.location.href = url; + } else { + $("#exportAlertModal").click(); + } +} + class lotsSearcher { static lots = []; diff --git a/ereuse_devicehub/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html index b871b48c..2d93d4bd 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -29,7 +29,7 @@