mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-30 01:08:32 -05:00
Add /r/myrandom (gold only for now)
Takes you to a random subreddit you subscribe to
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user