logs-collector/logs_collector/collector/views.py

62 lines
1.7 KiB
Python
Raw Normal View History

# from django.shortcuts import render
from django.contrib.auth.decorators import login_required
2023-07-29 06:56:42 +02:00
from django.http import FileResponse, Http404
from django.views import generic
from .models import Archive, Ticket, Platform
2023-07-25 08:29:17 +02:00
# handles the url "/archives/{PATH}"".
@login_required
2023-07-29 06:56:42 +02:00
def download(request, path):
try:
file = Archive.objects.get(file=path)
except Archive.DoesNotExist:
return Http404
return FileResponse(file.file)
2023-07-29 06:56:42 +02:00
class ListAllTickets(generic.ListView):
model = Ticket
template_name = 'collector/tickets.html'
context_object_name = 'tickets'
2023-07-29 09:36:08 +02:00
paginate_by = 5
2023-07-29 06:56:42 +02:00
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
2023-07-29 09:36:08 +02:00
paginate_by = 5
2023-07-29 06:56:42 +02:00
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'
2023-07-29 06:56:42 +02:00
def get_object(self, queryset=None):
return Ticket.objects.get(number=self.kwargs.get('ticket'))
2023-07-29 06:56:42 +02:00
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['platforms'] = Platform.objects.all()
return context