Skip to content
Snippets Groups Projects
Commit a164985c authored by jarmil's avatar jarmil Committed by jan.bednarik
Browse files

Pridano strankovani aktualit. Solves #10

parent bc77e9d0
No related branches found
No related tags found
2 merge requests!68sync test,!64Pridano strankovani aktualit. Solves #10
Pipeline #977 passed
...@@ -145,3 +145,5 @@ cython_debug/ ...@@ -145,3 +145,5 @@ cython_debug/
media_files/ media_files/
static_files/ static_files/
.python-version
.idea/
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models from django.db import models
from django.utils.translation import gettext_lazy from django.utils.translation import gettext_lazy
from wagtail.admin.edit_handlers import ( from wagtail.admin.edit_handlers import (
...@@ -319,6 +320,18 @@ class SenatCampaignNewsIndexPage(Page, SubpageMixin, MetadataPageMixin): ...@@ -319,6 +320,18 @@ class SenatCampaignNewsIndexPage(Page, SubpageMixin, MetadataPageMixin):
def get_context(self, request): def get_context(self, request):
context = super().get_context(request) context = super().get_context(request)
articles = self.get_children().live().order_by("-senatcampaignnewspage__date") articles = self.get_children().live().order_by("-senatcampaignnewspage__date")
paginator = Paginator(articles, 4)
page = request.GET.get("page")
try:
articles = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
articles = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
articles = paginator.page(paginator.num_pages)
context["articles"] = articles context["articles"] = articles
return context return context
......
...@@ -34,30 +34,44 @@ ...@@ -34,30 +34,44 @@
</div> <!-- /row --> </div> <!-- /row -->
{% comment %}{# TODO #} {% if articles.paginator.num_pages > 1 %}
<nav aria-label="Stránkování aktualit"> <nav aria-label="Stránkování aktualit">
<ul class="pagination justify-content-center"> <ul class="pagination justify-content-center">
<li class="page-item active">
<a class="page-link" href="#">1 <span class="sr-only">(current)</span></a> {% if articles.has_previous %}
</li> <li class="page-item"><a class="page-link" href="?page={{ articles.previous_page_number }}">Předchozí</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li> {% endif %}
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"> {% for page_num in articles.paginator.page_range %}
<a class="page-link" href="#">Další</a> {% if page_num == articles.number %}
</li> <li class="page-item active">
<a class="page-link" href="#">{{ page_num }} <span class="sr-only">(current)</span></a>
</li>
{% else %}
<li class="page-item"><a class="page-link" href="?page={{ page_num }}">{{ page_num }}</a></li>
{% endif %}
{% endfor %}
{% if articles.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ articles.next_page_number }}">Další</a></li>
{% endif %}
</ul> </ul>
</nav> </nav>
{% endcomment %}
{% endif %}
</div><!-- /column --> </div><!-- /column -->
{% if page.root_page.facebook %} {% if page.root_page.facebook %}
{% if articles.number == 1 %}
<div class="col-12 col-lg-4 offset-xl-1 text-center"> <div class="col-12 col-lg-4 offset-xl-1 text-center">
<h3 class="lead mb-3">Z mého facebooku</h3> <h3 class="lead mb-3">Z mého facebooku</h3>
<iframe src="https://www.facebook.com/plugins/page.php?href={{ page.root_page.facebook }}&tabs=timeline&width=290&height=500&small_header=true&adapt_container_width=true&hide_cover=true&show_facepile=false&appId=410144066050191" width="290" height="500" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media"></iframe> <iframe src="https://www.facebook.com/plugins/page.php?href={{ page.root_page.facebook }}&tabs=timeline&width=290&height=500&small_header=true&adapt_container_width=true&hide_cover=true&show_facepile=false&appId=410144066050191" width="290" height="500" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media"></iframe>
</div><!-- /column --> </div><!-- /column -->
{% endif %}
{% endif %} {% endif %}
</div> <!-- /row --> </div> <!-- /row -->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment