diff --git a/tildes/scss/_base.scss b/tildes/scss/_base.scss index c1087e2..b74483c 100644 --- a/tildes/scss/_base.scss +++ b/tildes/scss/_base.scss @@ -161,6 +161,10 @@ ol { margin-top: 0.2rem; max-width: $paragraph-max-width - 2rem; } + + &:last-child { + margin-bottom: 0.2rem; + } } p { diff --git a/tildes/tildes/__init__.py b/tildes/tildes/__init__.py index 02df50d..655aee9 100644 --- a/tildes/tildes/__init__.py +++ b/tildes/tildes/__init__.py @@ -137,10 +137,11 @@ def current_listing_base_url( The `query` argument allows adding query variables to the generated url. """ - if request.matched_route.name not in ('home', 'group'): + if request.matched_route.name not in ('home', 'group', 'user'): raise AttributeError('Current route is not supported.') - base_view_vars = ('order', 'period', 'per_page', 'tag', 'unfiltered') + base_view_vars = ( + 'order', 'period', 'per_page', 'tag', 'type', 'unfiltered') query_vars = { key: val for key, val in request.GET.copy().items() if key in base_view_vars @@ -165,7 +166,7 @@ def current_listing_normal_url( The `query` argument allows adding query variables to the generated url. """ - if request.matched_route.name not in ('home', 'group'): + if request.matched_route.name not in ('home', 'group', 'user'): raise AttributeError('Current route is not supported.') normal_view_vars = ('order', 'period', 'per_page') diff --git a/tildes/tildes/models/comment/comment_query.py b/tildes/tildes/models/comment/comment_query.py index 672367b..fb029f8 100644 --- a/tildes/tildes/models/comment/comment_query.py +++ b/tildes/tildes/models/comment/comment_query.py @@ -4,12 +4,12 @@ from typing import Any from pyramid.request import Request -from tildes.models import ModelQuery +from tildes.models.pagination import PaginatedQuery from .comment import Comment from .comment_vote import CommentVote -class CommentQuery(ModelQuery): +class CommentQuery(PaginatedQuery): """Specialized ModelQuery for Comments.""" def __init__(self, request: Request) -> None: diff --git a/tildes/tildes/models/pagination.py b/tildes/tildes/models/pagination.py index c4c6d8c..cd52d2f 100644 --- a/tildes/tildes/models/pagination.py +++ b/tildes/tildes/models/pagination.py @@ -3,9 +3,9 @@ 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 tildes.lib.id import id_to_id36, id36_to_id from .model_query import ModelQuery @@ -22,7 +22,8 @@ class PaginatedQuery(ModelQuery): super().__init__(model_cls, request) - self._sort_column: Optional[Column] = None + # default to sorting by created_time descending (newest first) + self._sort_column = model_cls.created_time self.sort_desc = True self.after_id: Optional[int] = None @@ -135,17 +136,16 @@ class PaginatedQuery(ModelQuery): """Finalize the query before execution.""" query = super()._finalize() - if self._sort_column: - # if the query is reversed, we need to sort in the opposite dir - # (basically self.sort_desc XOR self.is_reversed) - desc = self.sort_desc - if self.is_reversed: - desc = not desc + # if the query is reversed, we need to sort in the opposite dir + # (basically self.sort_desc XOR self.is_reversed) + desc = self.sort_desc + if self.is_reversed: + desc = not desc - if desc: - query = query.order_by(*self.sorting_columns_desc) - else: - query = query.order_by(*self.sorting_columns) + if desc: + query = query.order_by(*self.sorting_columns_desc) + else: + query = query.order_by(*self.sorting_columns) # pylint: disable=protected-access query = query._apply_before_or_after() @@ -204,3 +204,21 @@ class PaginatedResults: def __len__(self) -> int: """Return the number of results.""" return len(self.results) + + @property + 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 + + next_id = inspect(self.results[-1]).identity[0] + return id_to_id36(next_id) + + @property + 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 + + prev_id = inspect(self.results[0]).identity[0] + return id_to_id36(prev_id) diff --git a/tildes/tildes/templates/macros/user_menu.jinja2 b/tildes/tildes/templates/macros/user_menu.jinja2 index 761a85a..0033ab9 100644 --- a/tildes/tildes/templates/macros/user_menu.jinja2 +++ b/tildes/tildes/templates/macros/user_menu.jinja2 @@ -7,7 +7,7 @@
diff --git a/tildes/tildes/templates/topic_listing.jinja2 b/tildes/tildes/templates/topic_listing.jinja2 index 611fed2..ab4bf51 100644 --- a/tildes/tildes/templates/topic_listing.jinja2 +++ b/tildes/tildes/templates/topic_listing.jinja2 @@ -154,13 +154,13 @@ diff --git a/tildes/tildes/templates/user.jinja2 b/tildes/tildes/templates/user.jinja2 index 1e3a1f1..b6362fe 100644 --- a/tildes/tildes/templates/user.jinja2 +++ b/tildes/tildes/templates/user.jinja2 @@ -10,13 +10,33 @@ {{ user.username }} {% endblock %} -{% block main_heading %}{{ user.username }}'s recent activity{% endblock %} +{# Only show the heading if they can't see the type tabs #} +{% block main_heading %} + {% if not request.has_permission('view_types', user) %} + {{ user.username }}'s recent activity + {% endif %} +{% endblock %} {% block content %} +{% if request.has_permission('view_types', user) %} + +{% endif %} -{% if merged_posts %} +{% if posts %}