django-utils

personal collection of django utilities
git clone https://git.ce9e.org/django-utils.git

commit
ae66739fe94650139e230dd5fb93d381936b379c
parent
af9add84c1cc3c5d23a07bd1b007b7885f07faf7
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-10-22 17:21
add next mixin

Diffstat

A utils/next.py 20 ++++++++++++++++++++

1 files changed, 20 insertions, 0 deletions


diff --git a/utils/next.py b/utils/next.py

@@ -0,0 +1,20 @@
   -1     1 from django.utils.http import is_safe_url
   -1     2 
   -1     3 
   -1     4 class NextMixin:
   -1     5     redirect_field_name = 'next'
   -1     6 
   -1     7     def get_success_url(self):
   -1     8         redirect_to = self.request.POST.get(
   -1     9             self.redirect_field_name,
   -1    10             self.request.GET.get(self.redirect_field_name))
   -1    11         if not redirect_to:
   -1    12             if self.success_url is not None:
   -1    13                 redirect_to = self.success_url
   -1    14             elif self.object:
   -1    15                 redirect_to = self.object.get_absolute_url()
   -1    16         host = self.request.get_host()
   -1    17         if redirect_to and is_safe_url(redirect_to, allowed_hosts={host}):
   -1    18             return redirect_to
   -1    19         else:
   -1    20             return ''