mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-24 14:27:58 -05:00
hot_links_by_url_listing: Return a listing of links for a given url.
This commit is contained in:
@@ -35,11 +35,11 @@ from r2.models import *
|
||||
from r2.config.extensions import is_api
|
||||
from r2.lib import recommender
|
||||
from r2.lib.pages import *
|
||||
from r2.lib.pages.things import wrap_links
|
||||
from r2.lib.pages.things import hot_links_by_url_listing
|
||||
from r2.lib.pages import trafficpages
|
||||
from r2.lib.menus import *
|
||||
from r2.lib.utils import to36, sanitize_url, check_cheating, title_to_url
|
||||
from r2.lib.utils import query_string, UrlParser, link_from_url, url_links_builder
|
||||
from r2.lib.utils import query_string, UrlParser, url_links_builder
|
||||
from r2.lib.template_helpers import get_domain
|
||||
from r2.lib.filters import unsafe, _force_unicode, _force_utf8
|
||||
from r2.lib.emailer import Email
|
||||
@@ -990,14 +990,16 @@ class FrontController(RedditController, OAuth2ResourceController):
|
||||
resubmit = request.GET.get('resubmit')
|
||||
if url and not resubmit:
|
||||
# check to see if the url has already been submitted
|
||||
links = link_from_url(url)
|
||||
listing = hot_links_by_url_listing(url, sr=c.site)
|
||||
links = listing.things
|
||||
|
||||
if links and len(links) == 1:
|
||||
return self.redirect(links[0].already_submitted_link)
|
||||
elif links:
|
||||
infotext = (strings.multiple_submitted
|
||||
% links[0].resubmit_link())
|
||||
res = BoringPage(_("seen it"),
|
||||
content=wrap_links(links),
|
||||
content=listing,
|
||||
infotext=infotext).render()
|
||||
return res
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
from reddit_base import RedditController
|
||||
from r2.lib.pages import *
|
||||
from r2.models import *
|
||||
from r2.lib.pages.things import wrap_links
|
||||
from r2.lib.pages.things import hot_links_by_url_listing, wrap_links
|
||||
from r2.lib.menus import CommentSortMenu
|
||||
from r2.lib.filters import spaceCompress, safemarkdown
|
||||
from r2.lib.memoize import memoize
|
||||
@@ -152,7 +152,8 @@ class ToolbarController(RedditController):
|
||||
if is_shamed_domain(path)[0]:
|
||||
self.abort404()
|
||||
|
||||
link = utils.link_from_url(path, multiple = False)
|
||||
listing = hot_links_by_url_listing(path, sr=c.site, num=1)
|
||||
link = listing.things[0] if listing.things else None
|
||||
|
||||
if c.cname and not c.authorized_cname:
|
||||
# In this case, we make some bad guesses caused by the
|
||||
@@ -229,25 +230,24 @@ class ToolbarController(RedditController):
|
||||
url = nop('url'))
|
||||
def GET_toolbar(self, link, url):
|
||||
"""The visible toolbar, with voting buttons and all"""
|
||||
if not link:
|
||||
link = utils.link_from_url(url, multiple = False)
|
||||
|
||||
if link:
|
||||
link = list(wrap_links(link, wrapper = FrameToolbar))
|
||||
if link:
|
||||
res = link[0]
|
||||
listing = wrap_links(link, wrapper=FrameToolbar, skip=True, num=1)
|
||||
elif url:
|
||||
url = demangle_url(url)
|
||||
if not url: # also check for validity
|
||||
return self.abort404()
|
||||
|
||||
res = FrameToolbar(link = None,
|
||||
title = None,
|
||||
url = url,
|
||||
expanded = False)
|
||||
listing = hot_links_by_url_listing(url, sr=c.site, num=1, skip=True)
|
||||
else:
|
||||
return self.abort404()
|
||||
|
||||
url = demangle_url(url)
|
||||
res = None
|
||||
if listing.things:
|
||||
res = listing.things[0]
|
||||
elif url:
|
||||
res = FrameToolbar(link=None, title=None, url=url, expanded=False)
|
||||
|
||||
if res:
|
||||
return spaceCompress(res.render())
|
||||
else:
|
||||
return self.abort404()
|
||||
return spaceCompress(res.render())
|
||||
|
||||
@validate(link = VByName('id'))
|
||||
def GET_inner(self, link):
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
# Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
from r2.lib.db.thing import NotFound
|
||||
from r2.lib.menus import Styled
|
||||
from r2.lib.wrapped import Wrapped
|
||||
from r2.models import LinkListing, Link, PromotedLink
|
||||
@@ -235,6 +236,17 @@ def wrap_links(links, wrapper = default_thing_wrapper(),
|
||||
return l.listing()
|
||||
|
||||
|
||||
def hot_links_by_url_listing(url, sr=None, num=None, **kw):
|
||||
try:
|
||||
links_for_url = Link._by_url(url, sr)
|
||||
except NotFound:
|
||||
links_for_url = []
|
||||
|
||||
links_for_url.sort(key=lambda link: link._hot, reverse=True)
|
||||
listing = wrap_links(links_for_url, num=num, **kw)
|
||||
return listing
|
||||
|
||||
|
||||
def wrap_things(*things):
|
||||
"""Instantiate Wrapped for each thing, calling add_props if available."""
|
||||
if not things:
|
||||
|
||||
Reference in New Issue
Block a user