{% endif %}
{% if products.has_other_pages %}
{% with p_url=request.get_full_path %}
{% if products.has_previous %}
«
{% else %}
«
{% endif %}
{% for i in products.paginator.page_range %}
{# if we're beyond the first five pages, just show "..." until three pages before the current page #}
{# e.g. on page 12 show: "... 9 10 11 12" #}
{% if products.number > 5 and i < products.number|subtract:4 %}
{% if i|subtract:3 <= 0 %}{{ i }}{% endif %}
{% elif products.number > 5 and i == products.number|subtract:4 %}
{# show '...' #}
...
{# if we're before the last five pages, just show "..." for pages more than three after the current page #}
{# e.g. on page 1 of 10 show: "1 2 3 4 ..." #}
{% elif products.number < products.paginator.num_pages|subtract:5 and i > products.number|add:4 %}
{% if i|add:3 > products.paginator.num_pages %}{{ i }}{% endif %}
{% elif products.number < products.paginator.num_pages|subtract:5 and i == products.number|add:4 %}
{# show '...' #}
...
{% elif products.number == i %}
{{ i }}
{% else %}
{{ i }}
{% endif %}
{% endfor %}
{% if products.has_next %}
»
{% else %}
»
{% endif %}