Re: [Django] #36174: Apply optional pagination to history_view. (was: Add "Show All" option when pagination is applied on the admin history page.)

4 views
Skip to first unread message

Django

unread,
Feb 7, 2025, 10:40:20 PM2/7/25
to django-...@googlegroups.com
#36174: Apply optional pagination to history_view.
-------------------------------+--------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: New feature | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: pagination | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Antoliny):

* summary:
Add "Show All" option when pagination is applied on the admin history
page.
=> Apply optional pagination to history_view.


Old description:

> In the admin change list page, pagination can be optionally applied
> through the `list_per_page` option of `ModelAdmin`.
> {{{
> class PostAdmin(admin.ModelAdmin):
> list_display = ["title"]
> list_per_page = 3
>
> admin.site.register(Post, PostAdmin)
> }}}
> [[Image(change_list_pagination.png)]]
> As shown in the image above, pagination related elements are rendered.
> Among them, a "Show all" button is provided, which allows users to view
> all objects when clicked.
>
> In the admin History page, pagination is also applied automatically (not
> optionally) when the number of items exceeds 100, but the "Show all"
> option is not provided.
> [[Image(history_view_pagination.png)]]
>
> Since pagination is automatically applied in history_view, I believe
> history_view also needs a "Show all" button.
>
> === Additionally ===
>
> I looked into why there are differences between the pagination applied in
> the history_view and the change_list. When the history_view was first
> implemented, this aspect was naturally considered, but I found that the
> pagination related template tags(pagination, pagination_number) only work
> with `ChangeList`.
> {{{
> def pagination(cl):
> """
> Generate the series of links to the pages in a paginated list.
> """
> pagination_required = (not cl.show_all or not cl.can_show_all) and
> cl.multi_page
> page_range = cl.paginator.get_elided_page_range(cl.page_num) if
> pagination_required else []
> need_show_all_link = cl.can_show_all and not cl.show_all and
> cl.multi_page
> return {
> 'cl': cl,
> 'pagination_required': pagination_required,
> 'show_all_url': need_show_all_link and
> cl.get_query_string({ALL_VAR: ''}),
> 'page_range': page_range,
> 'ALL_VAR': ALL_VAR,
> '1': 1,
> }
> }}}
> I strongly feel that this issue should be resolved so that pagination is
> applied consistently across the Admin pages.
> (I will create a separate issue regarding this matter.)

New description:

Currently, pagination in history_view is applied automatically (when
EntryObjects exceed 100).
[[Image(history_view_pagination.png)]]
{{{
def history_view(...):
paginator = self.get_paginator(request, action_list, 100)
page_number = request.GET.get(PAGE_VAR, 1)
page_obj = paginator.get_page(page_number)
page_range = paginator.get_elided_page_range(page_obj.number)

context = {
**self.admin_site.each_context(request),
"title": _("Change history: %s") % obj,
"subtitle": None,
"action_list": page_obj,
"page_range": page_range,
"page_var": PAGE_VAR,
"pagination_required": paginator.count > 100,
}}}
As shown in the code above, the pagination value(100) is static, and I
would like it to be optionally provided, similar to how pagination is
applied in `list_display`.
{{{
class PostAdmin(admin.ModelAdmin):
list_display = ["title"]
list_per_page = 3
example) list_per_history = xx
}}}
Moreover, since the "Show all" button available in list_display is not
provided in history_view, this need feels even more necessary.
(Even if the "Show all" button is not provided, I believe this
functionality is still necessary. It is especially useful when searching
for a specific object using text(Ex.. Mac Command + F) search or similar
features when pagination is not applied.)

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36174#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages