From 69cd0d08ec399c5e42e9b56627e4f1f7cedea02a Mon Sep 17 00:00:00 2001 From: Chad Birch Date: Tue, 16 Apr 2013 12:06:05 -0600 Subject: [PATCH] Allow subreddits to hide comment scores initially Adds a new subreddit setting that allows defining a period of time after posting that comment scores will be hidden. --- r2/r2/controllers/api.py | 6 +++++- r2/r2/lib/jsontemplates.py | 1 + r2/r2/models/link.py | 7 ++++++- r2/r2/models/modaction.py | 1 + r2/r2/models/subreddit.py | 1 + r2/r2/templates/comment.html | 2 +- r2/r2/templates/createsubreddit.html | 12 ++++++++++++ 7 files changed, 27 insertions(+), 3 deletions(-) diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 0e67d8761..00b5cd1a5 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -1678,6 +1678,8 @@ class ApiController(RedditController, OAuth2ResourceController): link_type = VOneOf('link_type', ('any', 'link', 'self')), submit_link_label=VLength('submit_link_label', max_length=60), submit_text_label=VLength('submit_text_label', max_length=60), + comment_score_hide_mins=VInt('comment_score_hide_mins', + coerce=False, num_default=0, min=0, max=1440), wikimode = VOneOf('wikimode', ('disabled', 'modonly', 'anyone')), wiki_edit_karma = VInt("wiki_edit_karma", coerce=False, num_default=0, min=0), wiki_edit_age = VInt("wiki_edit_age", coerce=False, num_default=0, min=0), @@ -1720,7 +1722,7 @@ class ApiController(RedditController, OAuth2ResourceController): if k in ('name', 'title', 'domain', 'description', 'show_media', 'exclude_banned_modqueue', 'show_cname_sidebar', 'type', - 'link_type', 'submit_link_label', + 'link_type', 'submit_link_label', 'comment_score_hide_mins', 'submit_text_label', 'lang', 'css_on_cname', 'header_title', 'over_18', 'wikimode', 'wiki_edit_karma', 'wiki_edit_age', 'allow_top', 'public_description')) @@ -1791,6 +1793,8 @@ class ApiController(RedditController, OAuth2ResourceController): elif (form.has_errors(('wiki_edit_karma', 'wiki_edit_age'), errors.BAD_NUMBER)): pass + elif form.has_errors('comment_score_hide_mins', errors.BAD_NUMBER): + pass #creating a new reddit elif not sr: #sending kw is ok because it was sanitized above diff --git a/r2/r2/lib/jsontemplates.py b/r2/r2/lib/jsontemplates.py index 6b9be0991..4fb8718dd 100755 --- a/r2/r2/lib/jsontemplates.py +++ b/r2/r2/lib/jsontemplates.py @@ -720,6 +720,7 @@ class SubredditSettingsTemplate(ThingJsonTemplate): subreddit_type = 'site.type', submit_link_label = 'site.submit_link_label', submit_text_label = 'site.submit_text_label', + comment_score_hide_mins = 'site.comment_score_hide_mins', content_options = 'site.link_type', over_18 = 'site.over_18', default_set = 'site.allow_top', diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index ce4b3c511..c6406f54e 100755 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -882,6 +882,7 @@ class Comment(Thing, Printable): @classmethod def add_props(cls, user, wrapped): from r2.lib.template_helpers import add_attr, get_domain + from r2.lib.utils import timeago from r2.lib.wrapped import CachedVariable from r2.lib.pages import WrappedUser @@ -1043,7 +1044,11 @@ class Comment(Thing, Printable): else: item.votable = True - if (item.link.contest_mode and + hide_period = ('{0} minutes' + .format(item.subreddit.comment_score_hide_mins)) + + if ((item._date > timeago(hide_period) or + item.link.contest_mode) and not (c.user_is_admin or c.user_is_loggedin and item.subreddit.is_moderator(c.user))): diff --git a/r2/r2/models/modaction.py b/r2/r2/models/modaction.py index 8f542a202..1c2e932f3 100644 --- a/r2/r2/models/modaction.py +++ b/r2/r2/models/modaction.py @@ -130,6 +130,7 @@ class ModAction(tdb_cassandra.UuidThing, Printable): 'link_type': _('link type'), 'submit_link_label': _('submit link button label'), 'submit_text_label': _('submit text post button label'), + 'comment_score_hide_mins': _('comment score hide period'), 'over_18': _('toggle viewers must be over 18'), 'allow_top': _('toggle allow in default set'), 'show_media': _('toggle show thumbnail images of content'), diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 5bf643606..5c37a89e7 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -91,6 +91,7 @@ class Subreddit(Thing, Printable): link_type = 'any', # one of ('link', 'self', 'any') submit_link_label = '', submit_text_label = '', + comment_score_hide_mins = 0, flair_enabled = True, flair_position = 'right', # one of ('left', 'right') link_flair_position = '', # one of ('', 'left', 'right') diff --git a/r2/r2/templates/comment.html b/r2/r2/templates/comment.html index 4c48c30f7..cf8d7fd1d 100755 --- a/r2/r2/templates/comment.html +++ b/r2/r2/templates/comment.html @@ -105,7 +105,7 @@ ${parent.collapsed()} %if collapse and thing.collapsed and show: ${thing.collapsed_reason} %else: - %if show and not (thing.link.contest_mode and thing.score_hidden): + %if show and not thing.score_hidden: ${unsafe(self.score(thing, likes = thing.likes))} %endif ${thing_timestamp(thing, thing.timesince)} ${_("ago")} diff --git a/r2/r2/templates/createsubreddit.html b/r2/r2/templates/createsubreddit.html index 1db57e274..0cc996847 100644 --- a/r2/r2/templates/createsubreddit.html +++ b/r2/r2/templates/createsubreddit.html @@ -259,6 +259,18 @@ +
+
+ + %if thing.site: + + %else: + + %endif + ${error_field("BAD_NUMBER", "comment_score_hide_mins")} +
+
% if thing.site and thing.site.domain != thing.site._defaults['domain']: