Delete link_from_url and filter_links.

This commit is contained in:
Brian Simpson
2013-12-24 20:16:02 -05:00
parent 20419241df
commit c13923cd2f

View File

@@ -909,53 +909,6 @@ def common_subdomain(domain1, domain2):
return ""
def link_from_url(path, filter_spam = False, multiple = True):
from pylons import c
from r2.models import IDBuilder, Link, Subreddit, NotFound
if not path:
return
try:
links = Link._by_url(path, c.site)
except NotFound:
return [] if multiple else None
return filter_links(tup(links), filter_spam = filter_spam,
multiple = multiple)
def filter_links(links, filter_spam = False, multiple = True):
# run the list through a builder to remove any that the user
# isn't allowed to see
from pylons import c
from r2.models import IDBuilder, Link, Subreddit, NotFound
links = IDBuilder([link._fullname for link in links],
skip = False).get_items()[0]
if not links:
return
if filter_spam:
# first, try to remove any spam
links_nonspam = [ link for link in links
if not link._spam ]
if links_nonspam:
links = links_nonspam
# if it occurs in one or more of their subscriptions, show them
# that one first
subs = set(Subreddit.user_subreddits(c.user, limit = None))
def cmp_links(a, b):
if a.sr_id in subs and b.sr_id not in subs:
return -1
elif a.sr_id not in subs and b.sr_id in subs:
return 1
else:
return cmp(b._hot, a._hot)
links = sorted(links, cmp = cmp_links)
# among those, show them the hottest one
return links if multiple else links[0]
def url_links_builder(url, exclude=None, num=None, after=None, reverse=None,
count=None):
from r2.lib.template_helpers import add_sr