diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 6c281cea..a54b06eb 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -534,9 +534,7 @@ class SnapshotListView(GenericMixin): 'sid': snap.sid, 'snapshot_uuid': snap.snapshot_uuid, 'version': snap.version, - 'device': snap.snapshot.device.devicehub_id - if snap.snapshot - else '', + 'device': snap.get_device(), 'status': snap.get_status(), 'severity': snap.severity, 'created': snap.created, @@ -556,6 +554,29 @@ class SnapshotListView(GenericMixin): return result +class SnapshotDetailView(GenericMixin): + template_name = 'inventory/snapshot_detail.html' + + def dispatch_request(self, snapshot_uuid): + self.snapshot_uuid = snapshot_uuid + self.get_context() + self.context['page_title'] = "Snapshot Detail" + self.context['snapshots_log'] = self.get_snapshots_log() + self.context['snapshot_uuid'] = snapshot_uuid + self.context['snapshot_sid'] = '' + if self.context['snapshots_log'].count(): + self.context['snapshot_sid'] = self.context['snapshots_log'][0].sid + + return flask.render_template(self.template_name, **self.context) + + def get_snapshots_log(self): + return ( + SnapshotsLog.query.filter(SnapshotsLog.owner == g.user) + .filter(SnapshotsLog.snapshot_uuid == self.snapshot_uuid) + .order_by(SnapshotsLog.created.desc()) + ) + + devices.add_url_rule('/action/add/', view_func=NewActionView.as_view('action_add')) devices.add_url_rule('/action/trade/add/', view_func=NewTradeView.as_view('trade_add')) devices.add_url_rule( @@ -603,3 +624,7 @@ devices.add_url_rule( '/export//', view_func=ExportsView.as_view('export') ) devices.add_url_rule('/snapshots/', view_func=SnapshotListView.as_view('snapshotslist')) +devices.add_url_rule( + '/snapshots//', + view_func=SnapshotDetailView.as_view('snapshot_detail'), +) diff --git a/ereuse_devicehub/parser/models.py b/ereuse_devicehub/parser/models.py index b6e7d2eb..949011d0 100644 --- a/ereuse_devicehub/parser/models.py +++ b/ereuse_devicehub/parser/models.py @@ -40,3 +40,9 @@ class SnapshotsLog(Thing): return Severity(self.severity) return '' + + def get_device(self): + if self.snapshot: + return self.snapshot.device.devicehub_id + + return '' diff --git a/ereuse_devicehub/templates/inventory/snapshot_detail.html b/ereuse_devicehub/templates/inventory/snapshot_detail.html new file mode 100644 index 00000000..4ea87572 --- /dev/null +++ b/ereuse_devicehub/templates/inventory/snapshot_detail.html @@ -0,0 +1,54 @@ +{% extends "ereuse_devicehub/base_site.html" %} +{% block main %} + +
+

Inventory

+ +
+ +
+
+ +
+ +
+
+

{{ snapshot_sid }} | {{ snapshot_uuid }}

+ +
+ +
+
Traceability log Details
+
+ {% for log in snapshots_log %} +
+
+
{{ log.get_status() }}
+ {{ log.created.strftime('%H:%M %d-%m-%Y') }} +
+

+ Device: + {{ log.get_device() }}
+ Version: {{ log.version }}
+

+

+ + {{ log.description }} + +

+
+ {% endfor %} +
+
+ +
+
+
+
+
+{% endblock main %} diff --git a/ereuse_devicehub/templates/inventory/snapshots_list.html b/ereuse_devicehub/templates/inventory/snapshots_list.html index b7035613..0a6084d1 100644 --- a/ereuse_devicehub/templates/inventory/snapshots_list.html +++ b/ereuse_devicehub/templates/inventory/snapshots_list.html @@ -37,10 +37,16 @@ {% for snap in snapshots_log %} + {% if snap.sid %} + {{ snap.sid }} + + {% endif %} + {{ snap.snapshot_uuid }} + {{ snap.version }}