Subreddit AllMinus that subtracts from /r/all.

This commit is contained in:
Brian Simpson
2011-07-18 17:51:25 -07:00
committed by bsimpson63
parent 9723a6fc9f
commit 5ee83b1636
2 changed files with 34 additions and 0 deletions

View File

@@ -78,6 +78,7 @@ from r2.lib.validator import (
)
from r2.models import (
All,
AllMinus,
check_request,
DefaultSR,
DomainSR,
@@ -338,6 +339,16 @@ def set_subreddit():
else:
sr_ids = [sr._id for sr in srs]
c.site = MultiReddit(sr_ids, sr_name)
elif '-' in sr_name:
sr_names = sr_name.split('-')
if not sr_names[0].lower() == All.name.lower():
abort(404)
srs = Subreddit._by_name(sr_names[1:], stale=can_stale).values()
srs = [sr for sr in srs if not isinstance(sr, FakeSubreddit)]
if not srs:
c.site = All
else:
c.site = AllMinus(srs)
else:
try:
c.site = Subreddit._by_name(sr_name, stale=can_stale)

View File

@@ -973,6 +973,29 @@ class AllSR(FakeSubreddit):
return None
class AllMinus(AllSR):
name = 'minus'
def __init__(self, srs):
AllSR.__init__(self)
self.srs = srs
self.sr_ids = [sr._id for sr in srs]
@property
def title(self):
return 'all minus ' + ' '.join(sr.name for sr in self.srs)
@property
def path(self):
return '/r/all-' + '-'.join(sr.name for sr in self.srs)
def get_links(self, sort, time):
from r2.models import Link
from r2.lib.db.operators import not_
q = AllSR.get_links(self, sort, time)
q._filter(not_(Link.c.sr_id.in_(self.sr_ids)))
return q
class _DefaultSR(FakeSubreddit):
#notice the space before reddit.com
name = ' reddit.com'