This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add /r/myrandom (gold only for now)

Takes you to a random subreddit you subscribe to
  • Loading branch information...
Deimos committed Mar 2, 2013
1 parent c295ea0 commit a769dd66661447ae8d2f34d8704f14e67797870c
Showing with 25 additions and 2 deletions.
  1. +7 −0 r2/r2/controllers/reddit_base.py
  2. +5 −2 r2/r2/lib/pages/pages.py
  3. +12 −0 r2/r2/models/subreddit.py
  4. +1 −0 r2/r2/public/static/css/reddit.less
@@ -96,6 +96,7 @@
NotFound,
Random,
RandomNSFW,
+ RandomSubscription,
Sub,
Subreddit,
valid_admin_cookie,
@@ -975,6 +976,12 @@ def pre(self):
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)
View
@@ -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 @@ def popular_reddits(self, exclude=[]):
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:
View
@@ -669,6 +669,12 @@ def random_reddit(cls, limit = 2500, over18 = False):
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 @@ def get_links(self, sort, time):
All = AllSR()
Random = RandomReddit()
RandomNSFW = RandomNSFWReddit()
+RandomSubscription = RandomSubscriptionReddit()
Subreddit._specials.update(dict(friends = Friends,
randnsfw = RandomNSFW,
+ myrandom = RandomSubscription,
random = Random,
mod = Mod,
contrib = Contrib,
@@ -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;

0 comments on commit a769dd6

Please sign in to comment.