Pengin-Open-Source / pengin-pi-2

Pengin-Pi Django version
GNU General Public License v3.0
1 stars 1 forks source link

21 feature pagination template tag #22

Closed franfif closed 3 months ago

franfif commented 5 months ago

See issue #21

Added pagination template to include on any page requiring pagination. The view should use the Django provided Paginator class and return the current page.

I also replaced the call to paginate macro in forums/threads_html and jobs_applications. Other templates have a pagination bu didn't use the macro.

Next: all pages using pagination should include the template "components/pagination.html" passing the current page from the Django Paginator get_page() method.

For instance, in the Product list view:

from django.core.paginator import Paginator

[...]
class ListProduct(View):
    def get(self, request, is_admin):
        # some code to define queryset

        paginator = Paginator(products, 9)  # queryset and number of objects per page
        page_number = request.GET.get("page", 1)
        page_products = paginator.get_page(page_number)

        return render(request, self.template_name, {
                    "is_admin": is_admin,
                    "page_products": page_products,
                    "primary_title": "Products",
                })

and in the product list template:

{% include "components/pagination.html" with page=page_products %}
franfif commented 5 months ago

Switch back to macros using django-macros package. Still using the Django's Paginator class as previously described.

To use the macros in templates:

{% load macros %}  # At the top of the template
{% loadmacros "macros/pagination.html" %}

[...]

{% use_macro render_pagination applications.items %}  # When the macro must be used

I corrected the three places where this macros is being used: job_applications.html, forums/threads.html and products.html.