mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-05 03:00:15 -04:00
Add new 'other discussions' tab to comments pages
This commit is contained in:
@@ -100,7 +100,9 @@ def make_map(global_conf={}, app_conf={}):
|
||||
mc('/traffic/:article/:title', controller='front',
|
||||
action = 'traffic', title=None)
|
||||
mc('/comments/:article/:title/:comment', controller='front',
|
||||
action= 'comments', title=None, comment = None)
|
||||
action = 'comments', title=None, comment = None)
|
||||
mc('/duplicates/:article/:title', controller = 'front',
|
||||
action = 'duplicates', title=None)
|
||||
|
||||
mc('/mail/optout', controller='front', action = 'optout')
|
||||
mc('/mail/optin', controller='front', action = 'optin')
|
||||
|
||||
@@ -27,7 +27,7 @@ from r2.models import *
|
||||
from r2.lib.pages import *
|
||||
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
|
||||
from r2.lib.utils import query_string, UrlParser, link_from_url, link_duplicates
|
||||
from r2.lib.template_helpers import get_domain
|
||||
from r2.lib.emailer import has_opted_out, Email
|
||||
from r2.lib.db.operators import desc
|
||||
@@ -192,6 +192,7 @@ class FrontController(RedditController):
|
||||
|
||||
res = LinkInfoPage(link = article, comment = comment,
|
||||
content = displayPane,
|
||||
subtitle = _("comments"),
|
||||
nav_menus = [CommentSortMenu(default = sort),
|
||||
NumCommentsMenu(article.num_comments,
|
||||
default=num_comments)],
|
||||
@@ -336,7 +337,24 @@ class FrontController(RedditController):
|
||||
num = num, after = after, reverse = reverse,
|
||||
count = count)
|
||||
|
||||
return LinkInfoPage(link = article, content = pane).render()
|
||||
return LinkInfoPage(link = article, content = pane,
|
||||
subtitle = _('related')).render()
|
||||
|
||||
@base_listing
|
||||
@validate(article = VLink('article'))
|
||||
def GET_duplicates(self, article):
|
||||
links = link_duplicates(article)
|
||||
|
||||
builder = IDBuilder([ link._fullname for link in links ],
|
||||
skip = False)
|
||||
listing = LinkListing(builder).listing()
|
||||
|
||||
res = LinkInfoPage(link = article,
|
||||
comment = None,
|
||||
duplicates = links,
|
||||
content = listing,
|
||||
subtitle = _('other discussions')).render()
|
||||
return res
|
||||
|
||||
@base_listing
|
||||
@validate(query = nop('q'))
|
||||
|
||||
@@ -116,6 +116,7 @@ menu = MenuHandler(hot = _('hot'),
|
||||
# comments
|
||||
related = _("related"),
|
||||
details = _("details"),
|
||||
duplicates = _("other discussions (%(num)s)"),
|
||||
traffic = _("traffic"),
|
||||
|
||||
# reddits
|
||||
@@ -294,9 +295,10 @@ class NamedButton(NavButton):
|
||||
'dest' defaults to the 'name' as well (unless specified
|
||||
separately)."""
|
||||
|
||||
def __init__(self, name, sr_path = True, nocname=False, dest = None, **kw):
|
||||
def __init__(self, name, sr_path = True, nocname=False, dest = None, fmt_args = {}, **kw):
|
||||
self.name = name.strip('/')
|
||||
NavButton.__init__(self, menu[self.name], name if dest is None else dest,
|
||||
menutext = menu[self.name] % fmt_args
|
||||
NavButton.__init__(self, menutext, name if dest is None else dest,
|
||||
sr_path = sr_path, nocname=nocname, **kw)
|
||||
|
||||
def selected_title(self):
|
||||
|
||||
@@ -39,6 +39,7 @@ from r2.lib.menus import SubredditButton, SubredditMenu
|
||||
from r2.lib.menus import OffsiteButton, menu, JsNavMenu
|
||||
from r2.lib.strings import plurals, rand_strings, strings, Score
|
||||
from r2.lib.utils import title_to_url, query_string, UrlParser, to_js, vote_hash
|
||||
from r2.lib.utils import link_duplicates
|
||||
from r2.lib.template_helpers import add_sr, get_domain
|
||||
from r2.lib.subreddit_search import popular_searches
|
||||
|
||||
@@ -546,7 +547,8 @@ class LinkInfoPage(Reddit):
|
||||
create_reddit_box = False
|
||||
|
||||
def __init__(self, link = None, comment = None,
|
||||
link_title = '', *a, **kw):
|
||||
link_title = '', subtitle = None, duplicates = None,
|
||||
*a, **kw):
|
||||
from r2.controllers.listingcontroller import ListingController
|
||||
wrapper = make_wrapper(ListingController.builder_wrapper,
|
||||
expand_children = True)
|
||||
@@ -572,18 +574,30 @@ class LinkInfoPage(Reddit):
|
||||
params = {'title':_force_unicode(link_title), 'site' : c.site.name}
|
||||
title = strings.link_info_title % params
|
||||
|
||||
self.subtitle = subtitle
|
||||
|
||||
# if we're already looking at the 'duplicates' page, we can
|
||||
# avoid doing this lookup twice
|
||||
if duplicates is None:
|
||||
self.duplicates = link_duplicates(self.link)
|
||||
else:
|
||||
self.duplicates = duplicates
|
||||
|
||||
Reddit.__init__(self, title = title, *a, **kw)
|
||||
|
||||
def build_toolbars(self):
|
||||
base_path = "/%s/%s/" % (self.link._id36, title_to_url(self.link.title))
|
||||
base_path = _force_utf8(base_path)
|
||||
def info_button(name):
|
||||
def info_button(name, **fmt_args):
|
||||
return NamedButton(name, dest = '/%s%s' % (name, base_path),
|
||||
aliases = ['/%s/%s' % (name, self.link._id36)])
|
||||
|
||||
aliases = ['/%s/%s' % (name, self.link._id36)],
|
||||
fmt_args = fmt_args)
|
||||
|
||||
buttons = [info_button('comments'),
|
||||
info_button('related')]
|
||||
|
||||
if not self.link.is_self and self.duplicates:
|
||||
buttons.append(info_button('duplicates', num = len(self.duplicates)))
|
||||
if c.user_is_admin:
|
||||
buttons += [info_button('details')]
|
||||
if c.user_is_sponsor:
|
||||
@@ -601,7 +615,7 @@ class LinkInfoPage(Reddit):
|
||||
return self.content_stack((self.infobar, self.link_listing,
|
||||
PaneStack([PaneStack((self.nav_menu,
|
||||
self._content))],
|
||||
title = _("comments"),
|
||||
title = self.subtitle,
|
||||
css_class = "commentarea")))
|
||||
|
||||
def rightbox(self):
|
||||
|
||||
@@ -1083,3 +1083,16 @@ def link_from_url(path, filter_spam = False, multiple = True):
|
||||
# among those, show them the hottest one
|
||||
return links if multiple else links[0]
|
||||
|
||||
def link_duplicates(article):
|
||||
from r2.models import Link, NotFound
|
||||
|
||||
try:
|
||||
links = tup(Link._by_url(article.url, None))
|
||||
except NotFound:
|
||||
links = []
|
||||
|
||||
duplicates = [ link for link in links
|
||||
if link._fullname != article._fullname ]
|
||||
|
||||
return duplicates
|
||||
|
||||
|
||||
Reference in New Issue
Block a user