From ea495e8f290571bb1922b916c6e2a944b720f1d1 Mon Sep 17 00:00:00 2001 From: Evarin Date: Sat, 20 Jan 2018 19:33:50 +0100 Subject: [PATCH] Archives beta --- gestioncof/cms/models.py | 16 ++++++++++++++++ .../templates/cofcms/cof_actu_index_page.html | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/gestioncof/cms/models.py b/gestioncof/cms/models.py index 71e76bb8..e63acde7 100644 --- a/gestioncof/cms/models.py +++ b/gestioncof/cms/models.py @@ -62,6 +62,22 @@ class COFActuIndexPage(Page, COFActuIndexMixin): verbose_name = "Index des actualités" verbose_name_plural = "Indexs des actualités" + def get_context(self, request): + context = super(COFActuIndexPage, self).get_context(request) + actus = COFActuPage.objects.live().descendant_of(self).order_by('-date') + + page = request.GET.get('page') + paginator = Paginator(actus, 5) + try: + actus = paginator.page(page) + except PageNotAnInteger: + actus = paginator.page(1) + except EmptyPage: + actus = paginator.page(paginator.num_pages) + + context['actus'] = actus + return context + class COFActuPage(Page): body = RichTextField("Contenu") date = models.DateField("Date du post") diff --git a/gestioncof/cms/templates/cofcms/cof_actu_index_page.html b/gestioncof/cms/templates/cofcms/cof_actu_index_page.html index affd433d..975e520d 100644 --- a/gestioncof/cms/templates/cofcms/cof_actu_index_page.html +++ b/gestioncof/cms/templates/cofcms/cof_actu_index_page.html @@ -12,6 +12,13 @@
+ {% if actus.has_previous %} + Actualités plus récentes + {% endif %} + {% if actus.has_next %} + Actualités plus anciennes + {% endif %} + {% for actu in page.actus %}
@@ -26,5 +33,12 @@
{% endfor %} + + {% if actus.has_previous %} + Actualités plus récentes + {% endif %} + {% if actus.has_next %} + Actualités plus anciennes + {% endif %}
{% endblock %}