Opened 8 years ago

Closed 8 years ago

#5699 closed (invalid)

Generic views' page_range values incomparable to (current) page integer

Reported by: Simon Litchfield <simon@…> Owned by: nobody
Component: Generic views Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Consider this typical example --

<div class="pagenav">

Page
{% for p in page_range %}
<a href="{{ url }}{{ p }}/"{% ifequal page p %} class="sel"{% endifequal %}>{{ p }}</a>
{% endfor %}
{% if next_page %}
<a href="{{ url }}{{ next_page }}/">Next</a>
{% endif %}

</div>

Ooops, doesn't work! Ifequal doesn't seem to be able to compare the current page (integer) to variables in the page_range list.

Aside, it seems type handling can be unnecessarily tedious at times, particularly when using things like Decimal.

Change History (2)

comment:1 Changed 8 years ago by Simon Litchfield

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Let me try that again --

<div class="pagenav">
    Page
    {% for p in page_range %}
    <a href="{{ url }}{{ p }}/"{% ifequal page p %} class="sel"{% endifequal %}>{{ p }}</a>
    {% endfor %}
    {% if next_page %}
    <a href="{{ url }}{{ next_page }}/">Next</a>
    {% endif %}
</div>

comment:2 Changed 8 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to closed

Seems to work fine here. Using this test case and the template fragment you posted

data = {
    'queryset': Session.objects.all(),
    'template_name': 'foo.html',
    'paginate_by': 2,
}

urlpatterns = patterns('',
        (r'^example/(?P<page>\d+)/$', object_list, data),
)

with more than two items in my sessions table, I get the "page" item having the "sel" class added (and only that item).

Please reopen if you have a short, complete example that demonstrates the problem.

Note: See TracTickets for help on using tickets.
Back to Top