Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
add pagination to news list
Browse files Browse the repository at this point in the history
  • Loading branch information
ana-balica committed Jan 27, 2015
1 parent 1ec92c6 commit 5713849
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion systers_portal/blog/views.py
Expand Up @@ -16,7 +16,7 @@ class CommunityNewsListView(UserDetailsMixin, CommunityMenuMixin,
"""List of Community news view"""
template_name = "blog/news_list.html"
page_slug = 'news'
# TODO: add pagination
paginate_by = 5

def get(self, request, *args, **kwargs):
self.object = self.get_object(queryset=Community.objects.all())
Expand Down
1 change: 1 addition & 0 deletions systers_portal/templates/blog/news_list.html
Expand Up @@ -24,6 +24,7 @@ <h3 class="title"><a href="{{ news.get_absolute_url }}">{{ news.title }}</a></h3
</div>
<hr>
{% endfor %}
{% include "blog/snippets/pagination.html" %}
</div>
{% endblock %}

Expand Down
39 changes: 39 additions & 0 deletions systers_portal/templates/blog/snippets/pagination.html
@@ -0,0 +1,39 @@
{% if is_paginated %}
<nav>
<ul class="pagination">
{% if page_obj.has_previous %}
<li>
<a href="?page={{ page_obj.previous_page_number }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{% else %}
<li class="disabled">
<a href="#" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{% endif %}

{% for page in paginator.page_range %}
<li {% if page == page_obj.number %}class="active"{% endif %}>
<a href="?page={{ page }}">{{ page }}</a>
</li>
{% endfor %}

{% if page_obj.has_next %}
<li>
<a href="?page={{ page_obj.next_page_number }}" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{% else %}
<li {% if not page_obj.has_next %}class="disabled"{% endif %}>
<a href="#" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}

0 comments on commit 5713849

Please sign in to comment.