Scaffold containerized Django/Wagtail app with core features
This commit is contained in:
33
apps/core/views.py
Normal file
33
apps/core/views.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from django.http import HttpRequest, HttpResponse, HttpResponseNotAllowed
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
from apps.core.consent import ConsentService
|
||||
|
||||
|
||||
def consent_view(request: HttpRequest) -> HttpResponse:
|
||||
if request.method != "POST":
|
||||
return HttpResponseNotAllowed(["POST"])
|
||||
|
||||
analytics = False
|
||||
advertising = False
|
||||
|
||||
if request.POST.get("accept_all"):
|
||||
analytics = True
|
||||
advertising = True
|
||||
elif request.POST.get("reject_all"):
|
||||
analytics = False
|
||||
advertising = False
|
||||
else:
|
||||
analytics = request.POST.get("analytics") in {"true", "1", "on"}
|
||||
advertising = request.POST.get("advertising") in {"true", "1", "on"}
|
||||
|
||||
target = request.META.get("HTTP_REFERER", "/")
|
||||
response = redirect(target)
|
||||
ConsentService.set_consent(response, analytics=analytics, advertising=advertising)
|
||||
return response
|
||||
|
||||
|
||||
def robots_txt(request: HttpRequest) -> HttpResponse:
|
||||
return render(request, "core/robots.txt", content_type="text/plain")
|
||||
Reference in New Issue
Block a user