club: add pagination for ClubSellingView

This commit is contained in:
Antoine Bartuccio 2019-11-28 00:30:51 +01:00
parent a73f5cb270
commit 8dd2c02d3e
Signed by: klmp200
GPG Key ID: E7245548C53F904B
2 changed files with 18 additions and 2 deletions

View File

@ -1,9 +1,9 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %} {% from 'core/macros.jinja' import user_profile_link, paginate %}
{% block content %} {% block content %}
<h3>{% trans %}Sellings{% endtrans %}</h3> <h3>{% trans %}Sellings{% endtrans %}</h3>
<form action="" method="post"> <form action="?page=1" method="post">
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
<p><input type="submit" value="{% trans %}Show{% endtrans %}" /></p> <p><input type="submit" value="{% trans %}Show{% endtrans %}" /></p>
@ -53,6 +53,7 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{{ paginate(result, paginator) }}
{% endblock %} {% endblock %}

View File

@ -36,6 +36,7 @@ from django.utils import timezone
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext as _t from django.utils.translation import ugettext as _t
from django.core.exceptions import PermissionDenied, ValidationError, NON_FIELD_ERRORS 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.shortcuts import get_object_or_404, redirect
from django.db.models import Sum from django.db.models import Sum
@ -331,6 +332,14 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailFormView):
template_name = "club/club_sellings.jinja" template_name = "club/club_sellings.jinja"
current_tab = "sellings" current_tab = "sellings"
form_class = SellingsForm 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): def get_form_kwargs(self):
kwargs = super(ClubSellingView, self).get_form_kwargs() kwargs = super(ClubSellingView, self).get_form_kwargs()
@ -381,6 +390,12 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailFormView):
if benefit["product__purchase_price__sum"]: if benefit["product__purchase_price__sum"]:
kwargs["benefit"] = 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 return kwargs