mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 03:31:04 +01:00
Add ability to select number of images shown per page
This commit is contained in:
parent
bf0ecae7bf
commit
cc09910eea
@ -19,7 +19,11 @@
|
||||
dropdown.form.submit();
|
||||
})
|
||||
};
|
||||
const dropdownSelectors = ["#collection_chooser_collection_id", "#order_images_by"];
|
||||
const dropdownSelectors = [
|
||||
"#collection_chooser_collection_id",
|
||||
"#order_images_by",
|
||||
"#entries_per_page",
|
||||
];
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
dropdownSelectors.forEach(dropdownSelector => submitFormOnDropdownChange(dropdownSelector)
|
||||
);
|
||||
@ -66,6 +70,21 @@
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div class="field choice_field select">
|
||||
<label for="entries_per_page">{% trans "Entries per page" %}:</label>
|
||||
<div class="field-content">
|
||||
<div class="input">
|
||||
<select id="entries_per_page" name="entries_per_page">
|
||||
{% for value in ENTRIES_PER_PAGE_CHOICES %}
|
||||
<option value="{{ value }}" {% if entries_per_page == value %}selected="selected"{% endif %}>{{ value }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{% if popular_tags %}
|
||||
<li>
|
||||
<fieldset class="tagfilter">
|
||||
|
@ -34,6 +34,7 @@ USAGE_PAGE_SIZE = getattr(settings, "WAGTAILIMAGES_USAGE_PAGE_SIZE", 20)
|
||||
|
||||
|
||||
class BaseListingView(TemplateView):
|
||||
ENTRIES_PER_PAGE_CHOICES = sorted({10, 25, 50, 100, INDEX_PAGE_SIZE})
|
||||
ORDERING_OPTIONS = {
|
||||
"-created_at": _("Newest"),
|
||||
"created_at": _("Oldest"),
|
||||
@ -48,6 +49,17 @@ class BaseListingView(TemplateView):
|
||||
def get(self, request):
|
||||
return super().get(request)
|
||||
|
||||
def get_num_entries_per_page(self):
|
||||
entries_per_page = self.request.GET.get("entries_per_page", INDEX_PAGE_SIZE)
|
||||
try:
|
||||
entries_per_page = int(entries_per_page)
|
||||
except ValueError:
|
||||
entries_per_page = INDEX_PAGE_SIZE
|
||||
if entries_per_page not in self.ENTRIES_PER_PAGE_CHOICES:
|
||||
entries_per_page = INDEX_PAGE_SIZE
|
||||
|
||||
return entries_per_page
|
||||
|
||||
def get_valid_orderings(self):
|
||||
return self.ORDERING_OPTIONS
|
||||
|
||||
@ -103,7 +115,8 @@ class BaseListingView(TemplateView):
|
||||
except (AttributeError):
|
||||
self.current_tag = None
|
||||
|
||||
paginator = Paginator(images, per_page=INDEX_PAGE_SIZE)
|
||||
entries_per_page = self.get_num_entries_per_page()
|
||||
paginator = Paginator(images, per_page=entries_per_page)
|
||||
images = paginator.get_page(self.request.GET.get("p"))
|
||||
|
||||
next_url = reverse("wagtailimages:index")
|
||||
@ -117,6 +130,8 @@ class BaseListingView(TemplateView):
|
||||
"query_string": query_string,
|
||||
"is_searching": bool(query_string),
|
||||
"next": next_url,
|
||||
"entries_per_page": entries_per_page,
|
||||
"ENTRIES_PER_PAGE_CHOICES": self.ENTRIES_PER_PAGE_CHOICES,
|
||||
"current_ordering": ordering,
|
||||
"ORDERING_OPTIONS": self.ORDERING_OPTIONS,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user