From 461fed556756abd7f84da0411eea40fa77ac8a7d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 13 May 2020 13:45:57 +0200 Subject: [PATCH] admin: remove more duplicate code --- passbook/admin/views/policy.py | 6 +++--- passbook/admin/views/providers.py | 8 +++----- passbook/stages/invitation/api.py | 4 +--- passbook/stages/password/api.py | 1 - 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/passbook/admin/views/policy.py b/passbook/admin/views/policy.py index 588f3a5cf..7c65c1d5c 100644 --- a/passbook/admin/views/policy.py +++ b/passbook/admin/views/policy.py @@ -14,7 +14,7 @@ from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from passbook.admin.forms.policies import PolicyTestForm from passbook.core.models import Policy -from passbook.lib.utils.reflection import path_to_class +from passbook.lib.utils.reflection import all_subclasses, path_to_class from passbook.lib.views import CreateAssignPermView from passbook.policies.engine import PolicyEngine @@ -30,7 +30,7 @@ class PolicyListView(LoginRequiredMixin, PermissionListMixin, ListView): def get_context_data(self, **kwargs): kwargs["types"] = { - x.__name__: x._meta.verbose_name for x in Policy.__subclasses__() + x.__name__: x._meta.verbose_name for x in all_subclasses(Policy) } return super().get_context_data(**kwargs) @@ -62,7 +62,7 @@ class PolicyCreateView( def get_form_class(self): policy_type = self.request.GET.get("type") - model = next(x for x in Policy.__subclasses__() if x.__name__ == policy_type) + model = next(x for x in all_subclasses(Policy) if x.__name__ == policy_type) if not model: raise Http404 return path_to_class(model.form) diff --git a/passbook/admin/views/providers.py b/passbook/admin/views/providers.py index 845dfaad0..f0a1d5892 100644 --- a/passbook/admin/views/providers.py +++ b/passbook/admin/views/providers.py @@ -12,7 +12,7 @@ from django.views.generic import DeleteView, ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from passbook.core.models import Provider -from passbook.lib.utils.reflection import path_to_class +from passbook.lib.utils.reflection import all_subclasses, path_to_class from passbook.lib.views import CreateAssignPermView @@ -27,7 +27,7 @@ class ProviderListView(LoginRequiredMixin, PermissionListMixin, ListView): def get_context_data(self, **kwargs): kwargs["types"] = { - x.__name__: x._meta.verbose_name for x in Provider.__subclasses__() + x.__name__: x._meta.verbose_name for x in all_subclasses(Provider) } return super().get_context_data(**kwargs) @@ -52,9 +52,7 @@ class ProviderCreateView( def get_form_class(self): provider_type = self.request.GET.get("type") - model = next( - x for x in Provider.__subclasses__() if x.__name__ == provider_type - ) + model = next(x for x in all_subclasses(Provider) if x.__name__ == provider_type) if not model: raise Http404 return path_to_class(model.form) diff --git a/passbook/stages/invitation/api.py b/passbook/stages/invitation/api.py index c4218db6f..33da32b63 100644 --- a/passbook/stages/invitation/api.py +++ b/passbook/stages/invitation/api.py @@ -34,9 +34,7 @@ class InvitationSerializer(ModelSerializer): fields = [ "pk", "expires", - "fixed_username", - "fixed_email", - "needs_confirmation", + "fixed_data", ] diff --git a/passbook/stages/password/api.py b/passbook/stages/password/api.py index 48e1c5191..6b8f28703 100644 --- a/passbook/stages/password/api.py +++ b/passbook/stages/password/api.py @@ -15,7 +15,6 @@ class PasswordStageSerializer(ModelSerializer): "pk", "name", "backends", - "password_policies", ]