Skip to content

Commit 763b1b8

Browse files
✨ [#114] Support overriding the post accept/decline success URL
1 parent 46cc3bc commit 763b1b8

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

cookie_consent/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.conf import settings # NOQA
22

33
from appconf import AppConf
4+
from django.urls import reverse_lazy
45

56
__all__ = ["settings"]
67

@@ -24,3 +25,5 @@ class CookieConsentConf(AppConf):
2425
CACHE_BACKEND = "default"
2526

2627
LOG_ENABLED = True
28+
29+
SUCCESS_URL = reverse_lazy("cookie_consent_cookie_group_list")

cookie_consent/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.utils.http import url_has_allowed_host_and_scheme
77
from django.views.generic import ListView, View
88

9+
from .conf import settings
910
from .models import CookieGroup
1011
from .util import (
1112
accept_cookies,
@@ -48,7 +49,7 @@ def get_success_url(self):
4849
require_https=self.request.is_secure(),
4950
):
5051
raise SuspiciousOperation("Unsafe open redirect suspected.")
51-
return redirect_to or reverse("cookie_consent_cookie_group_list")
52+
return redirect_to or settings.COOKIE_CONSENT_SUCCESS_URL
5253

5354
def process(self, request, response, varname): # pragma: no cover
5455
raise NotImplementedError()

docs/settings.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ for more details about the meaning.
6666
Boolean value represents if user actions when they accepting and declining cookies will be logged. Turning it off might be useful for preventing your database from getting filled up with log items.
6767

6868
Default: ``True``
69+
70+
``COOKIE_CONSENT_SUCCESS_URL``
71+
The success URL to redirect the user too after a successful accept/decline action. If
72+
a ``?next`` parameter is present in the request, then it takes priority over this
73+
setting. Defaults to the URL of the built-in cookie list view.

0 commit comments

Comments
 (0)