From de64c1a9891ef20d4f007e6572f45cc68cae6f5d Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Fri, 6 Dec 2024 17:48:06 -0300 Subject: [PATCH] added current state to device details --- action/forms.py | 22 +++++ device/templates/details.html | 149 +++++++++++++++++++--------------- device/views.py | 7 +- 3 files changed, 109 insertions(+), 69 deletions(-) create mode 100644 action/forms.py diff --git a/action/forms.py b/action/forms.py new file mode 100644 index 0000000..4d391f2 --- /dev/null +++ b/action/forms.py @@ -0,0 +1,22 @@ +from django import forms +from .models import State + + +class AddStateForm(forms.Form): + add_note = forms.BooleanField(required=False) + note = forms.CharField( + required=False, + widget=forms.Textarea(attrs={'rows': 4, 'maxlength': 200, 'placeholder': 'Max 200 characters'}), + ) + state_id = forms.IntegerField(required=True, widget=forms.HiddenInput()) + snapshot_uuid = forms.UUIDField(required=True, widget=forms.HiddenInput()) + + + def clean(self): + cleaned_data = super().clean() + add_note = cleaned_data.get('add_note') + note = cleaned_data.get('note') + + if add_note == True and not note: + self.add_error('note', 'Please enter a note if you checked "Add a note".') + return cleaned_data \ No newline at end of file diff --git a/device/templates/details.html b/device/templates/details.html index 62a0bfb..3dd8600 100644 --- a/device/templates/details.html +++ b/device/templates/details.html @@ -63,77 +63,91 @@ - -
+
-
{% trans 'Details' %}
-
-
Phid
-
{{ object.id }}
-
- - {% if object.is_eraseserver %} -
-
- {% trans 'Is a erase server' %} +
+ +
+
{% trans 'Details' %}
+
+
+
{% trans 'Phid' %}
+
{{ object.id }}
-
-
- {% endif %} -
-
Type
-
{{ object.type }}
-
+ {% if object.is_eraseserver %} +
+
{% trans 'Is an erase server' %}
+
{% trans 'Yes' %}
+
+ {% endif %} - {% if object.is_websnapshot and object.last_user_evidence %} - {% for k, v in object.last_user_evidence %} -
-
{{ k }}
-
{{ v|default:'' }}
+
+
{% trans 'Type' %}
+
{{ object.type }}
- {% endfor %} - {% else %} -
-
- {% trans 'Manufacturer' %} + + {% if object.is_websnapshot and object.last_user_evidence %} + {% for k, v in object.last_user_evidence.items %} +
+
{{ k }}
+
{{ v|default:'' }}
+
+ {% endfor %} + {% else %} +
+
{% trans 'Manufacturer' %}
+
{{ object.manufacturer|default:'' }}
+
+ +
+
{% trans 'Model' %}
+
{{ object.model|default:'' }}
+
+ +
+
{% trans 'Serial Number' %}
+
{{ object.serial_number|default:'' }}
+
+ {% endif %} + +
+
{% trans 'Identifiers' %}
+
+ {% for chid in object.hids %} +
{{ chid|default:'' }}
+ {% endfor %} +
-
{{ object.manufacturer|default:'' }}
-
-
- {% trans 'Model' %} -
-
{{ object.model|default:'' }}
-
-
-
- {% trans 'Version' %} + +
+
{% trans 'Current State' %}
+
+
+
{% trans 'State' %}
+
{{ device_states.0.state }}
-
{{ object.version|default:'' }}
-
- -
-
- {% trans 'Serial Number' %} +
+
{% trans 'Date' %}
+
{{ device_states.0.date|date:"SHORT_DATETIME_FORMAT" }}
-
{{ object.serial_number|default:'' }}
-
- {% endif %} -
-
- {% trans 'Identifiers' %} + + {% if last_note %} +
+
{% trans 'Note' %}
+
{{ object.last_state.note }}
+
+ {% endif %}
- {% for chid in object.hids %} -
-
{{ chid|default:'' }}
-
- {% endfor %}
+
+ +
@@ -174,14 +188,14 @@
- + {% endfor %}
- + {% for a in object.get_user_properties %} -
+
{% endfor %} @@ -370,14 +384,14 @@ {% trans "From:" %} - state_placeholder + state_placeholder
{% trans "To:" %} {{ state.state }} -
-
+
+
- +
-
- +
+ +
- + - + {% endfor %} diff --git a/device/views.py b/device/views.py index 623a039..48db1a4 100644 --- a/device/views.py +++ b/device/views.py @@ -13,7 +13,7 @@ from django.views.generic.edit import ( DeleteView, ) from django.views.generic.base import TemplateView -from action.models import StateDefinition +from action.models import StateDefinition, State from dashboard.mixins import DashboardView, Http403 from evidence.models import UserProperty, SystemProperty, Property from lot.models import LotTag @@ -117,12 +117,15 @@ class DetailsView(DashboardView, TemplateView): uuid__in=self.object.uuids, type=PROOF_TYPE["IssueDPP"] ) + last_evidence= self.object.get_last_evidence(), + uuid=self.object.last_uuid() context.update({ 'object': self.object, - 'snapshot': self.object.get_last_evidence(), + 'snapshot': last_evidence, 'lot_tags': lot_tags, 'dpps': dpps, "state_definitions": StateDefinition.objects.filter(institution=self.request.user.institution).order_by('order'), + "device_states": State.objects.filter(snapshot_uuid=uuid).order_by('date'), }) return context