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 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
@ -206,17 +206,19 @@ class PaginatedResults:
return len(self.results)
@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:
raise AttributeError
return inspect(self.results[-1]).identity[0]
next_id = inspect(self.results[-1]).identity[0]
return id_to_id36(next_id)
@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:
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">
{% if topics.has_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>
{% endif %}
{% if topics.has_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>
{% endif %}
</div>

4
tildes/tildes/templates/user.jinja2

@ -52,13 +52,13 @@
<div class="pagination">
{% if posts.has_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>
{% endif %}
{% if posts.has_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>
{% endif %}
</div>

Loading…
Cancel
Save