diff --git a/passbook/admin/views/applications.py b/passbook/admin/views/applications.py index 2a5bc85da..16bd09652 100644 --- a/passbook/admin/views/applications.py +++ b/passbook/admin/views/applications.py @@ -9,19 +9,18 @@ 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 +from passbook.admin.views.utils import 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, ListView): +class ApplicationListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all applications""" model = Application permission_required = "passbook_core.view_application" ordering = "name" - paginate_by = 40 template_name = "administration/application/list.html" diff --git a/passbook/admin/views/certificate_key_pair.py b/passbook/admin/views/certificate_key_pair.py index 2ab02eeb6..d667cc0c4 100644 --- a/passbook/admin/views/certificate_key_pair.py +++ b/passbook/admin/views/certificate_key_pair.py @@ -9,19 +9,18 @@ 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 +from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin from passbook.crypto.forms import CertificateKeyPairForm from passbook.crypto.models import CertificateKeyPair from passbook.lib.views import CreateAssignPermView -class CertificateKeyPairListView(LoginRequiredMixin, PermissionListMixin, ListView): +class CertificateKeyPairListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all keypairs""" model = CertificateKeyPair permission_required = "passbook_crypto.view_certificatekeypair" ordering = "name" - paginate_by = 40 template_name = "administration/certificatekeypair/list.html" diff --git a/passbook/admin/views/flows.py b/passbook/admin/views/flows.py index 3fb977d38..388a4fd38 100644 --- a/passbook/admin/views/flows.py +++ b/passbook/admin/views/flows.py @@ -11,7 +11,7 @@ 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 +from passbook.admin.views.utils import 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,13 +23,12 @@ from passbook.lib.utils.urls import redirect_with_qs from passbook.lib.views import CreateAssignPermView -class FlowListView(LoginRequiredMixin, PermissionListMixin, ListView): +class FlowListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all flows""" model = Flow permission_required = "passbook_flows.view_flow" ordering = "name" - paginate_by = 40 template_name = "administration/flow/list.html" diff --git a/passbook/admin/views/groups.py b/passbook/admin/views/groups.py index 267a88075..c6dd421da 100644 --- a/passbook/admin/views/groups.py +++ b/passbook/admin/views/groups.py @@ -9,19 +9,18 @@ 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 +from passbook.admin.views.utils import 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, ListView): +class GroupListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all groups""" model = Group permission_required = "passbook_core.view_group" ordering = "name" - paginate_by = 40 template_name = "administration/group/list.html" diff --git a/passbook/admin/views/outposts.py b/passbook/admin/views/outposts.py index ced9adb86..a82cbaded 100644 --- a/passbook/admin/views/outposts.py +++ b/passbook/admin/views/outposts.py @@ -12,19 +12,18 @@ 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 +from passbook.admin.views.utils import 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, ListView): +class OutpostListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all outposts""" model = Outpost permission_required = "passbook_outposts.view_outpost" ordering = "name" - paginate_by = 40 template_name = "administration/outpost/list.html" diff --git a/passbook/admin/views/policies.py b/passbook/admin/views/policies.py index 523c7650a..628b5e3c8 100644 --- a/passbook/admin/views/policies.py +++ b/passbook/admin/views/policies.py @@ -20,18 +20,17 @@ from passbook.admin.views.utils import ( DeleteMessageView, InheritanceCreateView, InheritanceListView, - InheritanceUpdateView, + InheritanceUpdateView, UserPaginateListMixin, ) from passbook.policies.models import Policy, PolicyBinding from passbook.policies.process import PolicyProcess, PolicyRequest -class PolicyListView(LoginRequiredMixin, PermissionListMixin, InheritanceListView): +class PolicyListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView): """Show list of all policies""" model = Policy permission_required = "passbook_policies.view_policy" - paginate_by = 10 ordering = "name" template_name = "administration/policy/list.html" diff --git a/passbook/admin/views/policies_bindings.py b/passbook/admin/views/policies_bindings.py index 67f73be87..456cfad02 100644 --- a/passbook/admin/views/policies_bindings.py +++ b/passbook/admin/views/policies_bindings.py @@ -11,18 +11,17 @@ 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 +from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin from passbook.lib.views import CreateAssignPermView from passbook.policies.forms import PolicyBindingForm from passbook.policies.models import PolicyBinding -class PolicyBindingListView(LoginRequiredMixin, PermissionListMixin, ListView): +class PolicyBindingListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all policies""" model = PolicyBinding permission_required = "passbook_policies.view_policybinding" - paginate_by = 10 ordering = ["order", "target"] template_name = "administration/policy_binding/list.html" diff --git a/passbook/admin/views/property_mapping.py b/passbook/admin/views/property_mapping.py index 790d2f912..1b5e380a0 100644 --- a/passbook/admin/views/property_mapping.py +++ b/passbook/admin/views/property_mapping.py @@ -4,6 +4,7 @@ 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 @@ -12,13 +13,13 @@ from passbook.admin.views.utils import ( DeleteMessageView, InheritanceCreateView, InheritanceListView, - InheritanceUpdateView, + InheritanceUpdateView, UserPaginateListMixin, ) from passbook.core.models import PropertyMapping class PropertyMappingListView( - LoginRequiredMixin, PermissionListMixin, InheritanceListView + LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView ): """Show list of all property_mappings""" @@ -26,7 +27,6 @@ class PropertyMappingListView( permission_required = "passbook_core.view_propertymapping" template_name = "administration/property_mapping/list.html" ordering = "name" - paginate_by = 40 class PropertyMappingCreateView( diff --git a/passbook/admin/views/providers.py b/passbook/admin/views/providers.py index 8cfc003c0..9cb2da245 100644 --- a/passbook/admin/views/providers.py +++ b/passbook/admin/views/providers.py @@ -12,18 +12,17 @@ from passbook.admin.views.utils import ( DeleteMessageView, InheritanceCreateView, InheritanceListView, - InheritanceUpdateView, + InheritanceUpdateView, UserPaginateListMixin, ) from passbook.core.models import Provider -class ProviderListView(LoginRequiredMixin, PermissionListMixin, InheritanceListView): +class ProviderListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView): """Show list of all providers""" model = Provider permission_required = "passbook_core.add_provider" template_name = "administration/provider/list.html" - paginate_by = 10 ordering = "id" diff --git a/passbook/admin/views/sources.py b/passbook/admin/views/sources.py index f7a318061..354b5dc57 100644 --- a/passbook/admin/views/sources.py +++ b/passbook/admin/views/sources.py @@ -12,18 +12,17 @@ from passbook.admin.views.utils import ( DeleteMessageView, InheritanceCreateView, InheritanceListView, - InheritanceUpdateView, + InheritanceUpdateView, UserPaginateListMixin, ) from passbook.core.models import Source -class SourceListView(LoginRequiredMixin, PermissionListMixin, InheritanceListView): +class SourceListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView): """Show list of all sources""" model = Source permission_required = "passbook_core.view_source" ordering = "name" - paginate_by = 40 template_name = "administration/source/list.html" diff --git a/passbook/admin/views/stages.py b/passbook/admin/views/stages.py index cbcbf5a5b..12223d22b 100644 --- a/passbook/admin/views/stages.py +++ b/passbook/admin/views/stages.py @@ -12,19 +12,18 @@ from passbook.admin.views.utils import ( DeleteMessageView, InheritanceCreateView, InheritanceListView, - InheritanceUpdateView, + InheritanceUpdateView, UserPaginateListMixin, ) from passbook.flows.models import Stage -class StageListView(LoginRequiredMixin, PermissionListMixin, InheritanceListView): +class StageListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, InheritanceListView): """Show list of all stages""" model = Stage template_name = "administration/stage/list.html" permission_required = "passbook_flows.view_stage" ordering = "name" - paginate_by = 40 class StageCreateView( diff --git a/passbook/admin/views/stages_bindings.py b/passbook/admin/views/stages_bindings.py index 5ff5c418d..cb68d439c 100644 --- a/passbook/admin/views/stages_bindings.py +++ b/passbook/admin/views/stages_bindings.py @@ -9,18 +9,17 @@ 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 +from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin from passbook.flows.forms import FlowStageBindingForm from passbook.flows.models import FlowStageBinding from passbook.lib.views import CreateAssignPermView -class StageBindingListView(LoginRequiredMixin, PermissionListMixin, ListView): +class StageBindingListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all flows""" model = FlowStageBinding permission_required = "passbook_flows.view_flowstagebinding" - paginate_by = 10 ordering = ["target", "order"] template_name = "administration/stage_binding/list.html" diff --git a/passbook/admin/views/stages_invitations.py b/passbook/admin/views/stages_invitations.py index 2a1be1c8a..ef123f67a 100644 --- a/passbook/admin/views/stages_invitations.py +++ b/passbook/admin/views/stages_invitations.py @@ -10,20 +10,19 @@ 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 +from passbook.admin.views.utils import 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, ListView): +class InvitationListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all invitations""" model = Invitation permission_required = "passbook_stages_invitation.view_invitation" template_name = "administration/stage_invitation/list.html" - paginate_by = 10 ordering = "-expires" diff --git a/passbook/admin/views/stages_prompts.py b/passbook/admin/views/stages_prompts.py index 8ebd2d336..2ee8c569e 100644 --- a/passbook/admin/views/stages_prompts.py +++ b/passbook/admin/views/stages_prompts.py @@ -9,19 +9,18 @@ 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 +from passbook.admin.views.utils import 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, ListView): +class PromptListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all prompts""" model = Prompt permission_required = "passbook_stages_prompt.view_prompt" ordering = "order" - paginate_by = 40 template_name = "administration/stage_prompt/list.html" diff --git a/passbook/admin/views/tokens.py b/passbook/admin/views/tokens.py index 204bc1012..7b09f1fd1 100644 --- a/passbook/admin/views/tokens.py +++ b/passbook/admin/views/tokens.py @@ -5,17 +5,16 @@ 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 +from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin from passbook.core.models import Token -class TokenListView(LoginRequiredMixin, PermissionListMixin, ListView): +class TokenListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all tokens""" model = Token permission_required = "passbook_core.view_token" ordering = "expires" - paginate_by = 40 template_name = "administration/token/list.html" diff --git a/passbook/admin/views/users.py b/passbook/admin/views/users.py index 38aaa2e95..c9a7588a6 100644 --- a/passbook/admin/views/users.py +++ b/passbook/admin/views/users.py @@ -18,18 +18,17 @@ from guardian.mixins import ( ) from passbook.admin.forms.users import UserForm -from passbook.admin.views.utils import DeleteMessageView +from passbook.admin.views.utils import DeleteMessageView, UserPaginateListMixin from passbook.core.models import Token, User from passbook.lib.views import CreateAssignPermView -class UserListView(LoginRequiredMixin, PermissionListMixin, ListView): +class UserListView(LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView): """Show list of all users""" model = User permission_required = "passbook_core.view_user" ordering = "username" - paginate_by = 40 template_name = "administration/user/list.html" def get_queryset(self): diff --git a/passbook/admin/views/utils.py b/passbook/admin/views/utils.py index 22e984a64..f35c13448 100644 --- a/passbook/admin/views/utils.py +++ b/passbook/admin/views/utils.py @@ -3,7 +3,9 @@ from typing import Any, Dict from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin +from django.db.models import QuerySet from django.http import Http404 +from django.http.request import HttpRequest from django.views.generic import DeleteView, ListView, UpdateView from passbook.lib.utils.reflection import all_subclasses @@ -69,3 +71,12 @@ class InheritanceUpdateView(UpdateView): .select_subclasses() .first() ) + + +class UserPaginateListMixin: + """Get paginate_by value from user's attributes, defaulting to 15""" + + request: HttpRequest + + def get_paginate_by(self, queryset: QuerySet) -> int: + return self.request.user.attributes.get("paginate_by", 15) diff --git a/passbook/audit/views.py b/passbook/audit/views.py index da437888a..ba32ba6d9 100644 --- a/passbook/audit/views.py +++ b/passbook/audit/views.py @@ -3,14 +3,16 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import ListView from guardian.mixins import PermissionListMixin +from passbook.admin.views.utils import UserPaginateListMixin from passbook.audit.models import Event -class EventListView(PermissionListMixin, LoginRequiredMixin, ListView): +class EventListView( + PermissionListMixin, LoginRequiredMixin, UserPaginateListMixin, ListView +): """Show list of all invitations""" model = Event template_name = "audit/list.html" permission_required = "passbook_audit.view_event" ordering = "-created" - paginate_by = 20 diff --git a/passbook/lib/templatetags/passbook_utils.py b/passbook/lib/templatetags/passbook_utils.py index 2effddc1c..c4e90455d 100644 --- a/passbook/lib/templatetags/passbook_utils.py +++ b/passbook/lib/templatetags/passbook_utils.py @@ -17,7 +17,7 @@ LOGGER = get_logger() @register.simple_tag(takes_context=True) def back(context: Context) -> str: - """Return a link back (either from GET paramter or referer.""" + """Return a link back (either from GET parameter or referer.""" if "request" not in context: return "" request = context.get("request")