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.
This commit is contained in:
Chad Birch
2013-04-16 12:06:05 -06:00
parent b49e6c113a
commit 69cd0d08ec
7 changed files with 27 additions and 3 deletions

View File

@@ -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

View File

@@ -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',

View File

@@ -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))):

View File

@@ -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'),

View File

@@ -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')

View File

@@ -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")}

View File

@@ -259,6 +259,18 @@
</li>
</ul>
</div>
<div class="usertext-edit">
<div class="delete-field">
<label for="comment_score_hide_mins">${_('Minutes to hide comment scores:')}</label>
%if thing.site:
<input id="comment_score_hide_mins" type="text" name="comment_score_hide_mins" placeholder="0"
value = "${thing.site.comment_score_hide_mins}" />
%else:
<input id="comment_score_hide_mins" type="text" name="comment_score_hide_mins" value="0" placeholder="0" />
%endif
${error_field("BAD_NUMBER", "comment_score_hide_mins")}
</div>
</div>
</%utils:line_field>
% if thing.site and thing.site.domain != thing.site._defaults['domain']: