Skip to content
This repository has been archived by the owner on Oct 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #367 from aldryn/feature/pagenav
Browse files Browse the repository at this point in the history
Update pagination.html
  • Loading branch information
FinalAngel committed Mar 16, 2016
2 parents 019e561 + fe3be20 commit 4d40a2d
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ CHANGELOG
=========


1.2.1 (UNRELEASED)
-------------------
* Adapt pagenav to hide too many entries
* Pagenav shows "..." if there are to many pages forward or backwards


1.2.0 (2016-03-10)
-------------------

Expand Down
4 changes: 2 additions & 2 deletions aldryn_newsblog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ class NewsBlogConfigAdmin(
def get_config_fields(self):
return (
'app_title', 'permalink_type', 'non_permalink_handling',
'template_prefix',
'paginate_by', 'create_authors', 'search_indexed',
'template_prefix', 'paginate_by', 'pagination_pages_start',
'pagination_pages_visible', 'create_authors', 'search_indexed',
'config.default_published', )

admin.site.register(models.NewsBlogConfig, NewsBlogConfigAdmin)
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
{% load i18n %}

{% if is_paginated %}
<ul>
<ul class="pagination">
{% if page_obj.has_previous %}
{% if page_obj.number > pagination.pages_visible_total %}
<li>
<a href="?page={{ page_obj.paginator.page_range|first }}" aria-label="{% trans 'First' %}" title="{% trans 'First' %}">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{% endif %}
<li>
<a href="?page={{ page_obj.previous_page_number }}" aria-label="{% trans "Previous" %}>
<span aria-hidden="true">&laquo;</span>
<a href="?page={{ page_obj.previous_page_number }}" aria-label="{% trans 'Previous' %}" title="{% trans 'Previous' %}">
<span aria-hidden="true">&lsaquo;</span>
</a>
</li>
{% endif %}

{% if paginator.num_pages > 10 %}
{% if page_obj.number > 5 %}
<li><a href="?page={{ page_obj.number|add:-5 }}">...</a></li>
{% if paginator.num_pages > pagination.pages_start %}
{% if page_obj.number > pagination.pages_visible_total %}
<li><a href="?page={{ page_obj.number|add:pagination.pages_visible_total_negative }}">...</a></li>
{% endif %}

{% for num in paginator.page_range %}
{% if num == page_obj.number %}
<li class="active"><span>{{ num }}</span></li>
{% elif num > page_obj.number|add:-5 and num < page_obj.number|add:5 %}
{% elif num > page_obj.number|add:pagination.pages_visible_total_negative and num < page_obj.number|add:pagination.pages_visible_total %}
<li><a href="?page={{ num }}">{{ num }}</a></li>
{% endif %}
{% endfor %}

{% if page_obj.number < paginator.num_pages|add:-4 %}
<li><a href="?page={{ page_obj.number|add:5 }}">...</a></li>
{% if page_obj.number < paginator.num_pages|add:pagination.pages_visible_negative %}
<li><a href="?page={{ page_obj.number|add:pagination.pages_visible_total }}">...</a></li>
{% endif %}
{% else %}
{% for num in page_obj.paginator.page_range %}
Expand All @@ -38,10 +44,17 @@

{% if page_obj.has_next %}
<li>
<a href="?page={{ page_obj.next_page_number }}" aria-label="{% trans "Next" %}>
<span aria-hidden="true">&raquo;</span>
<a href="?page={{ page_obj.next_page_number }}" aria-label="{% trans 'Next' %}" title="{% trans 'Next' %}">
<span aria-hidden="true">&rsaquo;</span>
</a>
</li>
{% if page_obj.number < paginator.num_pages|add:pagination.pages_visible_negative %}
<li>
<a href="?page={{ paginator.num_pages }}" aria-label="{% trans 'Last' %}" title="{% trans 'Last' %}">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{% endif %}
{% endif %}
</ul>
{% endif %}
15 changes: 14 additions & 1 deletion aldryn_newsblog/cms_appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,26 @@ class NewsBlogConfig(TranslatableModel, AppHookConfig):
choices=NON_PERMALINK_HANDLING,
help_text=_('How to handle non-permalink urls?'))

# ALDRYN_NEWSBLOG_PAGINATE_BY
paginate_by = models.PositiveIntegerField(
_('Paginate size'),
blank=False,
default=5,
help_text=_('When paginating list views, how many articles per page?'),
)
pagination_pages_start = models.PositiveIntegerField(
_('Pagination pages start'),
blank=False,
default=10,
help_text=_('When paginating list views, after how many pages '
'should we start grouping the page numbers.'),
)
pagination_pages_visible = models.PositiveIntegerField(
_('Pagination pages visible'),
blank=False,
default=4,
help_text=_('When grouping page numbers, this determines how many '
'pages are visible on each side of the active page.'),
)

template_prefix = models.CharField(
max_length=20,
Expand Down
24 changes: 24 additions & 0 deletions aldryn_newsblog/migrations/0010_auto_20160316_0935.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('aldryn_newsblog', '0009_auto_20160211_1022'),
]

operations = [
migrations.AddField(
model_name='newsblogconfig',
name='pagination_pages_start',
field=models.PositiveIntegerField(default=10, help_text='When paginating list views, after how many pages should we start grouping the page numbers.', verbose_name='Pagination pages start'),
),
migrations.AddField(
model_name='newsblogconfig',
name='pagination_pages_visible',
field=models.PositiveIntegerField(default=4, help_text='When grouping page numbers, this determines how many pages are visible on each side of the active page.', verbose_name='Pagination pages visible'),
),
]

0 comments on commit 4d40a2d

Please sign in to comment.