Show components and serials only if user is authenticated
This commit is contained in:
parent
033e4df297
commit
e6c42a908f
|
@ -120,11 +120,13 @@
|
|||
<div class="col-md-4 info-label">Model</div>
|
||||
<div class="col-md-8 info-value">{{ object.model|default:'' }}</div>
|
||||
</div>
|
||||
{% if user.is_authenticated %}
|
||||
<div class="info-row row">
|
||||
<div class="col-md-4 info-label">Serial Number</div>
|
||||
<div class="col-md-8 info-value">{{ object.serial_number|default:'' }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-lg-6">
|
||||
|
@ -136,7 +138,7 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<h2 class="section-title mt-5">Components</h2>
|
||||
<div class="row">
|
||||
{% for component in object.components %}
|
||||
|
@ -156,8 +158,8 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<p>
|
||||
©{% now 'Y' %} eReuse. All rights reserved.
|
||||
|
|
|
@ -133,15 +133,31 @@ class PublicDeviceWebView(TemplateView):
|
|||
})
|
||||
return context
|
||||
|
||||
def get_json_response(self):
|
||||
data = {
|
||||
@property
|
||||
def public_fields(self):
|
||||
return {
|
||||
'id': self.object.id,
|
||||
'shortid': self.object.shortid,
|
||||
'uuids': self.object.uuids,
|
||||
'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):
|
||||
|
|
Loading…
Reference in New Issue