From 47cb76f7c37978213924a3d96578802b016dfaa4 Mon Sep 17 00:00:00 2001 From: Chris May Date: Thu, 31 Oct 2019 13:29:22 -0400 Subject: [PATCH] Fixing Paginator warnings --- wagtailmedia/utils.py | 9 +++++++++ wagtailmedia/views/chooser.py | 2 +- wagtailmedia/views/media.py | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 wagtailmedia/utils.py diff --git a/wagtailmedia/utils.py b/wagtailmedia/utils.py new file mode 100644 index 00000000..70e7af9e --- /dev/null +++ b/wagtailmedia/utils.py @@ -0,0 +1,9 @@ +from django.core.paginator import Paginator + +DEFAULT_PAGE_KEY = 'p' + + +def paginate(request, items, page_key=DEFAULT_PAGE_KEY, per_page=20): + paginator = Paginator(items, per_page) + page = paginator.get_page(request.GET.get(page_key)) + return paginator, page diff --git a/wagtailmedia/views/chooser.py b/wagtailmedia/views/chooser.py index ab6ce685..ae57e84a 100644 --- a/wagtailmedia/views/chooser.py +++ b/wagtailmedia/views/chooser.py @@ -5,10 +5,10 @@ from wagtail.admin.modal_workflow import render_modal_workflow from wagtail.admin.utils import PermissionPolicyChecker from wagtail.core.models import Collection -from wagtail.utils.pagination import paginate from wagtailmedia.models import get_media_model from wagtailmedia.permissions import permission_policy +from wagtailmedia.utils import paginate if WAGTAIL_VERSION < (2, 5): from wagtail.admin.forms import SearchForm diff --git a/wagtailmedia/views/media.py b/wagtailmedia/views/media.py index 9e2a6c10..eededb04 100644 --- a/wagtailmedia/views/media.py +++ b/wagtailmedia/views/media.py @@ -10,11 +10,11 @@ from wagtail.admin.utils import PermissionPolicyChecker, permission_denied, popular_tags_for_model from wagtail.core.models import Collection from wagtail.search.backends import get_search_backends -from wagtail.utils.pagination import paginate from wagtailmedia.forms import get_media_form from wagtailmedia.models import get_media_model from wagtailmedia.permissions import permission_policy +from wagtailmedia.utils import paginate if WAGTAIL_VERSION < (2, 5): from wagtail.admin.forms import SearchForm