Задать вопрос

Тел: +7 965 3737 888

525

Просмотров

2

Ответов

Page numbers with ... like in Digg

<p>Digg-like page numbering using inclusion tag.</p>
<p>Usage in template:</p>
{% load pagination %}
{% pagination yourpage %}

<p>Inclusion template pagination.html:</p>
{% load i18n %}
&lt;div class="pagination"&gt;
    &lt;span class="step-links"&gt;
    {% if page.has_previous %}
        &lt;a href="?page={{ page.previous_page_number }}" class="previous"&gt;{% trans "previous" %}&lt;/a&gt;
    {% endif %}

        {% for pnum in begin %}
            {% ifequal page.number pnum %}
                &lt;span class="current"&gt;{{ pnum }}&lt;/span&gt;
            {% else %}
                &lt;a href="?page={{ pnum }}"&gt;{{ pnum }}&lt;/a&gt;
            {% endifequal %}
        {% endfor %}

        {% if middle %}
            &lt;span class="continue"&gt;...&lt;/span&gt;
            {% for pnum in middle %}
                {% ifequal page.number pnum %}
                    &lt;span class="current"&gt;{{ pnum }}&lt;/span&gt;
                {% else %}
                    &lt;a href="?page={{ pnum }}"&gt;{{ pnum }}&lt;/a&gt;
                {% endifequal %}
            {% endfor %}
        {% endif %}

        {% if end %}
            &lt;span class="continue"&gt;...&lt;/span&gt;
            {% for pnum in end %}
                {% ifequal page.number pnum %}
                    &lt;span class="current"&gt;{{ pnum }}&lt;/span&gt;
                {% else %}
                    &lt;a href="?page={{ pnum }}"&gt;{{ pnum }}&lt;/a&gt;
                {% endifequal %}
            {% endfor %}
        {% endif %}

    {% if page.has_next %}
        &lt;a href="?page={{ page.next_page_number }}" class="next"&gt;{% trans "next" %}&lt;/a&gt;
    {% endif %}
    &lt;/span&gt;
&lt;/div&gt;

<p>Produces:</p>
<p>previous  1  2  ...  4  5  6  7  <strong>8</strong>  9  10  11  12  ...  17  18  next</p>
<p>Or:</p>
<p><strong>1</strong>  2  3  4  5  6  7  8  ...  17  18  next<br></p>
<p>Or:</p>
<p>previous  1  2  ...  10  11  12  13  14  15  16  <strong>17</strong>  18  next<br></p>

Вопрос полезен? Да0/Нет0
file_3220.py(1.6Кб)
None

Ответы (2):

Ответciantic:20.01.2010
Ответ полезен? Да0/Нет0

This is very much in use, and I would like to know when it fails if it fails...

But note that it is intended to drop entries if there are too many. When user selects entry from closer it will show the next entries, so they are not really gone.

Ответstalker:20.12.2009
Ответ полезен? Да0/Нет0

IMHO, this code have some bad logic, I replaced line 28 with:

end = range(max(page.number-before_current_pages, 1), last_page_number+1)

and line 33 with:

begin = range(1, min(page.number + after_current_pages, last_page_number)+1)

Without those two changes, one can't access (in some cases) all pages with using only generated links