diff --git a/passbook/admin/views/applications.py b/passbook/admin/views/applications.py index 16bd09652..112e6c57c 100644 --- a/passbook/admin/views/applications.py +++ b/passbook/admin/views/applications.py @@ -9,13 +9,19 @@ from django.utils.translation import gettext as _ from django.views.generic import ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin -from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin +from passbook.admin.views.utils import ( + BackSuccessUrlMixin, + DeleteMessageView, + UserPaginateListMixin, +) from passbook.core.forms.applications import ApplicationForm from passbook.core.models import Application from passbook.lib.views import CreateAssignPermView -class ApplicationListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class ApplicationListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all applications""" model = Application @@ -26,6 +32,7 @@ class ApplicationListView(LoginRequiredMixin, PermissionListMixin, UserPaginateL class ApplicationCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -42,7 +49,11 @@ class ApplicationCreateView( class ApplicationUpdateView( - SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView + SuccessMessageMixin, + BackSuccessUrlMixin, + LoginRequiredMixin, + PermissionRequiredMixin, + UpdateView, ): """Update application""" diff --git a/passbook/admin/views/certificate_key_pair.py b/passbook/admin/views/certificate_key_pair.py index d667cc0c4..c1620a039 100644 --- a/passbook/admin/views/certificate_key_pair.py +++ b/passbook/admin/views/certificate_key_pair.py @@ -9,13 +9,19 @@ from django.utils.translation import gettext as _ from django.views.generic import ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin -from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin +from passbook.admin.views.utils import ( + BackSuccessUrlMixin, + DeleteMessageView, + UserPaginateListMixin, +) from passbook.crypto.forms import CertificateKeyPairForm from passbook.crypto.models import CertificateKeyPair from passbook.lib.views import CreateAssignPermView -class CertificateKeyPairListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class CertificateKeyPairListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all keypairs""" model = CertificateKeyPair @@ -26,6 +32,7 @@ class CertificateKeyPairListView(LoginRequiredMixin, PermissionListMixin, UserPa class CertificateKeyPairCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -42,7 +49,11 @@ class CertificateKeyPairCreateView( class CertificateKeyPairUpdateView( - SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView + SuccessMessageMixin, + BackSuccessUrlMixin, + LoginRequiredMixin, + PermissionRequiredMixin, + UpdateView, ): """Update certificatekeypair""" diff --git a/passbook/admin/views/flows.py b/passbook/admin/views/flows.py index 388a4fd38..99ca054f1 100644 --- a/passbook/admin/views/flows.py +++ b/passbook/admin/views/flows.py @@ -11,7 +11,11 @@ from django.utils.translation import gettext as _ from django.views.generic import DetailView, FormView, ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin -from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin +from passbook.admin.views.utils import ( + BackSuccessUrlMixin, + DeleteMessageView, + UserPaginateListMixin, +) from passbook.flows.forms import FlowForm, FlowImportForm from passbook.flows.models import Flow from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER @@ -23,7 +27,9 @@ from passbook.lib.utils.urls import redirect_with_qs from passbook.lib.views import CreateAssignPermView -class FlowListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class FlowListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all flows""" model = Flow @@ -34,6 +40,7 @@ class FlowListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixi class FlowCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -50,7 +57,11 @@ class FlowCreateView( class FlowUpdateView( - SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView + SuccessMessageMixin, + BackSuccessUrlMixin, + LoginRequiredMixin, + PermissionRequiredMixin, + UpdateView, ): """Update flow""" diff --git a/passbook/admin/views/groups.py b/passbook/admin/views/groups.py index c6dd421da..dfbe32f41 100644 --- a/passbook/admin/views/groups.py +++ b/passbook/admin/views/groups.py @@ -9,13 +9,19 @@ from django.utils.translation import gettext as _ from django.views.generic import ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin -from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin +from passbook.admin.views.utils import ( + BackSuccessUrlMixin, + DeleteMessageView, + UserPaginateListMixin, +) from passbook.core.forms.groups import GroupForm from passbook.core.models import Group from passbook.lib.views import CreateAssignPermView -class GroupListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class GroupListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all groups""" model = Group @@ -26,6 +32,7 @@ class GroupListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMix class GroupCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -42,7 +49,11 @@ class GroupCreateView( class GroupUpdateView( - SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView + SuccessMessageMixin, + BackSuccessUrlMixin, + LoginRequiredMixin, + PermissionRequiredMixin, + UpdateView, ): """Update group""" diff --git a/passbook/admin/views/outposts.py b/passbook/admin/views/outposts.py index a82cbaded..7874d9dc7 100644 --- a/passbook/admin/views/outposts.py +++ b/passbook/admin/views/outposts.py @@ -12,13 +12,19 @@ from django.utils.translation import gettext as _ from django.views.generic import ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin -from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin +from passbook.admin.views.utils import ( + BackSuccessUrlMixin, + DeleteMessageView, + UserPaginateListMixin, +) from passbook.lib.views import CreateAssignPermView from passbook.outposts.forms import OutpostForm from passbook.outposts.models import Outpost, OutpostConfig -class OutpostListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class OutpostListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all outposts""" model = Outpost @@ -29,6 +35,7 @@ class OutpostListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListM class OutpostCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -52,7 +59,11 @@ class OutpostCreateView( class OutpostUpdateView( - SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView + SuccessMessageMixin, + BackSuccessUrlMixin, + LoginRequiredMixin, + PermissionRequiredMixin, + UpdateView, ): """Update outpost""" diff --git a/passbook/admin/views/policies.py b/passbook/admin/views/policies.py index 628b5e3c8..26d4be81d 100644 --- a/passbook/admin/views/policies.py +++ b/passbook/admin/views/policies.py @@ -17,16 +17,20 @@ from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from passbook.admin.forms.policies import PolicyTestForm from passbook.admin.views.utils import ( + BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceListView, - InheritanceUpdateView, UserPaginateListMixin, + InheritanceUpdateView, + UserPaginateListMixin, ) from passbook.policies.models import Policy, PolicyBinding from passbook.policies.process import PolicyProcess, PolicyRequest -class PolicyListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView): +class PolicyListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView +): """Show list of all policies""" model = Policy @@ -37,6 +41,7 @@ class PolicyListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMi class PolicyCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -53,6 +58,7 @@ class PolicyCreateView( class PolicyUpdateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/passbook/admin/views/policies_bindings.py b/passbook/admin/views/policies_bindings.py index 456cfad02..c082d0d05 100644 --- a/passbook/admin/views/policies_bindings.py +++ b/passbook/admin/views/policies_bindings.py @@ -11,13 +11,19 @@ from django.views.generic import ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from guardian.shortcuts import get_objects_for_user -from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin +from passbook.admin.views.utils import ( + BackSuccessUrlMixin, + DeleteMessageView, + UserPaginateListMixin, +) from passbook.lib.views import CreateAssignPermView from passbook.policies.forms import PolicyBindingForm from passbook.policies.models import PolicyBinding -class PolicyBindingListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class PolicyBindingListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all policies""" model = PolicyBinding @@ -46,6 +52,7 @@ class PolicyBindingListView(LoginRequiredMixin, PermissionListMixin, UserPaginat class PolicyBindingCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -62,7 +69,11 @@ class PolicyBindingCreateView( class PolicyBindingUpdateView( - SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView + SuccessMessageMixin, + BackSuccessUrlMixin, + LoginRequiredMixin, + PermissionRequiredMixin, + UpdateView, ): """Update policybinding""" diff --git a/passbook/admin/views/property_mapping.py b/passbook/admin/views/property_mapping.py index 1b5e380a0..89d228756 100644 --- a/passbook/admin/views/property_mapping.py +++ b/passbook/admin/views/property_mapping.py @@ -4,16 +4,17 @@ from django.contrib.auth.mixins import ( PermissionRequiredMixin as DjangoPermissionRequiredMixin, ) from django.contrib.messages.views import SuccessMessageMixin -from django.db.models import QuerySet from django.urls import reverse_lazy from django.utils.translation import gettext as _ from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from passbook.admin.views.utils import ( + BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceListView, - InheritanceUpdateView, UserPaginateListMixin, + InheritanceUpdateView, + UserPaginateListMixin, ) from passbook.core.models import PropertyMapping @@ -31,6 +32,7 @@ class PropertyMappingListView( class PropertyMappingCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -47,6 +49,7 @@ class PropertyMappingCreateView( class PropertyMappingUpdateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/passbook/admin/views/providers.py b/passbook/admin/views/providers.py index 9cb2da245..02ee7508e 100644 --- a/passbook/admin/views/providers.py +++ b/passbook/admin/views/providers.py @@ -9,15 +9,19 @@ from django.utils.translation import gettext as _ from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from passbook.admin.views.utils import ( + BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceListView, - InheritanceUpdateView, UserPaginateListMixin, + InheritanceUpdateView, + UserPaginateListMixin, ) from passbook.core.models import Provider -class ProviderListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView): +class ProviderListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView +): """Show list of all providers""" model = Provider @@ -28,6 +32,7 @@ class ProviderListView(LoginRequiredMixin, PermissionListMixin, UserPaginateList class ProviderCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -44,6 +49,7 @@ class ProviderCreateView( class ProviderUpdateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/passbook/admin/views/sources.py b/passbook/admin/views/sources.py index 354b5dc57..e0a5c907f 100644 --- a/passbook/admin/views/sources.py +++ b/passbook/admin/views/sources.py @@ -9,15 +9,19 @@ from django.utils.translation import gettext as _ from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from passbook.admin.views.utils import ( + BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceListView, - InheritanceUpdateView, UserPaginateListMixin, + InheritanceUpdateView, + UserPaginateListMixin, ) from passbook.core.models import Source -class SourceListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView): +class SourceListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView +): """Show list of all sources""" model = Source @@ -28,6 +32,7 @@ class SourceListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMi class SourceCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -44,6 +49,7 @@ class SourceCreateView( class SourceUpdateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/passbook/admin/views/stages.py b/passbook/admin/views/stages.py index 12223d22b..e7778864e 100644 --- a/passbook/admin/views/stages.py +++ b/passbook/admin/views/stages.py @@ -9,15 +9,19 @@ from django.utils.translation import gettext as _ from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from passbook.admin.views.utils import ( + BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceListView, - InheritanceUpdateView, UserPaginateListMixin, + InheritanceUpdateView, + UserPaginateListMixin, ) from passbook.flows.models import Stage -class StageListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView): +class StageListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView +): """Show list of all stages""" model = Stage @@ -28,6 +32,7 @@ class StageListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMix class StageCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -44,6 +49,7 @@ class StageCreateView( class StageUpdateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/passbook/admin/views/stages_bindings.py b/passbook/admin/views/stages_bindings.py index cb68d439c..dfac12cc8 100644 --- a/passbook/admin/views/stages_bindings.py +++ b/passbook/admin/views/stages_bindings.py @@ -9,13 +9,19 @@ from django.utils.translation import gettext as _ from django.views.generic import ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin -from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin +from passbook.admin.views.utils import ( + BackSuccessUrlMixin, + DeleteMessageView, + UserPaginateListMixin, +) from passbook.flows.forms import FlowStageBindingForm from passbook.flows.models import FlowStageBinding from passbook.lib.views import CreateAssignPermView -class StageBindingListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class StageBindingListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all flows""" model = FlowStageBinding @@ -26,6 +32,7 @@ class StageBindingListView(LoginRequiredMixin, PermissionListMixin, UserPaginate class StageBindingCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -42,7 +49,11 @@ class StageBindingCreateView( class StageBindingUpdateView( - SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView + SuccessMessageMixin, + BackSuccessUrlMixin, + LoginRequiredMixin, + PermissionRequiredMixin, + UpdateView, ): """Update FlowStageBinding""" diff --git a/passbook/admin/views/stages_invitations.py b/passbook/admin/views/stages_invitations.py index ef123f67a..5dec555af 100644 --- a/passbook/admin/views/stages_invitations.py +++ b/passbook/admin/views/stages_invitations.py @@ -10,14 +10,20 @@ from django.utils.translation import gettext as _ from django.views.generic import ListView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin -from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin +from passbook.admin.views.utils import ( + BackSuccessUrlMixin, + DeleteMessageView, + UserPaginateListMixin, +) from passbook.lib.views import CreateAssignPermView from passbook.stages.invitation.forms import InvitationForm from passbook.stages.invitation.models import Invitation from passbook.stages.invitation.signals import invitation_created -class InvitationListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class InvitationListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all invitations""" model = Invitation @@ -28,6 +34,7 @@ class InvitationListView(LoginRequiredMixin, PermissionListMixin, UserPaginateLi class InvitationCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, diff --git a/passbook/admin/views/stages_prompts.py b/passbook/admin/views/stages_prompts.py index 2ee8c569e..6fb92169d 100644 --- a/passbook/admin/views/stages_prompts.py +++ b/passbook/admin/views/stages_prompts.py @@ -9,13 +9,19 @@ from django.utils.translation import gettext as _ from django.views.generic import ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin -from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin +from passbook.admin.views.utils import ( + BackSuccessUrlMixin, + DeleteMessageView, + UserPaginateListMixin, +) from passbook.lib.views import CreateAssignPermView from passbook.stages.prompt.forms import PromptAdminForm from passbook.stages.prompt.models import Prompt -class PromptListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class PromptListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all prompts""" model = Prompt @@ -26,6 +32,7 @@ class PromptListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMi class PromptCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -42,7 +49,11 @@ class PromptCreateView( class PromptUpdateView( - SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView + SuccessMessageMixin, + BackSuccessUrlMixin, + LoginRequiredMixin, + PermissionRequiredMixin, + UpdateView, ): """Update prompt""" diff --git a/passbook/admin/views/tokens.py b/passbook/admin/views/tokens.py index 7b09f1fd1..d72f28168 100644 --- a/passbook/admin/views/tokens.py +++ b/passbook/admin/views/tokens.py @@ -9,7 +9,9 @@ from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin from passbook.core.models import Token -class TokenListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class TokenListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all tokens""" model = Token diff --git a/passbook/admin/views/users.py b/passbook/admin/views/users.py index c9a7588a6..9275acc8d 100644 --- a/passbook/admin/views/users.py +++ b/passbook/admin/views/users.py @@ -18,12 +18,18 @@ from guardian.mixins import ( ) from passbook.admin.forms.users import UserForm -from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin +from passbook.admin.views.utils import ( + BackSuccessUrlMixin, + DeleteMessageView, + UserPaginateListMixin, +) from passbook.core.models import Token, User from passbook.lib.views import CreateAssignPermView -class UserListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): +class UserListView( + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView +): """Show list of all users""" model = User @@ -37,6 +43,7 @@ class UserListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixi class UserCreateView( SuccessMessageMixin, + BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -53,7 +60,11 @@ class UserCreateView( class UserUpdateView( - SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView + SuccessMessageMixin, + BackSuccessUrlMixin, + LoginRequiredMixin, + PermissionRequiredMixin, + UpdateView, ): """Update user""" diff --git a/passbook/admin/views/utils.py b/passbook/admin/views/utils.py index f35c13448..e8f2fd18d 100644 --- a/passbook/admin/views/utils.py +++ b/passbook/admin/views/utils.py @@ -1,5 +1,6 @@ """passbook admin util views""" -from typing import Any, Dict +from typing import Any, Dict, Optional +from urllib.parse import urlparse from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin @@ -73,10 +74,29 @@ class InheritanceUpdateView(UpdateView): ) +class BackSuccessUrlMixin: + """Checks if a relative URL has been given as ?back param, and redirect to it. Otherwise + default to self.success_url.""" + + request: HttpRequest + + success_url: Optional[str] + + def get_success_url(self) -> str: + """get_success_url from FormMixin""" + back_param = self.request.GET.get("back") + if back_param: + if not bool(urlparse(back_param).netloc): + return back_param + return str(self.success_url) + + class UserPaginateListMixin: """Get paginate_by value from user's attributes, defaulting to 15""" request: HttpRequest + # pylint: disable=unused-argument def get_paginate_by(self, queryset: QuerySet) -> int: + """get_paginate_by Function of ListView""" return self.request.user.attributes.get("paginate_by", 15)