96-add-serial-number-in-public-web #24
|
@ -120,10 +120,12 @@
|
||||||
<div class="col-md-4 info-label">Model</div>
|
<div class="col-md-4 info-label">Model</div>
|
||||||
<div class="col-md-8 info-value">{{ object.model|default:'' }}</div>
|
<div class="col-md-8 info-value">{{ object.model|default:'' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="info-row row">
|
{% if user.is_authenticated %}
|
||||||
<div class="col-md-4 info-label">Serial Number</div>
|
<div class="info-row row">
|
||||||
<div class="col-md-8 info-value">{{object.serial_number|default:'' }}</div>
|
<div class="col-md-4 info-label">Serial Number</div>
|
||||||
</div>
|
<div class="col-md-8 info-value">{{ object.serial_number|default:'' }}</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -136,28 +138,28 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if user.is_authenticated %}
|
||||||
<h2 class="section-title mt-5">Components</h2>
|
<h2 class="section-title mt-5">Components</h2>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% for component in object.components %}
|
{% for component in object.components %}
|
||||||
<div class="col-md-6 mb-3">
|
<div class="col-md-6 mb-3">
|
||||||
<div class="card component-card">
|
<div class="card component-card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">{{ component.type }}</h5>
|
<h5 class="card-title">{{ component.type }}</h5>
|
||||||
<p class="card-text">
|
<p class="card-text">
|
||||||
{% for component_key, component_value in component.items %}
|
{% for component_key, component_value in component.items %}
|
||||||
{% if component_key not in 'actions,type' %}
|
{% if component_key not in 'actions,type' %}
|
||||||
<strong>{{ component_key }}:</strong> {{ component_value }}<br />
|
<strong>{{ component_key }}:</strong> {{ component_value }}<br />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% endfor %}
|
||||||
{% endfor %}
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<p>
|
<p>
|
||||||
©{% now 'Y' %} eReuse. All rights reserved.
|
©{% now 'Y' %} eReuse. All rights reserved.
|
||||||
|
|
|
@ -117,10 +117,10 @@ class PublicDeviceWebView(TemplateView):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.pk = kwargs['pk']
|
self.pk = kwargs['pk']
|
||||||
self.object = Device(id=self.pk)
|
self.object = Device(id=self.pk)
|
||||||
|
|
||||||
if not self.object.last_evidence:
|
if not self.object.last_evidence:
|
||||||
raise Http404
|
raise Http404
|
||||||
|
|
||||||
if self.request.headers.get('Accept') == 'application/json':
|
if self.request.headers.get('Accept') == 'application/json':
|
||||||
return self.get_json_response()
|
return self.get_json_response()
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
@ -133,15 +133,31 @@ class PublicDeviceWebView(TemplateView):
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_json_response(self):
|
@property
|
||||||
data = {
|
def public_fields(self):
|
||||||
|
return {
|
||||||
'id': self.object.id,
|
'id': self.object.id,
|
||||||
'shortid': self.object.shortid,
|
'shortid': self.object.shortid,
|
||||||
'uuids': self.object.uuids,
|
'uuids': self.object.uuids,
|
||||||
'hids': self.object.hids,
|
'hids': self.object.hids,
|
||||||
'components': self.object.components
|
|
||||||
}
|
}
|
||||||
return JsonResponse(data)
|
|
||||||
|
@property
|
||||||
|
def authenticated_fields(self):
|
||||||
|
return {
|
||||||
|
'components': self.object.components,
|
||||||
|
'serial_number': self.object.serial_number
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_device_data(self):
|
||||||
|
data = self.public_fields
|
||||||
|
if self.request.user.is_authenticated:
|
||||||
|
data.update(self.authenticated_fields)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def get_json_response(self):
|
||||||
|
device_data = self.get_device_data()
|
||||||
|
return JsonResponse(device_data)
|
||||||
|
|
||||||
|
|
||||||
class AddAnnotationView(DashboardView, CreateView):
|
class AddAnnotationView(DashboardView, CreateView):
|
||||||
|
|
Loading…
Reference in New Issue