Merge pull request #356 from eReuse/feature/3809-new-export-hdds

Feature/3809 new export hdds
This commit is contained in:
cayop 2022-09-21 12:22:46 +02:00 committed by GitHub
commit 06e1aac5a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 84 additions and 2 deletions

View file

@ -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():

View file

@ -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;

View file

@ -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 = [];

View file

@ -29,7 +29,7 @@
<span class="d-none" id="exportAlertModal" data-bs-toggle="modal" data-bs-target="#exportErrorModal"></span>
<ul class="dropdown-menu" aria-labelledby="btnExport">
<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>
Data Storage Spreadsheet
</a>
@ -64,6 +64,7 @@
<input type="checkbox" class="deviceSelect" data="{{ ac.device.id }}"
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-action-erasure="{{ ac.id }}"
{% if form_new_allocate.type.data and ac.device.id in list_devices %}
checked="checked"
{% endif %}
@ -90,7 +91,7 @@
<td>
{{ ac.severity }}
</td>
<td>{{ ac.created.strftime('%Y-%m-%d %H:%M:%S')}}</td>
<td>{{ ac.created.strftime('%Y-%m-%d %H:%M:%S') }}</td>
<td>
<a href="{{ url_for('inventory.export', export_id='snapshot') }}?id={{ ac.snapshot.uuid }}">
<i class="bi bi-box-arrow-up-right"></i>

View file

@ -260,6 +260,20 @@ def test_export_certificates(user3: UserClientFlask):
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.usefixtures(conftest.app_context.__name__)
def test_labels(user3: UserClientFlask):