diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index d0532c16..f5fb87d6 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -798,6 +798,7 @@ class ExportsView(View): export_ids = { 'metrics': self.metrics, 'devices': self.devices_list, + 'actions_erasures': self.actions_erasures, 'certificates': self.erasure, 'lots': self.lots_export, 'devices_lots': self.devices_lots_export, @@ -898,6 +899,48 @@ class ExportsView(View): insert_hash(res.data) return res + 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 [] + ids = [id.strip() for id in ids] + + 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): erasures = [] for device in self.find_devices(): 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 cf702a40..2d93d4bd 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -29,7 +29,7 @@