diff --git a/r2/r2/controllers/reddit_base.py b/r2/r2/controllers/reddit_base.py index 8dad313f3..4e677ddae 100644 --- a/r2/r2/controllers/reddit_base.py +++ b/r2/r2/controllers/reddit_base.py @@ -96,6 +96,7 @@ from r2.models import ( NotFound, Random, RandomNSFW, + RandomSubscription, Sub, Subreddit, valid_admin_cookie, @@ -975,6 +976,12 @@ class RedditController(MinimalController): if c.site == Random: c.site = Subreddit.random_reddit() redirect_to("/" + c.site.path.strip('/') + request.path) + elif c.site == RandomSubscription: + if c.user.gold: + c.site = Subreddit.random_subscription(c.user) + redirect_to('/' + c.site.path.strip('/') + request.path) + else: + redirect_to('/gold/about') elif c.site == RandomNSFW: c.site = Subreddit.random_reddit(over18=True) redirect_to("/" + c.site.path.strip('/') + request.path) diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index ec92a3c5c..7c1fff1db 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -23,7 +23,7 @@ from r2.lib.wrapped import Wrapped, Templated, CachedTemplate from r2.models import Account, FakeAccount, DefaultSR, make_feedurl from r2.models import FakeSubreddit, Subreddit, Ad, AdSR, SubSR, AllMinus, AllSR -from r2.models import Friends, All, Sub, NotFound, DomainSR, Random, Mod, RandomNSFW, MultiReddit, ModSR, Frontpage +from r2.models import Friends, All, Sub, NotFound, DomainSR, Random, Mod, RandomNSFW, RandomSubscription, MultiReddit, ModSR, Frontpage from r2.models import Link, Printable, Trophy, bidding, PromoCampaign, PromotionWeights, Comment from r2.models import Flair, FlairTemplate, FlairTemplateBySubredditIndex from r2.models import USER_FLAIR, LINK_FLAIR @@ -1682,11 +1682,14 @@ class SubredditTopBar(CachedTemplate): css_class = 'sr-bar', _id = 'sr-bar') def special_reddits(self): - css_classes = {Random: "random"} + css_classes = {Random: "random", + RandomSubscription: "gold"} reddits = [Frontpage, All, Random] if getattr(c.site, "over_18", False): reddits.append(RandomNSFW) if c.user_is_loggedin: + if c.user.gold: + reddits.append(RandomSubscription) if c.user.friends: reddits.append(Friends) if c.show_mod_mail: diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 103fe201f..fad624344 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -669,6 +669,12 @@ class Subreddit(Thing, Printable): return (Subreddit._byID(random.choice(srs)) if srs else Subreddit._by_name(g.default_sr)) + @classmethod + def random_subscription(cls, user): + srs = Subreddit.reverse_subscriber_ids(user) + return (Subreddit._byID(random.choice(srs)) + if srs else Subreddit._by_name(g.default_sr)) + @classmethod def user_subreddits(cls, user, ids=True, over18=False, limit=DEFAULT_LIMIT, stale=False): @@ -1212,6 +1218,10 @@ class RandomNSFWReddit(FakeSubreddit): name = 'randnsfw' header = "" +class RandomSubscriptionReddit(FakeSubreddit): + name = 'myrandom' + header = "" + class ModContribSR(MultiReddit): name = None title = None @@ -1297,9 +1307,11 @@ Contrib = ContribSR() All = AllSR() Random = RandomReddit() RandomNSFW = RandomNSFWReddit() +RandomSubscription = RandomSubscriptionReddit() Subreddit._specials.update(dict(friends = Friends, randnsfw = RandomNSFW, + myrandom = RandomSubscription, random = Random, mod = Mod, contrib = Contrib, diff --git a/r2/r2/public/static/css/reddit.less b/r2/r2/public/static/css/reddit.less index ffdd3ac47..28c32a36c 100755 --- a/r2/r2/public/static/css/reddit.less +++ b/r2/r2/public/static/css/reddit.less @@ -3409,6 +3409,7 @@ ul#image-preview-list .description pre { .sr-bar .separator {color: gray; } .sr-bar a {color: black;} +.sr-bar a.gold { color: #9a7d2e; font-weight: bold; } #sr-more-link { color: black;