mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 00:07:57 -05:00
Exclude subscriptions from Random and RandomNSFW.
This commit is contained in:
@@ -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/"):
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user