add details for user validated
This commit is contained in:
parent
c82db8caa0
commit
312f8a01bf
|
@ -4,7 +4,7 @@ import flask
|
|||
from ereuseapi.methods import API
|
||||
from flask import Blueprint
|
||||
from flask import current_app as app
|
||||
from flask import g, redirect, render_template, request, session
|
||||
from flask import g, render_template, request, session
|
||||
from flask.json import jsonify
|
||||
from flask.views import View
|
||||
|
||||
|
@ -20,6 +20,8 @@ class DidView(View):
|
|||
template_name = 'did/layout.html'
|
||||
|
||||
def dispatch_request(self, id_dpp):
|
||||
self.dpp = None
|
||||
self.device = None
|
||||
self.get_ids(id_dpp)
|
||||
|
||||
# import pdb; pdb.set_trace()
|
||||
|
@ -28,10 +30,16 @@ class DidView(View):
|
|||
'oidc': 'oidc' in app.blueprints.keys(),
|
||||
'user': g.user,
|
||||
'path': request.path,
|
||||
'last_dpp': None,
|
||||
'before_dpp': None,
|
||||
'rols': [],
|
||||
'rol': None,
|
||||
}
|
||||
self.get_rols()
|
||||
self.get_rol()
|
||||
self.get_device()
|
||||
self.get_last_dpp()
|
||||
self.get_before_dpp()
|
||||
|
||||
if 'json' in request.headers['Accept']:
|
||||
return jsonify(self.get_result())
|
||||
|
@ -52,7 +60,7 @@ class DidView(View):
|
|||
return []
|
||||
|
||||
if rols:
|
||||
return [(k, k) for k in rols]
|
||||
self.context['rols'] = rols
|
||||
|
||||
if 'trublo' not in app.blueprints.keys():
|
||||
return []
|
||||
|
@ -87,9 +95,13 @@ class DidView(View):
|
|||
def get_device(self):
|
||||
if self.id_dpp:
|
||||
self.dpp = Dpp.query.filter_by(key=self.id_dpp).one()
|
||||
device = self.dpp.device
|
||||
else:
|
||||
device = Device.query.filter_by(chid=self.chid, active=True).first()
|
||||
|
||||
if not device:
|
||||
return flask.abort(404)
|
||||
|
||||
abstract = None
|
||||
if device.placeholder:
|
||||
abstract = device.placeholder.binding
|
||||
|
@ -98,6 +110,9 @@ class DidView(View):
|
|||
device_abstract = placeholder and placeholder.binding or device
|
||||
device_real = placeholder and placeholder.device or device
|
||||
self.device = device_abstract
|
||||
components = self.device.components
|
||||
if self.dpp:
|
||||
components = self.dpp.snapshot.components
|
||||
|
||||
self.context.update(
|
||||
{
|
||||
|
@ -106,20 +121,29 @@ class DidView(View):
|
|||
'device_abstract': device_abstract,
|
||||
'device_real': device_real,
|
||||
'abstract': abstract,
|
||||
'components': components,
|
||||
}
|
||||
)
|
||||
|
||||
def get_last_dpp(self, dpp):
|
||||
dpps = [
|
||||
act.dpp[0] for act in dpp.device.actions if act.t == 'Snapshot' and act.dpp
|
||||
]
|
||||
last_dpp = ''
|
||||
for d in dpps:
|
||||
if d.key == dpp.key:
|
||||
return last_dpp
|
||||
last_dpp = d.key
|
||||
def get_last_dpp(self):
|
||||
dpps = sorted(self.device.dpps, key=lambda x: x.created)
|
||||
self.context['last_dpp'] = dpps and dpps[-1] or ''
|
||||
return self.context['last_dpp']
|
||||
|
||||
return last_dpp
|
||||
def get_before_dpp(self):
|
||||
if not self.dpp:
|
||||
self.context['before_dpp'] = ''
|
||||
return ''
|
||||
|
||||
dpps = sorted(self.device.dpps, key=lambda x: x.created)
|
||||
before_dpp = ''
|
||||
for dpp in dpps:
|
||||
if dpp == self.dpp:
|
||||
break
|
||||
before_dpp = dpp
|
||||
|
||||
self.context['before_dpp'] = before_dpp
|
||||
return before_dpp
|
||||
|
||||
def get_result(self):
|
||||
data = {
|
||||
|
@ -130,7 +154,7 @@ class DidView(View):
|
|||
|
||||
if self.dpp:
|
||||
data['hardware'] = json.loads(self.dpp.snapshot.json_hw)
|
||||
last_dpp = self.get_last_dpp(self.id_dpp)
|
||||
last_dpp = self.get_last_dpp()
|
||||
url_last = ''
|
||||
if last_dpp:
|
||||
url_last = 'http://did.ereuse.org/{did}'.format(did=last_dpp)
|
||||
|
|
|
@ -67,8 +67,40 @@
|
|||
<div class="card-body">
|
||||
<h3 class="nav-link mt-5" style="color: #993365">{{ device_real.type }} - {{ device_real.verbose_name }}</h3>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="col-12">
|
||||
<h5 class="card-title">Basic</h5>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
Device Identifier (CHID):
|
||||
</div>
|
||||
<div class="col">
|
||||
<a href="{{ url_for('did.did', id_dpp=device_abstract.chid) }}">{{ device_abstract.chid }}</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
Last Digital Passport (Last Dpp):
|
||||
</div>
|
||||
<div class="col">
|
||||
{% if last_dpp %}
|
||||
<a href="{{ url_for('did.did', id_dpp=last_dpp.key) }}">{{ last_dpp.key }}</a>
|
||||
{% else %}
|
||||
- not detected -
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
Before Digital Passport (Before Dpp):
|
||||
</div>
|
||||
<div class="col">
|
||||
{% if before_dpp %}
|
||||
<a href="{{ url_for('did.did', id_dpp=before_dpp.key) }}">{{ before_dpp.key }}</a>
|
||||
{% else %}
|
||||
- not detected -
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
Usody Identifier (DHID)
|
||||
|
@ -122,55 +154,33 @@
|
|||
Serial Number
|
||||
</div>
|
||||
<div class="col">
|
||||
- anonymized -
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-1">
|
||||
</div>
|
||||
<div class="col-5">
|
||||
<h5 class="card-title">Status</h5>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="label"><b>Physical</b></div>
|
||||
<div>{{ device_real.physical_status and device.physical_status.type or '- not status -' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="label"><b>Lifecycle</b></div>
|
||||
<div>{{ device_real.status and device_real.status.type or '- not status -' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="label"><b>Allocation</b></div>
|
||||
<div>
|
||||
{% if device_real.allocated %}
|
||||
Allocated
|
||||
{% if rol %}
|
||||
{{ device_abstract.serial_number and device_abstract.serial_number.upper() or '- not detected -' }}
|
||||
{% else %}
|
||||
Not allocated
|
||||
- anonymized -
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="col-6">
|
||||
<div class="col-12">
|
||||
<h5 class="card-title">Components</h5>
|
||||
<div class="row">
|
||||
{% if placeholder.binding %}
|
||||
{% if components %}
|
||||
<div class="list-group col">
|
||||
{% for component in placeholder.binding.components|sort(attribute='type') %}
|
||||
{% for component in components|sort(attribute='type') %}
|
||||
<div class="list-group-item">
|
||||
<div class="d-flex w-100 justify-content-between">
|
||||
<h5 class="mb-1">{{ component.type }}</h5>
|
||||
<small class="text-muted">{{ component.created.strftime('%H:%M %d-%m-%Y') }}</small>
|
||||
</div>
|
||||
<p class="mb-1">
|
||||
{{ component.manufacturer or '- not detected -' }}<br />
|
||||
{{ component.model or '- not detected -' }}<br />
|
||||
Manufacturer: {{ component.manufacturer or '- not detected -' }}<br />
|
||||
Model: {{ component.model or '- not detected -' }}<br />
|
||||
{% if rol %}
|
||||
Serial: {{ component.serial_number and component.serial_number.upper() or '- not detected -' }}
|
||||
{% endif %}
|
||||
</p>
|
||||
<small class="text-muted">
|
||||
{% if component.type in ['RamModule', 'HardDrive', 'SolidStateDrive'] %}
|
||||
|
@ -189,19 +199,6 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<h5 class="card-title">Repair history</h5>
|
||||
<div class="row">
|
||||
<div class="list-group col">
|
||||
{% for action in placeholder.actions %}
|
||||
<div class="list-group-item d-flex justify-content-between align-items-center">
|
||||
{{ action.type }} {{ action.severity }}
|
||||
<small class="text-muted">{{ action.created.strftime('%H:%M %d-%m-%Y') }}</small>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Reference in New Issue