Skip to content

Commit

Permalink
Beta mode: Add preference and subreddit callouts
Browse files Browse the repository at this point in the history
  • Loading branch information
umbrae committed May 7, 2015
1 parent 33a4173 commit 03bc77b
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 1 deletion.
3 changes: 3 additions & 0 deletions r2/example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ automatic_reddits =
lounge_reddit =
# subreddits that have subscribers hidden
hide_subscribers_srs =
# subreddit to use for beta testing
beta_sr = beta


multi_icons = art and design, ask, books, business, cars, comics, cute animals, diy, entertainment, food and drink, funny, games, grooming, health, life advice, military, models pinup, music, news, philosophy, pictures and gifs, science, shopping, sports, style, tech, travel, unusual stories, video

Expand Down
14 changes: 13 additions & 1 deletion r2/r2/lib/validator/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
VSRByName,
)
from r2.lib.errors import errors
from r2.models import Subreddit, NotFound

# Validators that map directly to Account._preference_attrs
# The key MUST be the same string as the value in _preference_attrs
Expand Down Expand Up @@ -84,12 +85,24 @@
pref_enable_default_themes=VBoolean("enable_default_themes", False),
pref_default_theme_sr=VSRByName("theme_selector", False),
pref_other_theme=VSRByName("other_theme", False),
pref_beta=VBoolean('beta'),
)


def set_prefs(user, prefs):
for k, v in prefs.iteritems():
if k == 'pref_beta' and v and not getattr(user, 'pref_beta', False):
# If a user newly opted into beta, we want to subscribe them
# to the beta subreddit.
try:
sr = Subreddit._by_name(g.beta_sr)
sr.add_subscriber(user)
except NotFound:
g.log.warning("Could not find beta subreddit '%s'. It may "
"need to be created." % g.beta_sr)

setattr(user, k, v)

if k == 'pref_default_comment_sort':
# We have to do this copy-modify-assign shenanigans because if we
# just assign directly into `c.user.sort_options`, `Thing` doesn't
Expand All @@ -99,7 +112,6 @@ def set_prefs(user, prefs):
user.sort_options = sort_options
g.stats.simple_event('default_comment_sort.changed_in_prefs')


def filter_prefs(prefs, user):
# replace stylesheet_override with other_theme if it doesn't exist
if feature.is_enabled_for('stylesheets_everywhere', user):
Expand Down
1 change: 1 addition & 0 deletions r2/r2/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Account(Thing):
pref_collapse_left_bar=False,
pref_public_server_seconds=False,
pref_ignore_suggested_sort=False,
pref_beta=False,
mobile_compress = False,
mobile_thumbnail = True,
reported = 0,
Expand Down
24 changes: 24 additions & 0 deletions r2/r2/public/static/css/reddit.less
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,26 @@ ul.flat-vert {text-align: left;}
.user .userkarma {
font-weight: bold;
}
.beta-hint {
position: absolute;
margin-left: -22px;
width: 46px;
height: 25px;

opacity: 0.8;
&:hover {
opacity: 1;
}

a {
.c-hide-text();
display: inline-block;
width: 20px;
height: 13px;
background: transparent data-uri('../flask.svg') center left no-repeat;
background-size: contain;
}
}

.pagename {
font-weight: bold;
Expand Down Expand Up @@ -1383,6 +1403,10 @@ body.with-listing-chooser.explore-page #header .pagename {
margin: .5em;
}

a {
font-weight: bold;
}

a:hover {
text-decoration: underline
}
Expand Down
1 change: 1 addition & 0 deletions r2/r2/public/static/flask.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions r2/r2/templates/prefoptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,23 @@
</span>
</td>
</tr>
% if feature.is_enabled('beta_opt_in'):
<tr>
<th>${_("beta options")}</th>
<td class="prefright">
${checkbox(_("I would like to beta test features for reddit"), "beta")}
&#32;
<span class="details">
<%
beta_sr_link = format_html('&#32;<a href="/r/%s">/r/%s</a>&#32;', g.beta_sr, g.beta_sr)
%>
(${_wsf("by enabling you'll be subscribed to %(beta_sr_link)s automatically.", beta_sr_link=beta_sr_link)}
&#32;
<a href="/r/${g.beta_sr}/wiki">${_("details on the /r/{beta_sr} wiki").format(beta_sr=g.beta_sr)}</a>)
</span>
</td>
</tr>
%endif
%endif

%if c.user.gold:
Expand Down
16 changes: 16 additions & 0 deletions r2/r2/templates/redditheader.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@
${separator("|")}
%endif
%else:
%if feature.is_enabled('beta_opt_in') and c.user.pref_beta:
<div class="beta-hint help help-hoverable">
<a class="beta-link" href="/r/${g.beta_sr}">beta</a>
<div id="beta-help" class="hover-bubble help-bubble anchor-top">
<div class="help-section">
<p>${_("You're in beta mode! Thanks for helping to test reddit.")}</p>
<p>
${text_with_links(_("Please give feedback at %(beta_link)s, or %(learn_more_link)s."),
beta_link = dict(link_text="/r/" + g.beta_sr, path="/r/" + g.beta_sr),
learn_more_link = dict(link_text=_("learn more on the wiki"), path="/r/" + g.beta_sr + "/wiki")
)}
</p>
</div>
</div>
</div>
%endif
<span class="user">
${plain_link(c.user.name, "/user/%s/" % c.user.name, _sr_path=False)}
&nbsp;(<span class="userkarma" title="${_("link karma")}">${format_number(display_link_karma(c.user.link_karma))}</span>)
Expand Down
1 change: 1 addition & 0 deletions scripts/inject_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def inject_test_data(num_links=25, num_comments=25, num_votes=5):
ensure_account(g.automoderator_account)
ensure_subreddit(g.default_sr, system_user)
ensure_subreddit(g.takedown_sr, system_user)
ensure_subreddit(g.beta_sr, system_user)

print
print
Expand Down

0 comments on commit 03bc77b

Please sign in to comment.