diff --git a/conntrackt/views.py b/conntrackt/views.py --- a/conntrackt/views.py +++ b/conntrackt/views.py @@ -19,6 +19,28 @@ from .models import Project, Entity, Loc from .utils import generate_entity_iptables, generate_project_diagram +class RedirectToNextMixin(object): + """ + View mixin that can be used for redirecting the user to URL defined through + a GET parameter. The mixin is usable with Create/Update/Delete views that + utilise the get_success_url() call. + + The mixin accepts the following class options: + + next_parameter - Name of the GET parameter that contains the redirect + URL. Defaults to "next". + """ + + next_parameter = "next" + + def get_success_url(self): + """ + Returns the success URL to which the user will be redirected. + """ + + return self.request.GET.get(self.next_parameter, super(RedirectToNextMixin, self).get_success_url()) + + class IndexView(MultiplePermissionsRequiredMixin, TemplateView): """ Custom view used for rendering the index page.