It requires the current page number in order to render range range
correctly. Without the page number it always renders as if you are on page
one.
This means when one tries to use it in the template like this:
{{{
{% for i in paginator.get_elided_page_range %}
...
{% endfor %}
}}}
It renders only correctly when one is on page one, because the `paginator`
does not know the current page.
I stumbled across this [https://stackoverflow.com/questions/69277936/how-
to-use-get-elided-page-range-in-django-paginator stackoverflow question]
that someone else posted.
However the `page_obj` knows the current page number (`self.number`), and
it has `self.paginator`. It's quite trivial to just delegate the call.
In file `django.core.paginator.py` at the very bottom just add this to
`class Page`:
{{{
def get_elided_page_range(self, *args, **kwargs):
return self.paginator.get_elided_page_range(self.number, *args,
**kwargs)
}}}
Then in the template one can simply do:
{{{
{% for i in page_obj.get_elided_page_range %}
...
{% endfor %}
}}}
And everything works as expected.
If the general consenseus is this is a good thing, and I am not missing
something that already fixes this problem, I can try create a patch and
update the documentation.
And heres a more complete example usage:
{{{
{% for i in page_obj.get_elided_page_range %}
{% if i == page_obj.number %}
<div>{{ i }}</div>
{% elif i == paginator.ELLIPSIS %}
<div>{{ i }}</div>
{% else %}
<a href="{% paginator_url i %}">{{ i }}</a>
{% endif %}
{% endfor %}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33404>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: 0 => 1
* type: Uncategorized => New feature
* easy: 0 => 1
* stage: Unreviewed => Accepted
Comment:
I think it's a great idea and it makes sense.
--
Ticket URL: <https://code.djangoproject.com/ticket/33404#comment:1>
* owner: nobody => m_moeinzadeh
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/33404#comment:2>
Comment (by m_moeinzadeh):
It's impossible to do because in order for `get_elided_page_range` to know
the page number you need to pass the number to the method directly or pass
the number inside of paginator object.
--
Ticket URL: <https://code.djangoproject.com/ticket/33404#comment:3>
* owner: m_moeinzadeh => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/33404#comment:4>
* status: new => closed
* resolution: => invalid
--
Ticket URL: <https://code.djangoproject.com/ticket/33404#comment:5>