diff --git a/tildes/tildes/models/pagination.py b/tildes/tildes/models/pagination.py index c4c6d8c..d80ff64 100644 --- a/tildes/tildes/models/pagination.py +++ b/tildes/tildes/models/pagination.py @@ -3,7 +3,7 @@ from typing import Any, Iterator, List, Optional, TypeVar from pyramid.request import Request -from sqlalchemy import Column, func +from sqlalchemy import Column, func, inspect from tildes.lib.id import id36_to_id from .model_query import ModelQuery @@ -204,3 +204,19 @@ class PaginatedResults: def __len__(self) -> int: """Return the number of results.""" return len(self.results) + + @property + def next_page_after_id(self) -> int: + """Return "after" ID that should be used to fetch the next page.""" + if not self.has_next_page: + raise AttributeError + + return inspect(self.results[-1]).identity[0] + + @property + def prev_page_before_id(self) -> int: + """Return "before" ID that should be used to fetch the prev page.""" + if not self.has_prev_page: + raise AttributeError + + return inspect(self.results[0]).identity[0] diff --git a/tildes/tildes/templates/topic_listing.jinja2 b/tildes/tildes/templates/topic_listing.jinja2 index 611fed2..2439d8d8 100644 --- a/tildes/tildes/templates/topic_listing.jinja2 +++ b/tildes/tildes/templates/topic_listing.jinja2 @@ -154,13 +154,13 @@