From bdf0b427232fbd00ca77f5e9b35efdb4f09c2b7c Mon Sep 17 00:00:00 2001 From: Logan Hanks Date: Wed, 3 Aug 2011 11:05:56 -0700 Subject: [PATCH] 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. --- r2/r2/lib/pages/pages.py | 13 +++++++++-- r2/r2/templates/subredditinfobar.html | 33 ++++++++++++--------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index cdbab52f6..b8a27d259 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -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): diff --git a/r2/r2/templates/subredditinfobar.html b/r2/r2/templates/subredditinfobar.html index 148a179f5..7c71b3efd 100644 --- a/r2/r2/templates/subredditinfobar.html +++ b/r2/r2/templates/subredditinfobar.html @@ -36,24 +36,19 @@ hidden_data = dict(id = thing.sr._fullname))} -<%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: -
- - ${_("Show my flair on this reddit. It looks like:")} -
- ${wrapped_user} -
-
- %endif +<%def name="flair_control(flair_user)"> + %if flair_user: +
+ + ${_("Show my flair on this reddit. It looks like:")} +
+ ${flair_user} +
+
%endif @@ -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}