From: Emilie Date: Wed, 14 Sep 2016 09:58:14 +0000 (+0200) Subject: Topic : paginate article / 4 per pages just for tests X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=a98be8d44af17ee124ecc88ef4311c74982e7b9b;p=mezzo.git Topic : paginate article / 4 per pages just for tests --- diff --git a/app/local_settings.py b/app/local_settings.py index cad3a8f6..7ac1ecef 100644 --- a/app/local_settings.py +++ b/app/local_settings.py @@ -112,6 +112,7 @@ else: SLUGIFY = 'django.template.defaultfilters.slugify' BLOG_POST_PER_PAGE = 200 +ARTICLE_PER_PAGE = 4 # just for tests because we haven't got enough content # The numeric mode to set newly-uploaded files to. The value should be # a mode you'd pass directly to os.chmod. diff --git a/app/organization/magazine/views.py b/app/organization/magazine/views.py index 8cfd7610..29c2f010 100644 --- a/app/organization/magazine/views.py +++ b/app/organization/magazine/views.py @@ -10,6 +10,8 @@ from itertools import chain from dal import autocomplete from dal_select2_queryset_sequence.views import Select2QuerySetSequenceView from mezzanine_agenda.models import Event +from mezzanine.utils.views import paginate +from mezzanine.conf import settings from organization.magazine.models import Article, Topic, Brief from organization.network.models import DepartmentPage from organization.pages.models import CustomPage @@ -53,6 +55,7 @@ class BriefDetailView(SlugMixin, DetailView): context = super(BriefDetailView, self).get_context_data(**kwargs) return context + class BriefListView(SlugMixin, ListView): model = Brief @@ -72,6 +75,11 @@ class TopicDetailView(SlugMixin, DetailView): def get_context_data(self, **kwargs): context = super(TopicDetailView, self).get_context_data(**kwargs) + # paginate "manually" articles because we are not in a ListView + articles = paginate(self.object.articles.all(), self.request.GET.get("page", 1), + settings.ARTICLE_PER_PAGE, + settings.MAX_PAGING_LINKS) + context['articles'] = articles return context diff --git a/app/templates/magazine/topic/topic_detail.html b/app/templates/magazine/topic/topic_detail.html index 3a4a3f61..d7db68d8 100644 --- a/app/templates/magazine/topic/topic_detail.html +++ b/app/templates/magazine/topic/topic_detail.html @@ -61,12 +61,12 @@
- {% for article in topic.articles.all %} + {% for article in articles %}
{% include 'magazine/article/includes/article_card.html' %}
{% endfor %}
- + {% pagination_for articles %} {% endblock %}