Exclude subscriptions from Random and RandomNSFW.

This commit is contained in:
bsimpson63
2013-04-10 09:05:20 -04:00
parent 8eb5cba4ec
commit 31a2ee07ff
2 changed files with 6 additions and 3 deletions

View File

@@ -980,7 +980,7 @@ class RedditController(MinimalController):
# random reddit trickery -- have to do this after the content lang is set
if c.site == Random:
c.site = Subreddit.random_reddit()
c.site = Subreddit.random_reddit(user=c.user)
redirect_to("/" + c.site.path.strip('/') + request.path)
elif c.site == RandomSubscription:
if c.user.gold:
@@ -989,7 +989,7 @@ class RedditController(MinimalController):
else:
redirect_to('/gold/about')
elif c.site == RandomNSFW:
c.site = Subreddit.random_reddit(over18=True)
c.site = Subreddit.random_reddit(over18=True, user=c.user)
redirect_to("/" + c.site.path.strip('/') + request.path)
if not request.path.startswith("/api/login/"):

View File

@@ -660,12 +660,15 @@ class Subreddit(Thing, Printable):
return sr_ids + automatic_ids
@classmethod
def random_reddit(cls, limit = 2500, over18 = False):
def random_reddit(cls, limit=2500, over18=False, user=None):
srs = cls.top_lang_srs(c.content_langs, limit,
filter_allow_top = False,
over18 = over18,
over18_only = over18,
ids=True)
if user:
excludes = cls.user_subreddits(user, over18=over18, limit=None)
srs = list(set(srs) - set(excludes))
return (Subreddit._byID(random.choice(srs))
if srs else Subreddit._by_name(g.default_sr))