Replace the entire .content div when loading bare content.

After I moved the ?bare param handling into Reddit, listing choosers
started getting included in bare page renders. This change moves the
related code into Reddit where we can more easily separate it out for
bare page purposes, and out of the .content div.

My fault for mixing metaphors here in the first place -- view
organization doesn't belong in controller code, and the listing chooser
doesn't belong in the same compartment as main page content.
This commit is contained in:
Max Goodman
2013-05-23 23:53:22 -07:00
parent fbaa4ad90f
commit b073d7cef7
5 changed files with 25 additions and 16 deletions

View File

@@ -110,17 +110,10 @@ class ListingController(RedditController, OAuth2ResourceController):
self.listing_obj = self.listing()
content = self.content()
page_classes = self.extra_page_classes
if (self.show_chooser and
c.render_style == "html" and
c.user_is_loggedin and
isinstance(c.site, (DefaultSR, AllSR, ModSR, LabeledMulti))):
page_classes = page_classes + ['with-listing-chooser']
content = PaneStack([ListingChooser(), content])
return self.render_cls(content=content,
page_classes=page_classes,
page_classes=self.extra_page_classes,
show_sidebar=self.show_sidebar,
show_chooser=self.show_chooser,
nav_menus=self.menus,
title=self.title(),
robots=getattr(self, "robots", None),

View File

@@ -1113,6 +1113,8 @@ class RedditController(MinimalController):
elif c.site.domain and c.site.css_on_cname and not c.cname:
c.can_apply_styles = False
c.bare_content = request.GET.pop('bare', False)
c.show_admin_bar = admin_bar_eligible and (c.user_is_admin or g.debug)
if not c.show_admin_bar:
g.stats.end_logging_timings()

View File

@@ -156,9 +156,9 @@ class Reddit(Templated):
def __init__(self, space_compress=None, nav_menus=None, loginbox=True,
infotext='', content=None, short_description='', title='',
robots=None, show_sidebar=True, footer=True, srbar=True,
page_classes=None, show_wiki_actions=False,
extra_js_config=None, **context):
robots=None, show_sidebar=True, show_chooser=False,
footer=True, srbar=True, page_classes=None,
show_wiki_actions=False, extra_js_config=None, **context):
Templated.__init__(self, **context)
self.title = title
self.short_description = short_description
@@ -236,6 +236,13 @@ class Reddit(Templated):
else:
self._content = content
self.show_chooser = (
show_chooser and
c.render_style == "html" and
c.user_is_loggedin and
isinstance(c.site, (DefaultSR, AllSR, ModSR, LabeledMulti))
)
self.toolbars = self.build_toolbars()
def wiki_actions_menu(self, moderator=False):
@@ -494,8 +501,8 @@ class Reddit(Templated):
In adition, unlike Templated.render, the result is in the form of a pylons
Response object with it's content set.
"""
if request.get.pop('bare', False):
res = self._content.render()
if c.bare_content:
res = self.content().render()
else:
res = Templated.render(self, *a, **kw)
@@ -607,6 +614,9 @@ class Reddit(Templated):
if isinstance(c.site, MultiReddit):
classes.add('multi-page')
if self.show_chooser:
classes.add('with-listing-chooser')
if self.extra_page_classes:
classes.update(self.extra_page_classes)
if self.supplied_page_classes:

View File

@@ -70,7 +70,7 @@ r.ui.refreshListing = function() {
url: url.attr('base') + url.attr('path'),
data: params
}).done(function(resp) {
$('#siteTable').replaceWith(resp)
$('body > .content').html(resp)
})
}

View File

@@ -23,7 +23,7 @@
<%!
from r2.lib.template_helpers import add_sr, static, join_urls, class_dict, get_domain
from r2.lib.filters import unsafe
from r2.lib.pages import SearchForm, ClickGadget, SideContentBox, Login
from r2.lib.pages import SearchForm, ClickGadget, SideContentBox, Login, ListingChooser
from r2.lib import tracking
from pylons import request
from r2.lib.strings import strings
@@ -143,6 +143,10 @@
</div>
%endif
%if thing.show_chooser:
${ListingChooser()}
%endif
<% content = getattr(self, "content", None) or thing.content %>
%if content:
##<div class="fixedwidth"><!--IE6sux--></div>