Browse Source
Add setting to hide post and comment scores
merge-requests/2/head
Ivan Fonseca
8 years ago
No known key found for this signature in database
GPG Key ID: 95A9C856EC788689
6 changed files with
71 additions and
3 deletions
-
tildes/alembic/versions/ec53997aff65_add_option_to_hide_scores.py
-
tildes/tildes/models/user/user.py
-
tildes/tildes/templates/macros/comments.jinja2
-
tildes/tildes/templates/macros/topics.jinja2
-
tildes/tildes/templates/settings.jinja2
-
tildes/tildes/views/api/web/user.py
|
|
|
@ -0,0 +1,24 @@ |
|
|
|
"""Add option to hide scores |
|
|
|
|
|
|
|
Revision ID: ec53997aff65 |
|
|
|
Revises: |
|
|
|
Create Date: 2018-07-18 17:28:08.273263 |
|
|
|
|
|
|
|
""" |
|
|
|
from alembic import op |
|
|
|
import sqlalchemy as sa |
|
|
|
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic. |
|
|
|
revision = 'ec53997aff65' |
|
|
|
down_revision = None |
|
|
|
branch_labels = None |
|
|
|
depends_on = None |
|
|
|
|
|
|
|
|
|
|
|
def upgrade(): |
|
|
|
op.add_column('users', sa.Column('hide_scores', sa.Boolean(), server_default='false', nullable=False)) |
|
|
|
|
|
|
|
|
|
|
|
def downgrade(): |
|
|
|
op.drop_column('users', 'hide_scores') |
|
|
|
@ -82,6 +82,8 @@ class User(DatabaseModel): |
|
|
|
Boolean, nullable=False, server_default='false') |
|
|
|
auto_mark_notifications_read: bool = Column( |
|
|
|
Boolean, nullable=False, server_default='false') |
|
|
|
hide_scores: bool = Column( |
|
|
|
Boolean, nullable=False, server_default='false') |
|
|
|
is_banned: bool = Column(Boolean, nullable=False, server_default='false') |
|
|
|
is_admin: bool = Column(Boolean, nullable=False, server_default='false') |
|
|
|
home_default_order: Optional[TopicSortOption] = Column( |
|
|
|
|
|
|
|
@ -73,7 +73,7 @@ |
|
|
|
|
|
|
|
{% 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 %} |
|
|
|
{% if request.user == comment.user and comment.num_votes > 0 and not request.user.hide_scores %} |
|
|
|
<span class="comment-votes">{{ comment.num_votes }} votes</span> |
|
|
|
{% endif %} |
|
|
|
|
|
|
|
@ -115,7 +115,7 @@ |
|
|
|
data-ic-target="#comment-{{ comment.comment_id36 }} .comment-itself:first" |
|
|
|
>Vote |
|
|
|
{% endif %} |
|
|
|
{% if comment.num_votes > 0 %} |
|
|
|
{% if comment.num_votes > 0 and not request.user.hide_scores %} |
|
|
|
({{ comment.num_votes }}) |
|
|
|
{% endif %} |
|
|
|
</a></li> |
|
|
|
|
|
|
|
@ -106,7 +106,13 @@ |
|
|
|
|
|
|
|
{# 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-votes"> |
|
|
|
{% if not request.user.hide_scores %} |
|
|
|
{{ topic.num_votes }} |
|
|
|
{% else %} |
|
|
|
- |
|
|
|
{% endif %} |
|
|
|
</span> |
|
|
|
<span class="topic-voting-label"> |
|
|
|
{% trans num_votes=topic.num_votes %} |
|
|
|
vote |
|
|
|
|
|
|
|
@ -37,6 +37,26 @@ |
|
|
|
</div> |
|
|
|
</form> |
|
|
|
</li> |
|
|
|
<li> |
|
|
|
<form |
|
|
|
name="hide-scores" |
|
|
|
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="hide_scores" |
|
|
|
name="hide_scores" |
|
|
|
data-js-autosubmit-on-change |
|
|
|
{% if request.user.hide_scores %}checked{% endif %} |
|
|
|
> |
|
|
|
<i class="form-icon"></i> Hide post and comment scores |
|
|
|
</label> |
|
|
|
</div> |
|
|
|
</form> |
|
|
|
</li> |
|
|
|
<li><a href="/settings/password_change">Change your password</a></li> |
|
|
|
<li> |
|
|
|
<a href="/settings/account_recovery">Set up account recovery</a> |
|
|
|
|
|
|
|
@ -104,6 +104,22 @@ def change_auto_mark_notifications(request: Request) -> Response: |
|
|
|
return IC_NOOP |
|
|
|
|
|
|
|
|
|
|
|
@ic_view_config( |
|
|
|
route_name='user', |
|
|
|
request_method='PATCH', |
|
|
|
request_param='ic-trigger-name=hide-scores', |
|
|
|
permission='change_hide_scores_setting,' |
|
|
|
) |
|
|
|
def change_hide_scores(request: Request) -> Response: |
|
|
|
"""Change the user's "hide scores" setting.""" |
|
|
|
user = request.context |
|
|
|
|
|
|
|
hide = bool(request.params.get('hide_scores')) |
|
|
|
user.hide_scores = hide |
|
|
|
|
|
|
|
return IC_NOOP |
|
|
|
|
|
|
|
|
|
|
|
@ic_view_config( |
|
|
|
route_name='user', |
|
|
|
request_method='PATCH', |
|
|
|
|