Remove the use of dj-pagination

Issue #134 invalid
M G created an issue

Django-postman optionally uses dj-pagination. However, this package is not maintained anymore (since 2021) and does not work with recent Django versions due to the ifequal template tag (deprecated in 2020).

Nowadays, one can easily create a pagination with a custom tag:

@register.simple_tag(takes_context=True)
def paginate_qs(context, queryset, per_page=10, page_attr="page"):
    """Paginate a queryset and store the pagination in the context."""
    paginator = Paginator(queryset, per_page)
    page_number = context["request"].GET.get(page_attr, "1")
    if re.match(r"^(0|[1-9]\d*)$", page_number):
        page = paginator.get_page(int(page_number))
    else:
        page = paginator.get_page(1)
    return page

and add this simple line in the base_folder.html template:

{% paginate_qs pm_messages per_page=10 as pm_messages_p %}
 <tbody>{% for message in pm_messages_p %}

I have also added the following pagination tag, using Django-bootstrap5, at the end of the form:

{% bootstrap_pagination pm_messages_p size='sm' justify_content='center' %}

Comments (3)

  1. Log in to comment