From 34f4ab8a3fcfcb532793f30cb5f6f5c3a0820253 Mon Sep 17 00:00:00 2001 From: Brian Whitton Date: Fri, 13 Sep 2019 16:37:59 -0400 Subject: [PATCH] allow image page sizes to be configurable (#5568) --- CHANGELOG.txt | 1 + CONTRIBUTORS.rst | 1 + docs/advanced_topics/settings.rst | 20 ++++++++++++++++++++ docs/releases/2.7.rst | 1 + wagtail/images/views/chooser.py | 9 ++++++--- wagtail/images/views/images.py | 8 ++++++-- 6 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 0e7f54d2e3..f16368ebfc 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -20,6 +20,7 @@ Changelog * Recognise Soundcloud artist URLs as embeddable (Kiril Staikov) * Add `WAGTAILDOCS_SERVE_METHOD` setting to determine how document downloads will be linked to and served (Tobias McNulty, Matt Westcott) * Add `WAGTAIL_MODERATION_ENABLED` setting to enable / disable the 'Submit for Moderation' option (Jacob Topp-Mugglestone) + * Added settings to customise pagination page size for the Images admin area (Brian Whitton) * Fix: Added line breaks to long filenames on multiple image / document uploader (Kevin Howbrook) * Fix: Added https support for Scribd oEmbed provider (Rodrigo) * Fix: Changed StreamField group labels color so labels are visible (Catherine Farman) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 990881f920..ba81c382b2 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -407,6 +407,7 @@ Contributors * Dawid Bugajewski * Dawn Wages * Jacob Topp-Mugglestone +* Brian Whitton Translators =========== diff --git a/docs/advanced_topics/settings.rst b/docs/advanced_topics/settings.rst index ffeccb6751..55e66f5b91 100644 --- a/docs/advanced_topics/settings.rst +++ b/docs/advanced_topics/settings.rst @@ -275,6 +275,24 @@ This setting lets you override the maximum number of pixels an image can have. I This setting enables feature detection once OpenCV is installed, see all details on the :ref:`image_feature_detection` documentation. +.. code-block:: python + + WAGTAILIMAGES_INDEX_PAGE_SIZE = 20 + +Specifies the number of images per page shown on the main Images listing in the Wagtail admin. + +.. code-block:: python + + WAGTAILIMAGES_USAGE_PAGE_SIZE = 20 + +Specifies the number of items per page shown when viewing an image's usage (see :ref:`WAGTAIL_USAGE_COUNT_ENABLED `). + +.. code-block:: python + + WAGTAILIMAGES_CHOOSER_PAGE_SIZE = 12 + +Specifies the number of images shown per page in the image chooser modal. + Documents --------- @@ -475,6 +493,8 @@ a custom user model is being used and extra fields are required in the user crea A list of the extra custom fields to be appended to the default list. +.. _WAGTAIL_USAGE_COUNT_ENABLED: + Usage for images, documents and snippets ---------------------------------------- diff --git a/docs/releases/2.7.rst b/docs/releases/2.7.rst index b36583aabf..019cdba5dd 100644 --- a/docs/releases/2.7.rst +++ b/docs/releases/2.7.rst @@ -39,6 +39,7 @@ Other features * Recognise Soundcloud artist URLs as embeddable (Kiril Staikov) * Add ``WAGTAILDOCS_SERVE_METHOD`` setting to determine how document downloads will be linked to and served (Tobias McNulty, Matt Westcott) * Add ``WAGTAIL_MODERATION_ENABLED`` setting to enable / disable the 'Submit for Moderation' option (Jacob Topp-Mugglestone) + * Added settings to customise pagination page size for the Images admin area (Brian Whitton) Bug fixes diff --git a/wagtail/images/views/chooser.py b/wagtail/images/views/chooser.py index 98e972f1d5..262b61f59b 100644 --- a/wagtail/images/views/chooser.py +++ b/wagtail/images/views/chooser.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.core.paginator import Paginator from django.shortcuts import get_object_or_404, render from django.urls import reverse @@ -17,6 +18,8 @@ from wagtail.search import index as search_index permission_checker = PermissionPolicyChecker(permission_policy) +CHOOSER_PAGE_SIZE = getattr(settings, 'WAGTAILIMAGES_CHOOSER_PAGE_SIZE', 12) + def get_chooser_js_data(): """construct context variables needed by the chooser JS""" @@ -106,7 +109,7 @@ def chooser(request): images = images.filter(tags__name=tag_name) # Pagination - paginator = Paginator(images, per_page=12) + paginator = Paginator(images, per_page=CHOOSER_PAGE_SIZE) images = paginator.get_page(request.GET.get('p')) return render(request, "wagtailimages/chooser/results.html", { @@ -116,7 +119,7 @@ def chooser(request): 'will_select_format': request.GET.get('select_format') }) else: - paginator = Paginator(images, per_page=12) + paginator = Paginator(images, per_page=CHOOSER_PAGE_SIZE) images = paginator.get_page(request.GET.get('p')) context = get_chooser_context(request) @@ -187,7 +190,7 @@ def chooser_upload(request): for hook in hooks.get_hooks('construct_image_chooser_queryset'): images = hook(images, request) - paginator = Paginator(images, per_page=12) + paginator = Paginator(images, per_page=CHOOSER_PAGE_SIZE) images = paginator.get_page(request.GET.get('p')) context = get_chooser_context(request) diff --git a/wagtail/images/views/images.py b/wagtail/images/views/images.py index 1a8df0c218..3246ccb213 100644 --- a/wagtail/images/views/images.py +++ b/wagtail/images/views/images.py @@ -1,5 +1,6 @@ import os +from django.conf import settings from django.core.paginator import Paginator from django.http import HttpResponse, JsonResponse from django.shortcuts import get_object_or_404, redirect, render @@ -23,6 +24,9 @@ from wagtail.search import index as search_index permission_checker = PermissionPolicyChecker(permission_policy) +INDEX_PAGE_SIZE = getattr(settings, 'WAGTAILIMAGES_INDEX_PAGE_SIZE', 20) +USAGE_PAGE_SIZE = getattr(settings, 'WAGTAILIMAGES_USAGE_PAGE_SIZE', 20) + @permission_checker.require_any('add', 'change', 'delete') @vary_on_headers('X-Requested-With') @@ -55,7 +59,7 @@ def index(request): except (ValueError, Collection.DoesNotExist): pass - paginator = Paginator(images, per_page=20) + paginator = Paginator(images, per_page=INDEX_PAGE_SIZE) images = paginator.get_page(request.GET.get('p')) collections = permission_policy.collections_user_has_any_permission_for( @@ -289,7 +293,7 @@ def add(request): def usage(request, image_id): image = get_object_or_404(get_image_model(), id=image_id) - paginator = Paginator(image.get_usage(), per_page=20) + paginator = Paginator(image.get_usage(), per_page=USAGE_PAGE_SIZE) used_by = paginator.get_page(request.GET.get('p')) return render(request, "wagtailimages/images/usage.html", {