diff --git a/tildes/alembic/versions/8056ce0a4f19_add_user_setting_to_hide_vote_counts.py b/tildes/alembic/versions/8056ce0a4f19_add_user_setting_to_hide_vote_counts.py new file mode 100644 index 0000000..b353de3 --- /dev/null +++ b/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") diff --git a/tildes/scripts/clean_private_data.py b/tildes/scripts/clean_private_data.py index 452b77e..99bcb2d 100644 --- a/tildes/scripts/clean_private_data.py +++ b/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, ) diff --git a/tildes/scss/modules/_topic.scss b/tildes/scss/modules/_topic.scss index ed1a770..08b167c 100644 --- a/tildes/scss/modules/_topic.scss +++ b/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 { diff --git a/tildes/tildes/models/user/user.py b/tildes/tildes/models/user/user.py index eea2d91..f957eff 100644 --- a/tildes/tildes/models/user/user.py +++ b/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: diff --git a/tildes/tildes/templates/macros/buttons.jinja2 b/tildes/tildes/templates/macros/buttons.jinja2 index 4fa84a6..5d2a7ce 100644 --- a/tildes/tildes/templates/macros/buttons.jinja2 +++ b/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 %} diff --git a/tildes/tildes/templates/macros/comments.jinja2 b/tildes/tildes/templates/macros/comments.jinja2 index 1bec7e4..0e51a5e 100644 --- a/tildes/tildes/templates/macros/comments.jinja2 +++ b/tildes/tildes/templates/macros/comments.jinja2 @@ -98,8 +98,8 @@ {% 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 %}