diff --git a/r2/r2/config/routing.py b/r2/r2/config/routing.py index 28c880e94..3ab05823c 100644 --- a/r2/r2/config/routing.py +++ b/r2/r2/config/routing.py @@ -92,7 +92,7 @@ def make_map(global_conf={}, app_conf={}): mc('/', controller='hot', action='listing') - listing_controllers = "hot|saved|toplinks|new|recommended|normalized" + listing_controllers = "hot|saved|toplinks|new|recommended|normalized|randomrising" mc('/:controller', action='listing', requirements=dict(controller=listing_controllers)) diff --git a/r2/r2/controllers/__init__.py b/r2/r2/controllers/__init__.py index 02553eee9..8ae9b83eb 100644 --- a/r2/r2/controllers/__init__.py +++ b/r2/r2/controllers/__init__.py @@ -30,6 +30,7 @@ from listingcontroller import RecommendedController from listingcontroller import MessageController from listingcontroller import RedditsController from listingcontroller import MyredditsController +from listingcontroller import RandomrisingController from feedback import FeedbackController from front import FrontController diff --git a/r2/r2/controllers/listingcontroller.py b/r2/r2/controllers/listingcontroller.py index 0019c2658..a4899d085 100644 --- a/r2/r2/controllers/listingcontroller.py +++ b/r2/r2/controllers/listingcontroller.py @@ -35,6 +35,9 @@ from r2.lib import organic from pylons.i18n import _ +import random + + class ListingController(RedditController): """Generalized controller for pages with lists of links.""" @@ -133,7 +136,6 @@ class ListingController(RedditController): @staticmethod def builder_wrapper(thing): - """""" if c.user.pref_compress and isinstance(thing, Link): thing.__class__ = LinkCompressed thing.score_fmt = Score.points @@ -333,6 +335,26 @@ class BrowseController(ListingController): return ListingController.GET_listing(self, **env) +class RandomrisingController(ListingController): + where = 'randomrising' + builder_cls = IDBuilder + title_text = _('you\'re really bored now, eh?') + + def query(self): + links = get_rising(c.site) + + if not links: + # just pull from the new page if the rising page isn't + # populated for some reason + q = Link._query(limit = 200, + data = True, + sort = desc('_date')) + links = [ x._fullname for x in q ] + + random.shuffle(links) + + return links + class RecommendedController(ListingController): where = 'recommended' builder_cls = IDBuilder