mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 07:41:14 +00:00
club: add pagination for ClubSellingView
This commit is contained in:
parent
a73f5cb270
commit
8dd2c02d3e
@ -1,9 +1,9 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
{% from 'core/macros.jinja' import user_profile_link %}
|
||||
{% from 'core/macros.jinja' import user_profile_link, paginate %}
|
||||
|
||||
{% block content %}
|
||||
<h3>{% trans %}Sellings{% endtrans %}</h3>
|
||||
<form action="" method="post">
|
||||
<form action="?page=1" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<p><input type="submit" value="{% trans %}Show{% endtrans %}" /></p>
|
||||
@ -53,6 +53,7 @@
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{{ paginate(result, paginator) }}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -36,6 +36,7 @@ from django.utils import timezone
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext as _t
|
||||
from django.core.exceptions import PermissionDenied, ValidationError, NON_FIELD_ERRORS
|
||||
from django.core.paginator import Paginator, InvalidPage
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.db.models import Sum
|
||||
|
||||
@ -331,6 +332,14 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailFormView):
|
||||
template_name = "club/club_sellings.jinja"
|
||||
current_tab = "sellings"
|
||||
form_class = SellingsForm
|
||||
paginate_by = 70
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
try:
|
||||
self.asked_page = int(request.GET.get("page", 1))
|
||||
except ValueError:
|
||||
raise Http404
|
||||
return super(ClubSellingView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(ClubSellingView, self).get_form_kwargs()
|
||||
@ -381,6 +390,12 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailFormView):
|
||||
if benefit["product__purchase_price__sum"]:
|
||||
kwargs["benefit"] = benefit["product__purchase_price__sum"]
|
||||
|
||||
kwargs["paginator"] = Paginator(kwargs["result"], self.paginate_by)
|
||||
try:
|
||||
kwargs["result"] = kwargs["paginator"].page(self.asked_page)
|
||||
except InvalidPage:
|
||||
raise Http404
|
||||
|
||||
return kwargs
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user