Add user tag for identify a device from form
This commit is contained in:
parent
1a44d40227
commit
aa2b8a750d
|
@ -9,7 +9,6 @@ from evidence.models import Annotation
|
|||
|
||||
|
||||
class UploadForm(forms.Form):
|
||||
|
||||
evidence_file = MultipleFileField(label=_("File"))
|
||||
|
||||
def clean(self):
|
||||
|
@ -47,3 +46,30 @@ class UploadForm(forms.Form):
|
|||
|
||||
for ev in self.evidences:
|
||||
Build(ev[1], user)
|
||||
|
||||
|
||||
class UserTagForm(forms.Form):
|
||||
tag = forms.CharField(label=_("Tag"))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.uuid = kwargs.pop('uuid', None)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
data = self.cleaned_data.get('tag')
|
||||
if not data:
|
||||
return False
|
||||
self.tag = data
|
||||
return True
|
||||
|
||||
def save(self, user, commit=True):
|
||||
if not commit:
|
||||
return
|
||||
|
||||
Annotation.objects.create(
|
||||
uuid=self.uuid,
|
||||
owner=user,
|
||||
type=Annotation.Type.SYSTEM,
|
||||
key='CUSTOM_ID',
|
||||
value=self.tag
|
||||
)
|
||||
|
|
|
@ -45,5 +45,29 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="tag">
|
||||
{% load django_bootstrap5 %}
|
||||
<div class="list-group col-6">
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||
<div class="message">
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}<br />
|
||||
{% endfor %}
|
||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="container">
|
||||
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.views.generic.edit import (
|
|||
|
||||
from dashboard.mixins import DashboardView, Http403
|
||||
from evidence.models import Evidence
|
||||
from evidence.forms import UploadForm
|
||||
from evidence.forms import UploadForm, UserTagForm
|
||||
# from django.shortcuts import render
|
||||
# from rest_framework import viewsets
|
||||
# from snapshot.serializers import SnapshotSerializer
|
||||
|
@ -51,12 +51,14 @@ class UploadView(DashboardView, FormView):
|
|||
response = super().form_invalid(form)
|
||||
return response
|
||||
|
||||
|
||||
class EvidenceView(DashboardView, TemplateView):
|
||||
|
||||
class EvidenceView(DashboardView, FormView):
|
||||
template_name = "ev_details.html"
|
||||
section = "evidences"
|
||||
title = _("Evidences")
|
||||
breadcrumb = "Evidences / Details"
|
||||
success_url = reverse_lazy('evidence:list')
|
||||
form_class = UserTagForm
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.pk = kwargs['pk']
|
||||
|
@ -73,3 +75,22 @@ class EvidenceView(DashboardView, TemplateView):
|
|||
'object': self.object,
|
||||
})
|
||||
return context
|
||||
|
||||
def get_form_kwargs(self):
|
||||
self.pk = self.kwargs.get('pk')
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs['uuid'] = self.pk
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
form.save(self.request.user)
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
|
||||
def form_invalid(self, form):
|
||||
response = super().form_invalid(form)
|
||||
return response
|
||||
|
||||
def get_success_url(self):
|
||||
success_url = reverse_lazy('evidence:details', args=[self.pk])
|
||||
return success_url
|
||||
|
|
|
@ -162,7 +162,7 @@ class LotDocumentsView(DashboardView, TemplateView):
|
|||
template_name = "documents.html"
|
||||
title = _("New Document")
|
||||
breadcrumb = "Device / New document"
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
self.pk = kwargs.get('pk')
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
@ -185,7 +185,7 @@ class LotAnnotationsView(DashboardView, TemplateView):
|
|||
template_name = "annotations.html"
|
||||
title = _("New Annotation")
|
||||
breadcrumb = "Device / New annotation"
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
self.pk = kwargs.get('pk')
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
@ -203,7 +203,7 @@ class LotAnnotationsView(DashboardView, TemplateView):
|
|||
})
|
||||
return context
|
||||
|
||||
|
||||
|
||||
class LotAddAnnotationView(DashboardView, CreateView):
|
||||
template_name = "new_annotation.html"
|
||||
title = _("New Annotation")
|
||||
|
|
Loading…
Reference in New Issue