Browse Source

Merge branch 'hide-vote-counts' into 'master'

Add user setting to hide vote counts

Closes #780

See merge request tildes/tildes!145
merge-requests/145/merge
Daniel Woznicki 3 months ago
parent
commit
5ccd6a580b
  1. 32
      tildes/alembic/versions/8056ce0a4f19_add_user_setting_to_hide_vote_counts.py
  2. 1
      tildes/scripts/clean_private_data.py
  3. 7
      tildes/scss/modules/_topic.scss
  4. 1
      tildes/tildes/models/user/user.py
  5. 4
      tildes/tildes/templates/macros/buttons.jinja2
  6. 8
      tildes/tildes/templates/macros/comments.jinja2
  7. 31
      tildes/tildes/templates/macros/topics.jinja2
  8. 21
      tildes/tildes/templates/settings.jinja2
  9. 16
      tildes/tildes/views/api/web/user.py

32
tildes/alembic/versions/8056ce0a4f19_add_user_setting_to_hide_vote_counts.py

@ -0,0 +1,32 @@
"""Add user setting to hide vote counts
Revision ID: 8056ce0a4f19
Revises: 55f4c1f951d5
Create Date: 2023-06-26 05:59:44.862789
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "8056ce0a4f19"
down_revision = "55f4c1f951d5"
branch_labels = None
depends_on = None
def upgrade():
op.add_column(
"users",
sa.Column(
"show_vote_counts",
sa.Boolean(),
server_default="true",
nullable=False,
),
)
def downgrade():
op.drop_column("users", "show_vote_counts")

1
tildes/scripts/clean_private_data.py

@ -207,6 +207,7 @@ class DataCleaner:
"last_exemplary_label_time": DEFAULT,
"_bio_markdown": DEFAULT,
"bio_rendered_html": DEFAULT,
"show_vote_counts": DEFAULT,
},
synchronize_session=False,
)

7
tildes/scss/modules/_topic.scss

@ -236,6 +236,13 @@
.topic-voting-label {
font-size: 0.6rem;
line-height: 0.6rem;
// When the vote count is hidden, the topic voting button becomes fairly short.
// This padding helps is somewhat match the original button size.
&.count-hidden {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
}
.topic-text-excerpt {

1
tildes/tildes/models/user/user.py

@ -145,6 +145,7 @@ class User(DatabaseModel):
)
)
bio_rendered_html: str = deferred(Column(Text))
show_vote_counts: bool = Column(Boolean, nullable=False, server_default="true")
@hybrid_property
def bio_markdown(self) -> str:

4
tildes/tildes/templates/macros/buttons.jinja2

@ -38,8 +38,8 @@
{% set normal_label = "Vote" %}
{% set toggled_label = "Voted" %}
{% if subject.num_votes > 0 %}
{# Append the vote count in parentheses #}
{% if subject.num_votes > 0 and request.user.show_vote_counts %}
{# Append the vote count in parentheses if vote counts are not hidden #}
{% set normal_label = normal_label~" ("~subject.num_votes~")" %}
{% set toggled_label = toggled_label~" ("~subject.num_votes~")" %}
{% endif %}

8
tildes/tildes/templates/macros/comments.jinja2

@ -98,8 +98,8 @@
</header>
{% if request.has_permission('view', comment) %}
{# Show votes at the top only if it's your own comment #}
{% if request.user == comment.user and comment.num_votes > 0 and not comment.is_removed %}
{# Show votes at the top only if it's your own comment and votes counts aren't hidden #}
{% if request.user == comment.user and comment.num_votes > 0 and not comment.is_removed and request.user.show_vote_counts %}
<div class="comment-votes">{{ pluralize(comment.num_votes, "vote") }}</div>
{% endif %}
@ -157,8 +157,8 @@
</div>
<menu class="btn-post">
{# Show non-button vote count if the viewer can't vote and it's not their comment #}
{% if not request.has_permission("vote", comment) and comment.num_votes > 0 and comment.user != request.user %}
{# Show non-button vote count if the viewer can't vote and it's not their comment and don't have vote counts hidden #}
{% if not request.has_permission("vote", comment) and comment.num_votes > 0 and comment.user != request.user and request.user.show_vote_counts %}
<div class="comment-votes">{{ pluralize(comment.num_votes, "vote") }}</div>
{% endif %}

31
tildes/tildes/templates/macros/topics.jinja2

@ -183,16 +183,27 @@
<div class="topic-voting">
{% endif %}
{# Hide voting from the topic's author if it has zero votes #}
{% if request.user != topic.user or topic.num_votes > 0 %}
<span class="topic-voting-votes">{{ topic.num_votes }}</span>
<span class="topic-voting-label">
{% trans num_votes=topic.num_votes %}
vote
{% pluralize %}
votes
{% endtrans %}
</span>
{# Hide voting from the topic's author if it has zero votes, or the author has vote counts turned off #}
{# For other users, also hide vote count if turned off, but still show the vote button #}
{% if request.user != topic.user or (request.user == topic.user and topic.num_votes > 0 and request.user.show_vote_counts) %}
{% if request.user.show_vote_counts %}
<span class="topic-voting-votes">{{ topic.num_votes }}</span>
<span class="topic-voting-label">
{% trans num_votes=topic.num_votes %}
vote
{% pluralize %}
votes
{% endtrans %}
</span>
{% else %}
<span class="topic-voting-label count-hidden">
{% if topic.user_voted %}
Voted
{% else %}
Vote
{% endif %}
</span>
{% endif %}
{% endif %}
{% if request.has_permission('vote', topic) %}

21
tildes/tildes/templates/settings.jinja2

@ -119,6 +119,27 @@
</form>
</li>
<li>
<form
name="show-vote-counts"
autocomplete="off"
data-ic-patch-to="{{ request.route_url('ic_user', username=request.user.username) }}"
>
<div class="form-group">
<label class="form-checkbox">
<input
type="checkbox"
id="show_vote_counts"
name="show_vote_counts"
data-js-autosubmit-on-change
{% if request.user.show_vote_counts %}checked{% endif %}
/>
<i class="form-icon"></i> Display vote counts for topics and comments
</label>
</div>
</form>
</li>
<li>
<h4>Open links in new tabs</h4>
<form

16
tildes/tildes/views/api/web/user.py

@ -278,6 +278,22 @@ def patch_change_collapse_old_comments(request: Request) -> Response:
return IC_NOOP
@ic_view_config(
route_name="user",
request_method="PATCH",
request_param="ic-trigger-name=show-vote-counts",
permission="change_settings",
)
def patch_change_show_vote_counts(request: Request) -> Response:
"""Change the user's "display vote counts" setting."""
user = request.context
show_vote_counts = bool(request.params.get("show_vote_counts"))
user.show_vote_counts = show_vote_counts
return IC_NOOP
@ic_view_config(
route_name="user",
request_method="PATCH",

Loading…
Cancel
Save