Merge pull request #356 from eReuse/feature/3809-new-export-hdds
Feature/3809 new export hdds
This commit is contained in:
commit
06e1aac5a5
|
@ -798,6 +798,7 @@ class ExportsView(View):
|
||||||
export_ids = {
|
export_ids = {
|
||||||
'metrics': self.metrics,
|
'metrics': self.metrics,
|
||||||
'devices': self.devices_list,
|
'devices': self.devices_list,
|
||||||
|
'actions_erasures': self.actions_erasures,
|
||||||
'certificates': self.erasure,
|
'certificates': self.erasure,
|
||||||
'lots': self.lots_export,
|
'lots': self.lots_export,
|
||||||
'devices_lots': self.devices_lots_export,
|
'devices_lots': self.devices_lots_export,
|
||||||
|
@ -898,6 +899,48 @@ class ExportsView(View):
|
||||||
insert_hash(res.data)
|
insert_hash(res.data)
|
||||||
return res
|
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):
|
def build_erasure_certificate(self):
|
||||||
erasures = []
|
erasures = []
|
||||||
for device in self.find_devices():
|
for device in self.find_devices():
|
||||||
|
|
|
@ -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 {
|
class lotsSearcher {
|
||||||
static enable() {
|
static enable() {
|
||||||
if (this.lotsSearchElement) this.lotsSearchElement.disabled = false;
|
if (this.lotsSearchElement) this.lotsSearchElement.disabled = false;
|
||||||
|
|
|
@ -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 {
|
class lotsSearcher {
|
||||||
static lots = [];
|
static lots = [];
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<span class="d-none" id="exportAlertModal" data-bs-toggle="modal" data-bs-target="#exportErrorModal"></span>
|
<span class="d-none" id="exportAlertModal" data-bs-toggle="modal" data-bs-target="#exportErrorModal"></span>
|
||||||
<ul class="dropdown-menu" aria-labelledby="btnExport">
|
<ul class="dropdown-menu" aria-labelledby="btnExport">
|
||||||
<li>
|
<li>
|
||||||
<a href="javascript:export_file('devices')" class="dropdown-item">
|
<a href="javascript:export_actions_erasure('actions_erasures')" class="dropdown-item">
|
||||||
<i class="bi bi-file-spreadsheet"></i>
|
<i class="bi bi-file-spreadsheet"></i>
|
||||||
Data Storage Spreadsheet
|
Data Storage Spreadsheet
|
||||||
</a>
|
</a>
|
||||||
|
@ -64,6 +64,7 @@
|
||||||
<input type="checkbox" class="deviceSelect" data="{{ ac.device.id }}"
|
<input type="checkbox" class="deviceSelect" data="{{ ac.device.id }}"
|
||||||
data-device-type="{{ ac.device.type }}" data-device-manufacturer="{{ ac.device.manufacturer }}"
|
data-device-type="{{ ac.device.type }}" data-device-manufacturer="{{ ac.device.manufacturer }}"
|
||||||
data-device-dhid="{{ ac.device.dhid }}" data-device-vname="{{ ac.device.verbose_name }}"
|
data-device-dhid="{{ ac.device.dhid }}" data-device-vname="{{ ac.device.verbose_name }}"
|
||||||
|
data-action-erasure="{{ ac.id }}"
|
||||||
{% if form_new_allocate.type.data and ac.device.id in list_devices %}
|
{% if form_new_allocate.type.data and ac.device.id in list_devices %}
|
||||||
checked="checked"
|
checked="checked"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -90,7 +91,7 @@
|
||||||
<td>
|
<td>
|
||||||
{{ ac.severity }}
|
{{ ac.severity }}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ ac.created.strftime('%Y-%m-%d %H:%M:%S')}}</td>
|
<td>{{ ac.created.strftime('%Y-%m-%d %H:%M:%S') }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ url_for('inventory.export', export_id='snapshot') }}?id={{ ac.snapshot.uuid }}">
|
<a href="{{ url_for('inventory.export', export_id='snapshot') }}?id={{ ac.snapshot.uuid }}">
|
||||||
<i class="bi bi-box-arrow-up-right"></i>
|
<i class="bi bi-box-arrow-up-right"></i>
|
||||||
|
|
|
@ -260,6 +260,20 @@ def test_export_certificates(user3: UserClientFlask):
|
||||||
assert 'hts54322' in body
|
assert 'hts54322' in body
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.mvp
|
||||||
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||||
|
def test_export_actions_erasure(user3: UserClientFlask):
|
||||||
|
snap = create_device(user3, 'erase-sectors-2-hdd.snapshot')
|
||||||
|
ids = [str(ac.id) for ac in snap.actions if ac.type == 'EraseBasic']
|
||||||
|
ids = ",".join(ids)
|
||||||
|
uri = "/inventory/export/actions_erasures/?ids={id}".format(id=ids)
|
||||||
|
|
||||||
|
body, status = user3.get(uri)
|
||||||
|
assert status == '200 OK'
|
||||||
|
assert "WD-WCAV27984668" in body
|
||||||
|
assert "WD-WCAV29008961" in body
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||||
def test_labels(user3: UserClientFlask):
|
def test_labels(user3: UserClientFlask):
|
||||||
|
|
Reference in a new issue