import json
from django.conf import settings
from django_jinja import library
from shuup.compat import contextfunction
from shuup.gdpr.utils import get_active_consent_pages
[docs]
class GDPRNamespace:
[docs]
def is_enabled(self, request, **kwargs):
from shuup.gdpr.models import GDPRSettings
return GDPRSettings.get_for_shop(request.shop).enabled
[docs]
def get_documents(self, request, **kwargs):
return get_active_consent_pages(request.shop)
[docs]
@contextfunction
def get_accepted_cookies(self, context, **kwargs):
request = context["request"]
if settings.SHUUP_GDPR_CONSENT_COOKIE_NAME in request.COOKIES:
consent_cookies = request.COOKIES[settings.SHUUP_GDPR_CONSENT_COOKIE_NAME]
return json.loads(consent_cookies).get("cookies")
return []
library.global_function(name="gdpr", fn=GDPRNamespace())