2024-07-11 15:40:45 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from django.views.generic.base import TemplateView
|
2024-07-13 13:27:26 +00:00
|
|
|
from django.urls import reverse_lazy
|
2024-07-18 15:21:22 +00:00
|
|
|
from django.views.generic.edit import (
|
2024-07-19 15:40:01 +00:00
|
|
|
FormView,
|
2024-07-18 15:21:22 +00:00
|
|
|
)
|
2024-07-13 13:27:26 +00:00
|
|
|
|
2024-07-31 17:24:22 +00:00
|
|
|
from dashboard.mixins import DashboardView, Http403
|
2024-07-31 11:28:46 +00:00
|
|
|
from evidence.models import Evidence
|
2024-07-30 17:38:04 +00:00
|
|
|
from evidence.forms import UploadForm
|
2024-06-12 07:32:49 +00:00
|
|
|
# from django.shortcuts import render
|
2024-07-01 10:17:23 +00:00
|
|
|
# from rest_framework import viewsets
|
|
|
|
# from snapshot.serializers import SnapshotSerializer
|
2024-06-12 07:32:49 +00:00
|
|
|
|
|
|
|
|
2024-07-01 10:17:23 +00:00
|
|
|
# class SnapshotViewSet(viewsets.ModelViewSet):
|
|
|
|
# queryset = Snapshot.objects.all()
|
|
|
|
# serializer_class = SnapshotSerializer
|
2024-06-12 07:32:49 +00:00
|
|
|
|
|
|
|
|
2024-07-26 15:59:34 +00:00
|
|
|
class ListEvidencesView(DashboardView, TemplateView):
|
|
|
|
template_name = "evidences.html"
|
|
|
|
section = "evidences"
|
|
|
|
title = _("Evidences")
|
|
|
|
breadcrumb = "Evidences"
|
2024-07-11 15:40:45 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2024-07-31 11:28:46 +00:00
|
|
|
evidences = Evidence.get_all(self.request.user)
|
|
|
|
|
2024-07-11 15:40:45 +00:00
|
|
|
context.update({
|
2024-07-26 15:59:34 +00:00
|
|
|
'evidences': evidences,
|
2024-07-11 15:40:45 +00:00
|
|
|
})
|
|
|
|
return context
|
2024-07-13 13:27:26 +00:00
|
|
|
|
|
|
|
|
2024-07-30 17:38:04 +00:00
|
|
|
class UploadView(DashboardView, FormView):
|
|
|
|
template_name = "upload.html"
|
|
|
|
section = "evidences"
|
|
|
|
title = _("Upload Evidence")
|
|
|
|
breadcrumb = "Evidences / Upload"
|
|
|
|
success_url = reverse_lazy('evidence:list')
|
|
|
|
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
|
2024-07-31 17:24:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EvidenceView(DashboardView, TemplateView):
|
|
|
|
template_name = "ev_details.html"
|
|
|
|
section = "evidences"
|
|
|
|
title = _("Evidences")
|
|
|
|
breadcrumb = "Evidences / Details"
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
self.pk = kwargs['pk']
|
|
|
|
self.object = Evidence(self.pk)
|
|
|
|
if self.object.owner != self.request.user:
|
|
|
|
raise Http403
|
|
|
|
|
|
|
|
self.object.get_annotations()
|
|
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context.update({
|
|
|
|
'object': self.object,
|
|
|
|
})
|
|
|
|
return context
|