mirror of
https://gitlab.com/tildes/tildes.git
synced 2026-04-17 23:08:32 +02:00
Add setting to choose default comment sort order
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
"""Add comment sort order account setting
|
||||||
|
|
||||||
|
Revision ID: 51a1012f4f63
|
||||||
|
Revises: 9b7a7b906956
|
||||||
|
Create Date: 2020-02-07 22:38:08.826608
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = "51a1012f4f63"
|
||||||
|
down_revision = "9b7a7b906956"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.execute(
|
||||||
|
"create type commenttreesortoption as enum('VOTES', 'NEWEST', 'POSTED', 'RELEVANCE')"
|
||||||
|
)
|
||||||
|
op.add_column(
|
||||||
|
"users",
|
||||||
|
sa.Column(
|
||||||
|
"comment_sort_order_default",
|
||||||
|
postgresql.ENUM(
|
||||||
|
"VOTES", "NEWEST", "POSTED", "RELEVANCE", name="commenttreesortoption"
|
||||||
|
),
|
||||||
|
nullable=True,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_column("users", "comment_sort_order_default")
|
||||||
|
op.execute("drop type commenttreesortoption")
|
||||||
@@ -30,7 +30,12 @@ from sqlalchemy.ext.hybrid import hybrid_property
|
|||||||
from sqlalchemy.orm import deferred
|
from sqlalchemy.orm import deferred
|
||||||
from sqlalchemy.sql.expression import text
|
from sqlalchemy.sql.expression import text
|
||||||
|
|
||||||
from tildes.enums import CommentLabelOption, HTMLSanitizationContext, TopicSortOption
|
from tildes.enums import (
|
||||||
|
CommentLabelOption,
|
||||||
|
CommentTreeSortOption,
|
||||||
|
HTMLSanitizationContext,
|
||||||
|
TopicSortOption,
|
||||||
|
)
|
||||||
from tildes.lib.database import CIText, TagList
|
from tildes.lib.database import CIText, TagList
|
||||||
from tildes.lib.datetime import utc_now
|
from tildes.lib.datetime import utc_now
|
||||||
from tildes.lib.hash import hash_string, is_match_for_hash
|
from tildes.lib.hash import hash_string, is_match_for_hash
|
||||||
@@ -90,6 +95,9 @@ class User(DatabaseModel):
|
|||||||
inviter_id: int = Column(Integer, ForeignKey("users.user_id"))
|
inviter_id: int = Column(Integer, ForeignKey("users.user_id"))
|
||||||
invite_codes_remaining: int = Column(Integer, nullable=False, server_default="0")
|
invite_codes_remaining: int = Column(Integer, nullable=False, server_default="0")
|
||||||
collapse_old_comments: bool = Column(Boolean, nullable=False, server_default="true")
|
collapse_old_comments: bool = Column(Boolean, nullable=False, server_default="true")
|
||||||
|
comment_sort_order_default: Optional[CommentTreeSortOption] = Column(
|
||||||
|
ENUM(CommentTreeSortOption)
|
||||||
|
)
|
||||||
auto_mark_notifications_read: bool = Column(
|
auto_mark_notifications_read: bool = Column(
|
||||||
Boolean, nullable=False, server_default="false"
|
Boolean, nullable=False, server_default="false"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -73,6 +73,31 @@
|
|||||||
<h2>Site behavior settings</h2>
|
<h2>Site behavior settings</h2>
|
||||||
|
|
||||||
<ul class="settings-list">
|
<ul class="settings-list">
|
||||||
|
<li>
|
||||||
|
<form
|
||||||
|
name="account-default-comment-sort-order"
|
||||||
|
data-ic-patch-to="{{ request.route_url(
|
||||||
|
'ic_user',
|
||||||
|
username=request.user.username
|
||||||
|
) }}"
|
||||||
|
>
|
||||||
|
<label class="form-label" for="comment-sort-order">Choose a default comment sort order:</label>
|
||||||
|
<select
|
||||||
|
class="form-select"
|
||||||
|
name="comment-sort-order"
|
||||||
|
id="comment-sort-order"
|
||||||
|
data-js-autosubmit-on-change
|
||||||
|
>
|
||||||
|
{% for sort_option in comment_sort_order_options %}
|
||||||
|
<option
|
||||||
|
value="{{ sort_option.name }}"
|
||||||
|
{{ 'selected' if current_comment_sort_order == sort_option else '' }}
|
||||||
|
>{{ sort_option.description|capitalize }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<form
|
<form
|
||||||
name="collapse-old-comments"
|
name="collapse-old-comments"
|
||||||
|
|||||||
@@ -184,6 +184,22 @@ def patch_change_show_tags_in_listings(request: Request) -> Response:
|
|||||||
return IC_NOOP
|
return IC_NOOP
|
||||||
|
|
||||||
|
|
||||||
|
@ic_view_config(
|
||||||
|
route_name="user",
|
||||||
|
request_method="PATCH",
|
||||||
|
request_param="ic-trigger-name=account-default-comment-sort-order",
|
||||||
|
permission="change_comment_sort_order_setting",
|
||||||
|
)
|
||||||
|
def patch_change_comment_sort_order(request: Request) -> Response:
|
||||||
|
"""Change the user's default comment sort order setting."""
|
||||||
|
user = request.context
|
||||||
|
|
||||||
|
comment_sort_order = request.params.get("comment-sort-order")
|
||||||
|
user.comment_sort_order_default = comment_sort_order
|
||||||
|
|
||||||
|
return IC_NOOP
|
||||||
|
|
||||||
|
|
||||||
@ic_view_config(
|
@ic_view_config(
|
||||||
route_name="user",
|
route_name="user",
|
||||||
request_method="PATCH",
|
request_method="PATCH",
|
||||||
|
|||||||
@@ -62,7 +62,17 @@ def get_settings(request: Request) -> dict:
|
|||||||
theme_options[user_default_theme] += " (account default)"
|
theme_options[user_default_theme] += " (account default)"
|
||||||
theme_options[site_default_theme] += " (site default)"
|
theme_options[site_default_theme] += " (site default)"
|
||||||
|
|
||||||
return {"current_theme": current_theme, "theme_options": theme_options}
|
if request.user.comment_sort_order_default:
|
||||||
|
current_comment_sort_order = request.user.comment_sort_order_default
|
||||||
|
else:
|
||||||
|
current_comment_sort_order = CommentTreeSortOption.RELEVANCE
|
||||||
|
|
||||||
|
return {
|
||||||
|
"current_comment_sort_order": current_comment_sort_order,
|
||||||
|
"comment_sort_order_options": CommentTreeSortOption,
|
||||||
|
"current_theme": current_theme,
|
||||||
|
"theme_options": theme_options,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
@view_config(
|
||||||
|
|||||||
@@ -380,16 +380,15 @@ def get_new_topic_form(request: Request) -> dict:
|
|||||||
|
|
||||||
@view_config(route_name="topic", renderer="topic.jinja2")
|
@view_config(route_name="topic", renderer="topic.jinja2")
|
||||||
@view_config(route_name="topic_no_title", renderer="topic.jinja2")
|
@view_config(route_name="topic_no_title", renderer="topic.jinja2")
|
||||||
@use_kwargs(
|
@use_kwargs({"comment_order": Enum(CommentTreeSortOption, missing=None)})
|
||||||
{
|
|
||||||
"comment_order": Enum(
|
|
||||||
CommentTreeSortOption, missing=CommentTreeSortOption.RELEVANCE
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
def get_topic(request: Request, comment_order: CommentTreeSortOption) -> dict:
|
def get_topic(request: Request, comment_order: CommentTreeSortOption) -> dict:
|
||||||
"""View a single topic."""
|
"""View a single topic."""
|
||||||
topic = request.context
|
topic = request.context
|
||||||
|
if comment_order is None:
|
||||||
|
if request.user and request.user.comment_sort_order_default:
|
||||||
|
comment_order = request.user.comment_sort_order_default
|
||||||
|
else:
|
||||||
|
comment_order = CommentTreeSortOption.RELEVANCE
|
||||||
|
|
||||||
# deleted and removed comments need to be included since they're necessary for
|
# deleted and removed comments need to be included since they're necessary for
|
||||||
# building the tree if they have replies
|
# building the tree if they have replies
|
||||||
|
|||||||
Reference in New Issue
Block a user