34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
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")
|