Daily Dev Notes 2024/06/16
Refactored the pagination links today in DJ Press, and then added some new ones to give some more flexibility. I've always had a goal with this package to be able to create fairly complex templates without needing to understand the models or the context being sent by the views.
So after I created the first template tag to allow a single tag to produce a basic pagination block of code, I immediately wanted to be able to create custom pagination code. You can see the results on this blog, but effectively, I created template tags to support the following template code:
{% is_paginated as paginated %}
{% if paginated %}
<span role="group">
{% get_pagination_range as page_range %}
{% get_pagination_current_page as current_page %}
{% for page in page_range %}
{% if page == current_page %}
<button aria-current="true" disabled>{{ page }}</button>
{% else %}
<a href="?page={{ page }}" role="button" title="Go to page {{ page }}">{{ page }}</a>
{% endif %}
{% endfor %}
</span>
The three tags are:
is_paginated
- returnsTrue
orFalse
if we have a paginated object.get_pagination_range
- returns arange
of page numbers that can be iterated over.get_pagination_current_page
- returns the current page number.
I've built a similar group of pagination buttons with Pico CSS to the Pagination component included in the Bootstrap docs. And I'm pretty happy with it. 😀