2019-07-26 17:36:03 +00:00
|
|
|
from django.shortcuts import render
|
|
|
|
from django.views.generic import View
|
2019-08-14 21:56:05 +00:00
|
|
|
from django.http.response import JsonResponse
|
2019-08-16 03:59:43 +00:00
|
|
|
from django_coreprotect.forms import *
|
2019-07-26 17:36:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Home(View):
|
2019-07-27 03:22:29 +00:00
|
|
|
|
|
|
|
def get(self, request):
|
2019-08-16 03:59:43 +00:00
|
|
|
form = form_data(request)
|
2019-08-14 21:56:05 +00:00
|
|
|
return render(request, "coreprotect/coreprotect.html", {"form": form})
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Query(View):
|
|
|
|
|
|
|
|
def get(self, request):
|
2019-08-16 03:59:43 +00:00
|
|
|
form = form_data(request)
|
2019-08-14 21:56:05 +00:00
|
|
|
results = result_data(form)
|
|
|
|
|
|
|
|
if "format" in request.GET and request.GET["format"] == "json":
|
|
|
|
return JsonResponse(results)
|
|
|
|
|
2019-08-15 22:00:54 +00:00
|
|
|
prev_page, next_page = False, False
|
2019-08-16 03:59:43 +00:00
|
|
|
if safe_int(form.page) > 0:
|
2019-08-15 22:00:54 +00:00
|
|
|
prev_page = True
|
2019-08-16 03:59:43 +00:00
|
|
|
if len(results) == safe_int(form.page_size):
|
2019-08-15 22:00:54 +00:00
|
|
|
next_page = True
|
|
|
|
|
|
|
|
return render(request, "coreprotect/table.html", {"results": results, "num": len(results), "prev": prev_page, "next": next_page})
|
2019-07-27 03:22:29 +00:00
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
pass
|