django_coreprotect/views.py

65 lines
1.8 KiB
Python
Raw Normal View History

from django.shortcuts import render
from django.views.generic import View
from django.http.response import JsonResponse
from django_coreprotect.gui import gui_data, gui_results
from django_coreprotect.activity import activity_data, activity_results
from django_coreprotect.utils import safe_int
from django_coreprotect.models import Preset
class GUI(View):
def get(self, request):
form = gui_data(request)
return render(request, "coreprotect/coreprotect.html", {"form": form, "presets": Preset.objects.filter(enabled=True)})
def post(self, request):
pass
class GUIQuery(View):
def get(self, request):
form = gui_data(request)
results = gui_results(form)
if "format" in request.GET and request.GET["format"] == "json":
return JsonResponse(results)
prev_page, next_page = False, False
if safe_int(form.page) > 0:
prev_page = True
if len(results) == safe_int(form.page_size):
next_page = True
return render(request, "coreprotect/table/coreprotect.html", {"results": results, "num": len(results), "prev": prev_page, "next": next_page})
def post(self, request):
pass
class Activity(View):
def get(self, request):
form = activity_data(request)
return render(request, "coreprotect/activity.html", {"form": form})
def post(self, request):
pass
class ActivityQuery(View):
def get(self, request):
form = activity_data(request)
results = activity_results(form)
if "format" in request.GET and request.GET["format"] == "json":
return JsonResponse(results)
return render(request, "coreprotect/table/activity.html", {"results": results})
def post(self, request):
pass