Fix users seeing other users' flair in sidebar.

Move some of the template logic into pages.py so the enflaired user becomes
part of the cache key.
This commit is contained in:
Logan Hanks
2011-08-03 11:05:56 -07:00
parent 6a954a6c25
commit bdf0b42723
2 changed files with 25 additions and 21 deletions

View File

@@ -485,14 +485,23 @@ class SubredditInfoBar(CachedTemplate):
def __init__(self, site = None):
site = site or c.site
#hackity hack. do i need to add all the others props?
# hackity hack. do i need to add all the others props?
self.sr = list(wrap_links(site))[0]
# we want to cache on the number of subscribers
self.subscribers = self.sr._ups
#so the menus cache properly
# so the menus cache properly
self.path = request.path
# if user has flair, then it will be displayed in this bar
self.flair_user = None
if c.user_is_loggedin:
wrapped_user = WrappedUser(c.user, subreddit=self.sr,
force_show_flair=True)
if wrapped_user.has_flair:
self.flair_user = wrapped_user
CachedTemplate.__init__(self)
def nav(self):

View File

@@ -36,24 +36,19 @@
hidden_data = dict(id = thing.sr._fullname))}
</%def>
<%def name="flair_control(user, sr)">
%if c.user_is_loggedin:
<%
wrapped_user = WrappedUser(user, subreddit=sr, force_show_flair=True)
%>
%if wrapped_user.has_flair:
<form class="toggle flairtoggle">
<input id="flair_enabled" type="checkbox" name="flair_enabled"
%if wrapped_user.flair_enabled:
checked="checked"
%endif
>
${_("Show my flair on this reddit. It looks like:")}
<div class="tagline">
${wrapped_user}
</div>
</form>
%endif
<%def name="flair_control(flair_user)">
%if flair_user:
<form class="toggle flairtoggle">
<input id="flair_enabled" type="checkbox" name="flair_enabled"
%if flair_user.flair_enabled:
checked="checked"
%endif
>
${_("Show my flair on this reddit. It looks like:")}
<div class="tagline">
${flair_user}
</div>
</form>
%endif
</%def>
@@ -80,7 +75,7 @@
_("you are no longer an approved submitter"))}
%endif
${flair_control(c.user, thing.sr)}
${flair_control(thing.flair_user)}
%if thing.sr.description:
${thing.sr.usertext}