Skip to content

Commit

Permalink
Refactored pagination into include
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Willison committed Oct 1, 2017
1 parent a76b691 commit 6c24d9f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
3 changes: 3 additions & 0 deletions static/css/all.css
Expand Up @@ -641,6 +641,9 @@ div.paginator {
padding: 0.5em 0; padding: 0.5em 0;
font-size: 0.9em font-size: 0.9em
} }
.pagination {
margin-bottom: 1em;
}
.paginator a { .paginator a {
text-decoration: none text-decoration: none
} }
Expand Down
24 changes: 24 additions & 0 deletions templates/_pagination.html
@@ -0,0 +1,24 @@
{% if page.paginator.num_pages > 1 %}{% load blog_tags %}
<div class="pagination">
{% if page_total %}
<strong>{{ page_total }} result{{ page_total|pluralize }}</strong>
{% endif %}
<span class="step-links">
{% if page.has_previous %}
<a href="{% page_href page.previous_page_number %}">&laquo; previous</a>
{% endif %}
<span class="current">
page {{ page.number }} / {{ page.paginator.num_pages }}
</span>
{% if page.has_next %}
<a href="{% page_href page.next_page_number %}">next &raquo;</a>
{% endif %}
</span>
</div>
{% else %}
{% if page_total %}
<div class="pagination">
<strong>{{ page_total }} result{{ page_total|pluralize }}</strong>
</div>
{% endif %}
{% endif %}
16 changes: 1 addition & 15 deletions templates/archive_tag.html
Expand Up @@ -8,21 +8,7 @@ <h2>{{ total }} item{{ total|pluralize }} tagged “{{ tags|join:"” and “"|e


{% blog_mixed_list_with_dates items %} {% blog_mixed_list_with_dates items %}


{% if page.paginator.num_pages > 1 %} {% include "_pagination.html" %}
<div class="pagination">
<span class="step-links">
{% if page.has_previous %}
<a href="{% page_href page.previous_page_number %}">&laquo; previous</a>
{% endif %}
<span class="current">
Page {{ page.number }} / {{ page.paginator.num_pages }}
</span>
{% if page.has_next %}
<a href="{% page_href page.next_page_number %}">next &raquo;</a>
{% endif %}
</span>
</div>
{% endif %}


{% endblock %} {% endblock %}


Expand Down
18 changes: 2 additions & 16 deletions templates/search.html
Expand Up @@ -13,23 +13,9 @@ <h2>Search{% if q %} for “{{ q }}”{% endif %}</h2>
<br> <br>


{% if total %} {% if total %}
<p><strong>{{ total }} result{{ total|pluralize }}</strong></p> {% include "_pagination.html" with page_total=total %}
{% blog_mixed_list_with_dates results %} {% blog_mixed_list_with_dates results %}
{% if page.paginator.num_pages > 1 %} {% include "_pagination.html" %}
<div class="pagination">
<span class="step-links">
{% if page.has_previous %}
<a href="{% page_href page.previous_page_number %}">&laquo; previous</a>
{% endif %}
<span class="current">
Page {{ page.number }} / {{ page.paginator.num_pages }}
</span>
{% if page.has_next %}
<a href="{% page_href page.next_page_number %}">next &raquo;</a>
{% endif %}
</span>
</div>
{% endif %}
{% endif %} {% endif %}


{% endblock %} {% endblock %}

0 comments on commit 6c24d9f

Please sign in to comment.