admin: make pagination size configurable
This commit is contained in:
parent
5d46c1ea5a
commit
e104c74761
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Reference in a new issue