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

Strankovani projektu ve webu dary. Solves #11

parent a164985c
Branches
No related tags found
2 merge requests!68sync test,!66Strankovani projektu ve webu dary. Solves #11
Pipeline #979 passed
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models
from django.shortcuts import redirect
from django.utils.translation import gettext_lazy
......@@ -61,7 +62,7 @@ class DonateFormMixin(models.Model):
def get_url(page, dest_page_type):
try:
return page.get_children().type(dest_page_type).live().first().get_url()
except Page.DoesNotExist:
except (Page.DoesNotExist, AttributeError):
return "#"
......@@ -323,9 +324,21 @@ class DonateProjectIndexPage(Page, SubpageMixin, MetadataPageMixin):
def get_context(self, request):
context = super().get_context(request)
context["projects"] = (
self.get_children().live().specific().order_by("-donateprojectpage__date")
paginator = Paginator(
self.get_children().live().specific().order_by("-donateprojectpage__date"),
6,
)
page = request.GET.get("page")
try:
projects = paginator.page(page)
except PageNotAnInteger:
projects = paginator.page(1)
except EmptyPage:
projects = paginator.page(paginator.num_pages)
context["projects"] = projects
return context
......
......@@ -18,20 +18,31 @@
</div> <!-- /row -->
{% comment %} {# TODO #}
<nav aria-label="Stránkování projektů">
{% if projects.paginator.num_pages > 1 %}
<nav aria-label="Stránkování aktualit">
<ul class="pagination justify-content-center">
{% if projects.has_previous %}
<li class="page-item"><a class="page-link" href="?page={{ projects.previous_page_number }}">Předchozí</a></li>
{% endif %}
{% for page_num in projects.paginator.page_range %}
{% if page_num == projects.number %}
<li class="page-item active">
<a class="page-link" href="#">1 <span class="sr-only">(current)</span></a>
</li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#">Další</a>
<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 projects.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ projects.next_page_number }}">Další</a></li>
{% endif %}
</ul>
</nav>
{% endcomment %}
{% endif %}
</div> <!-- /container -->
</section>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment