Show components and serials only if user is authenticated

This commit is contained in:
sergio_gimenez 2024-11-05 10:19:24 +01:00
parent 033e4df297
commit e6c42a908f
2 changed files with 47 additions and 29 deletions

View File

@ -120,11 +120,13 @@
<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>
{% if user.is_authenticated %}
<div class="info-row row"> <div class="info-row row">
<div class="col-md-4 info-label">Serial Number</div> <div class="col-md-4 info-label">Serial Number</div>
<div class="col-md-8 info-value">{{object.serial_number|default:'' }}</div> <div class="col-md-8 info-value">{{ object.serial_number|default:'' }}</div>
</div> </div>
{% endif %} {% endif %}
{% endif %}
</div> </div>
<div class="col-lg-6"> <div class="col-lg-6">
@ -136,7 +138,7 @@
{% 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 %}
@ -156,8 +158,8 @@
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% endif %}
</div> </div>
<footer> <footer>
<p> <p>
&copy;{% now 'Y' %} eReuse. All rights reserved. &copy;{% now 'Y' %} eReuse. All rights reserved.

View File

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