Browse Source

PaginatedResults: use id36s for before/after

This was previously using regular integer IDs, but it should have been
ID36s.
merge-requests/22/head
Deimos 6 years ago
parent
commit
2de03d719e
  1. 16
      tildes/tildes/models/pagination.py
  2. 4
      tildes/tildes/templates/topic_listing.jinja2
  3. 4
      tildes/tildes/templates/user.jinja2

16
tildes/tildes/models/pagination.py

@ -5,7 +5,7 @@ from typing import Any, Iterator, List, Optional, TypeVar
from pyramid.request import Request from pyramid.request import Request
from sqlalchemy import Column, func, inspect from sqlalchemy import Column, func, inspect
from tildes.lib.id import id36_to_id
from tildes.lib.id import id_to_id36, id36_to_id
from .model_query import ModelQuery from .model_query import ModelQuery
@ -206,17 +206,19 @@ class PaginatedResults:
return len(self.results) return len(self.results)
@property @property
def next_page_after_id(self) -> int:
"""Return "after" ID that should be used to fetch the next page."""
def next_page_after_id36(self) -> str:
"""Return "after" ID36 that should be used to fetch the next page."""
if not self.has_next_page: if not self.has_next_page:
raise AttributeError raise AttributeError
return inspect(self.results[-1]).identity[0]
next_id = inspect(self.results[-1]).identity[0]
return id_to_id36(next_id)
@property @property
def prev_page_before_id(self) -> int:
"""Return "before" ID that should be used to fetch the prev page."""
def prev_page_before_id36(self) -> str:
"""Return "before" ID36 that should be used to fetch the prev page."""
if not self.has_prev_page: if not self.has_prev_page:
raise AttributeError raise AttributeError
return inspect(self.results[0]).identity[0]
prev_id = inspect(self.results[0]).identity[0]
return id_to_id36(prev_id)

4
tildes/tildes/templates/topic_listing.jinja2

@ -154,13 +154,13 @@
<div class="pagination"> <div class="pagination">
{% if topics.has_prev_page %} {% if topics.has_prev_page %}
<a class="page-item btn" id="prev-page" <a class="page-item btn" id="prev-page"
href="{{ request.current_listing_base_url({'before': topics.prev_page_before_id}) }}"
href="{{ request.current_listing_base_url({'before': topics.prev_page_before_id36}) }}"
>Prev</a> >Prev</a>
{% endif %} {% endif %}
{% if topics.has_next_page %} {% if topics.has_next_page %}
<a class="page-item btn" id="next-page" <a class="page-item btn" id="next-page"
href="{{ request.current_listing_base_url({'after': topics.next_page_after_id}) }}"
href="{{ request.current_listing_base_url({'after': topics.next_page_after_id36}) }}"
>Next</a> >Next</a>
{% endif %} {% endif %}
</div> </div>

4
tildes/tildes/templates/user.jinja2

@ -52,13 +52,13 @@
<div class="pagination"> <div class="pagination">
{% if posts.has_prev_page %} {% if posts.has_prev_page %}
<a class="page-item btn" id="prev-page" <a class="page-item btn" id="prev-page"
href="{{ request.current_listing_base_url({'before': posts.prev_page_before_id}) }}"
href="{{ request.current_listing_base_url({'before': posts.prev_page_before_id36}) }}"
>Prev</a> >Prev</a>
{% endif %} {% endif %}
{% if posts.has_next_page %} {% if posts.has_next_page %}
<a class="page-item btn" id="next-page" <a class="page-item btn" id="next-page"
href="{{ request.current_listing_base_url({'after': posts.next_page_after_id}) }}"
href="{{ request.current_listing_base_url({'after': posts.next_page_after_id36}) }}"
>Next</a> >Next</a>
{% endif %} {% endif %}
</div> </div>

Loading…
Cancel
Save