mirror of
https://github.com/MOIS3Y/logs-collector.git
synced 2025-02-01 09:20:52 +01:00
82 lines
2.3 KiB
Python
82 lines
2.3 KiB
Python
# from django.shortcuts import render
|
|
from django.http import FileResponse, JsonResponse, Http404
|
|
from django.views import generic
|
|
|
|
from rest_framework import status
|
|
# from rest_framework.response import Response
|
|
|
|
from .models import Archive, Ticket, Platform
|
|
|
|
|
|
class ArchiveHandlerView(generic.View):
|
|
def get(self, request, path):
|
|
try:
|
|
file = Archive.objects.get(file=path)
|
|
except Archive.DoesNotExist:
|
|
return Http404
|
|
return FileResponse(file.file)
|
|
|
|
def delete(self, request, path):
|
|
try:
|
|
file = Archive.objects.get(file=path)
|
|
file.delete()
|
|
return JsonResponse(
|
|
{
|
|
'file': path,
|
|
'status': status.HTTP_200_OK
|
|
},
|
|
status=status.HTTP_200_OK
|
|
)
|
|
except Archive.DoesNotExist:
|
|
return JsonResponse(
|
|
{
|
|
'file': path,
|
|
'status': status.HTTP_204_NO_CONTENT
|
|
},
|
|
status=status.HTTP_204_NO_CONTENT
|
|
)
|
|
|
|
|
|
class ListAllTickets(generic.ListView):
|
|
model = Ticket
|
|
template_name = 'collector/tickets.html'
|
|
context_object_name = 'tickets'
|
|
paginate_by = 5
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context['platforms'] = Platform.objects.all()
|
|
return context
|
|
|
|
|
|
class ListPlatformTickets(generic.ListView):
|
|
model = Ticket
|
|
template_name = 'collector/tickets.html'
|
|
context_object_name = 'tickets'
|
|
allow_empty = False
|
|
paginate_by = 5
|
|
|
|
def get_queryset(self):
|
|
return Ticket.objects.filter(
|
|
platform__name=self.kwargs.get('platform')
|
|
)
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context['platforms'] = Platform.objects.all()
|
|
return context
|
|
|
|
|
|
class DetailTicket(generic.DetailView):
|
|
model = Ticket
|
|
template_name = 'collector/ticket.html'
|
|
context_object_name = 'ticket'
|
|
|
|
def get_object(self, queryset=None):
|
|
return Ticket.objects.get(number=self.kwargs.get('ticket'))
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context['platforms'] = Platform.objects.all()
|
|
return context
|