Add suggestions for next areas to browse in next/prev line.

This commit is contained in:
Max Goodman
2013-09-25 19:08:48 -07:00
parent 97ee5639e5
commit 3341b2049e
6 changed files with 101 additions and 14 deletions

View File

@@ -82,6 +82,9 @@ class ListingController(RedditController, OAuth2ResourceController):
# class (probably a subclass of Reddit) to use to render the page.
render_cls = Reddit
# class for suggestions next to "next/prev" buttons
next_suggestions_cls = None
#extra parameters to send to the render_cls constructor
render_params = {}
extra_page_classes = ['listing-page']
@@ -168,7 +171,11 @@ class ListingController(RedditController, OAuth2ResourceController):
if (getattr(c.site, "_id", -1) == get_promote_srid() and
not c.user_is_sponsor):
abort(403, 'forbidden')
pane = LinkListing(self.builder_obj, show_nums = self.show_nums).listing()
model = LinkListing(self.builder_obj, show_nums=self.show_nums)
suggestions = None
if self.next_suggestions_cls:
suggestions = self.next_suggestions_cls()
pane = model.listing(next_suggestions=suggestions)
# Indicate that the comment tree wasn't built for comments
for i in pane:
if hasattr(i, 'full_comment_path'):
@@ -228,6 +235,7 @@ class HotController(FixListing, ListingController):
where = 'hot'
extra_page_classes = ListingController.extra_page_classes + ['hot-page']
show_chooser = True
next_suggestions_cls = ListingSuggestions
def make_requested_ad(self):
try:
@@ -395,6 +403,7 @@ class NewController(ListingController):
title_text = _('newest submissions')
extra_page_classes = ListingController.extra_page_classes + ['new-page']
show_chooser = True
next_suggestions_cls = ListingSuggestions
def keep_fn(self):
def keep(item):
@@ -444,6 +453,7 @@ class RisingController(NewController):
class BrowseController(ListingController):
where = 'browse'
show_chooser = True
next_suggestions_cls = ListingSuggestions
def keep_fn(self):
"""For merged time-listings, don't show items that are too old
@@ -493,6 +503,7 @@ class BrowseController(ListingController):
class RandomrisingController(ListingController):
where = 'randomrising'
title_text = _('you\'re really bored now, eh?')
next_suggestions_cls = ListingSuggestions
def query(self):
links = get_rising(c.site)

View File

@@ -4329,3 +4329,20 @@ class SubredditSelector(Templated):
names.sort(key=str.lower)
groups.append((title, names))
return groups
class ListingSuggestions(Templated):
def __init__(self):
self.suggestion_type = None
if c.default_sr:
multis = c.user_is_loggedin and LabeledMulti.by_owner(c.user)
if multis:
self.suggestion_type = "multis"
if len(multis) <= 3:
self.suggestions = multis
else:
self.suggestions = random.sample(multis, 3)
else:
self.suggestion_type = "random"
Templated.__init__(self)

View File

@@ -68,9 +68,10 @@ class Listing(object):
item.render_replaced = True
return builder_items
def listing(self):
def listing(self, next_suggestions=None):
self.things, prev, next, bcount, acount = self.get_items()
self.next_suggestions = next_suggestions
self._max_num = max(acount, bcount)
self.after = None
self.before = None

View File

@@ -963,7 +963,7 @@ a.author { margin-right: 0.5em; }
.sitetable { list-style-type: none; }
.ajaxhook { position: absolute; top: -1000px; left: 0px; }
.nextprev {
.nextprev, .next-suggestions {
color: gray;
font-size: larger;
margin-top: 10px;
@@ -973,6 +973,7 @@ a.author { margin-right: 0.5em; }
background: #eee;
border: 1px solid #ddd;
border-radius: 3px;
font-weight: bold;
}
a:hover {
@@ -990,6 +991,17 @@ a.author { margin-right: 0.5em; }
padding-left: .5em;
border-left: 1px solid #ccc;
}
}
.next-suggestions {
margin-left: 1.5em;
a {
background: none;
font-weight: normal;
margin-left: .5em;
}
}
/* corner help */

View File

@@ -35,17 +35,22 @@
%endfor
%if thing.nextprev and (thing.prev or thing.next):
<p class="nextprev"> ${_("view more:")}&#32;
%if thing.prev:
${plain_link(unsafe("&lsaquo; " + _("prev")), thing.prev, _sr_path = (c.site != Sub), rel="nofollow prev")}
%endif
%if thing.prev and thing.next:
<span class="separator"></span>
%endif
%if thing.next:
${plain_link(unsafe(_("next") + " &rsaquo;"), thing.next, _sr_path = (c.site != Sub), rel="nofollow next")}
%endif
</p>
<div class="nav-buttons">
<span class="nextprev">${_("view more:")}&#32;
%if thing.prev:
${plain_link(unsafe("&lsaquo; " + _("prev")), thing.prev, _sr_path = (c.site != Sub), rel="nofollow prev")}
%endif
%if thing.prev and thing.next:
<span class="separator"></span>
%endif
%if thing.next:
${plain_link(unsafe(_("next") + " &rsaquo;"), thing.next, _sr_path = (c.site != Sub), rel="nofollow next")}
%endif
</span>
%if thing.next_suggestions:
${thing.next_suggestions}
%endif
</div>
%endif
%if not thing.things:
<p id="noresults" class="error">${_("there doesn't seem to be anything here")}</p>

View File

@@ -0,0 +1,41 @@
## The contents of this file are subject to the Common Public Attribution
## License Version 1.0. (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License at
## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
## License Version 1.1, but Sections 14 and 15 have been added to cover use of
## software over a computer network and provide for limited attribution for the
## Original Developer. In addition, Exhibit A has been modified to be
## consistent with Exhibit B.
##
## Software distributed under the License is distributed on an "AS IS" basis,
## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
## the specific language governing rights and limitations under the License.
##
## The Original Code is reddit.
##
## The Original Developer is the Initial Developer. The Initial Developer of
## the Original Code is reddit Inc.
##
## All portions of the code written by reddit are Copyright (c) 2006-2013
## reddit Inc. All Rights Reserved.
###############################################################################
<%namespace file="utils.html" import="text_with_links" />
%if thing.suggestion_type:
<span class="next-suggestions">
%if thing.suggestion_type == 'multis':
${_('or try a multi:')}
%for multi in thing.suggestions:
<a href="${multi.path}">/m/${multi.name}</a>
%endfor
%elif thing.suggestion_type == 'random':
${text_with_links(
_('or try a %(random_subreddit)s'),
random_subreddit=dict(link_text=_("random subreddit"), path="/r/random")
)}
%endif
</span>
%endif