Archives beta

This commit is contained in:
Evarin 2018-01-20 19:33:50 +01:00
parent adf43889e1
commit ea495e8f29
2 changed files with 30 additions and 0 deletions

View file

@ -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")

View file

@ -12,6 +12,13 @@
</section>
<section class="actulist">
{% if actus.has_previous %}
<a class="block prev-actus" href="?page={{ actus.previous_page_number }}{% for key,value in request.GET.items %}{% ifnotequal key 'page' %}&amp;{{ key }}={{ value }}{% endifnotequal %}{% endfor %}">Actualités plus récentes</a>
{% endif %}
{% if actus.has_next %}
<a class="block next-actus" href="?page={{ actus.next_page_number }}{% for key,value in request.GET.items %}{% ifnotequal key 'page' %}&amp;{{ key }}={{ value }}{% endifnotequal %}{% endfor %}">Actualités plus anciennes</a>
{% endif %}
{% for actu in page.actus %}
<article class="actu">
<div class="actu-image" {% if actu.image %}{% image actu.image fill-400x200 as img %}style="background-image:url('{{ img.url }}');"{% endif %}></div>
@ -26,5 +33,12 @@
</div>
</article>
{% endfor %}
{% if actus.has_previous %}
<a class="block prev-actus" href="?page={{ actus.previous_page_number }}{% for key,value in request.GET.items %}{% ifnotequal key 'page' %}&amp;{{ key }}={{ value }}{% endifnotequal %}{% endfor %}">Actualités plus récentes</a>
{% endif %}
{% if actus.has_next %}
<a class="block next-actus" href="?page={{ actus.next_page_number }}{% for key,value in request.GET.items %}{% ifnotequal key 'page' %}&amp;{{ key }}={{ value }}{% endifnotequal %}{% endfor %}">Actualités plus anciennes</a>
{% endif %}
</section>
{% endblock %}