upload evidences
This commit is contained in:
parent
0136a98ff5
commit
da1e40b7ed
|
@ -114,7 +114,7 @@
|
||||||
</a>
|
</a>
|
||||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if section == 'People' %}expanded{% else %}collapse{% endif %}" id="ul_evidences" data-bs-parent="#sidebarMenu">
|
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if section == 'People' %}expanded{% else %}collapse{% endif %}" id="ul_evidences" data-bs-parent="#sidebarMenu">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{# url 'idhub:admin_people_list' #}">
|
<a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{% url 'evidence:upload' %}">
|
||||||
{% trans 'Upload one' %}
|
{% trans 'Upload one' %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -7,18 +7,22 @@
|
||||||
<h3>{{ subtitle }}</h3>
|
<h3>{{ subtitle }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="col text-center">
|
<div class="col text-center">
|
||||||
|
{% if lot %}
|
||||||
<a href="{% url 'lot:documents' object.id %}" type="button" class="btn btn-green-admin">
|
<a href="{% url 'lot:documents' object.id %}" type="button" class="btn btn-green-admin">
|
||||||
<i class="bi bi-folder2"></i>
|
<i class="bi bi-folder2"></i>
|
||||||
{% trans 'Documents' %}
|
{% trans 'Documents' %}
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
<a href="{# url 'idhub:admin_people_activate' object.id #}" type="button" class="btn btn-green-admin">
|
<a href="{# url 'idhub:admin_people_activate' object.id #}" type="button" class="btn btn-green-admin">
|
||||||
<i class="bi bi-reply"></i>
|
<i class="bi bi-reply"></i>
|
||||||
{% trans 'Exports' %}
|
{% trans 'Exports' %}
|
||||||
</a>
|
</a>
|
||||||
|
{% if lot %}
|
||||||
<a href="{% url 'lot:annotations' object.id %}" type="button" class="btn btn-green-admin">
|
<a href="{% url 'lot:annotations' object.id %}" type="button" class="btn btn-green-admin">
|
||||||
<i class="bi bi-tag"></i>
|
<i class="bi bi-tag"></i>
|
||||||
{% trans 'Annotations' %}
|
{% trans 'Annotations' %}
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,10 @@ class LotDashboardView(InventaryMixin, DetailsMixin):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
devices = self.get_devices()
|
devices = self.get_devices()
|
||||||
|
lot = context.get('object')
|
||||||
context.update({
|
context.update({
|
||||||
'devices': devices,
|
'devices': devices,
|
||||||
|
'lot': lot,
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,33 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
from django import forms
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from evidence.parse import Build
|
||||||
|
|
||||||
|
|
||||||
class UploadForm(forms.Form):
|
class UploadForm(forms.Form):
|
||||||
|
|
||||||
evidence_file = forms.FileField(label=_("File"))
|
evidence_file = forms.FileField(label=_("File"))
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
data = self.cleaned_data
|
data = self.cleaned_data.get('evidence_file')
|
||||||
|
if not data:
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.file_name = data.name
|
||||||
|
self.file_data = data.read()
|
||||||
|
if not self.file_name or not self.file_data:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
self.file_json = json.loads(self.file_data)
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def save(self, user, commit=True):
|
||||||
|
if not commit or not user:
|
||||||
|
return
|
||||||
|
|
||||||
|
evidence = Build(self.file_json, user)
|
||||||
|
return evidence
|
||||||
|
|
32
evidence/templates/upload.html
Normal file
32
evidence/templates/upload.html
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h3>{{ subtitle }}</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% load django_bootstrap5 %}
|
||||||
|
<form role="form" method="post" enctype="multipart/form-data">
|
||||||
|
{% 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="form-actions-no-box">
|
||||||
|
<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>
|
||||||
|
{% endblock %}
|
|
@ -15,4 +15,5 @@ app_name = 'evidence'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.ListEvidencesView.as_view(), name="list"),
|
path("", views.ListEvidencesView.as_view(), name="list"),
|
||||||
|
path("upload", views.UploadView.as_view(), name="upload"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,7 +9,7 @@ from django.views.generic.edit import (
|
||||||
|
|
||||||
from dashboard.mixins import DashboardView
|
from dashboard.mixins import DashboardView
|
||||||
from evidence.models import Evidence, Annotation
|
from evidence.models import Evidence, Annotation
|
||||||
# from snapshot.forms import UploadForm
|
from evidence.forms import UploadForm
|
||||||
# from django.shortcuts import render
|
# from django.shortcuts import render
|
||||||
# from rest_framework import viewsets
|
# from rest_framework import viewsets
|
||||||
# from snapshot.serializers import SnapshotSerializer
|
# from snapshot.serializers import SnapshotSerializer
|
||||||
|
@ -36,10 +36,19 @@ class ListEvidencesView(DashboardView, TemplateView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
# class UploadView(DashboardView, FormView):
|
class UploadView(DashboardView, FormView):
|
||||||
# template_name = "upload.html"
|
template_name = "upload.html"
|
||||||
# section = "snapshots"
|
section = "evidences"
|
||||||
# title = _("Upload Snapshot")
|
title = _("Upload Evidence")
|
||||||
# breadcrumb = "Snapshots / Upload"
|
breadcrumb = "Evidences / Upload"
|
||||||
# success_url = reverse_lazy('snashot:list')
|
success_url = reverse_lazy('evidence:list')
|
||||||
# form_class = UploadForm
|
form_class = UploadForm
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in a new issue