From bc7d4cf9286cd71ec1ea2ecde6589fe626ddbd04 Mon Sep 17 00:00:00 2001 From: Matt Lee Date: Mon, 3 Aug 2015 14:37:59 -0700 Subject: [PATCH] Quarantine: Move feature flag checks out of templates. --- r2/r2/lib/pages/pages.py | 3 +++ r2/r2/models/link.py | 5 ++++- r2/r2/templates/comment.compact | 2 +- r2/r2/templates/comment.html | 2 +- r2/r2/templates/link.html | 4 ++-- r2/r2/templates/sidebarmodlist.html | 2 +- r2/r2/templates/subredditinfobar.html | 2 +- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 81128782d..c01bf6105 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -1046,6 +1046,8 @@ class SubredditInfoBar(CachedTemplate): self.sr_style_toggle = False self.use_subreddit_style = True + self.quarantine_enabled = feature.is_enabled('quarantine') + if (c.user_is_loggedin and (self.sr.stylesheet_url or self.sr.header) and feature.is_enabled('stylesheets_everywhere')): @@ -2252,6 +2254,7 @@ class SidebarModList(Templated): # primary sort is desc. subscribers, secondary is name self.subreddits = sorted(subreddits, key=lambda sr: (-sr._ups, sr.name.lower())) + self.quarantine_enabled = feature.is_enabled('quarantine') class ProfileBar(Templated): diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index 61b25f1ce..c96300cb9 100644 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -501,7 +501,8 @@ class Link(Thing, Printable): item.nsfw_str) item.nsfw = item.over_18 and user.pref_label_nsfw - item.quarantine = item.subreddit.quarantine + item.quarantine_enabled = feature.is_enabled('quarantine') + item.quarantine = item.quarantine_enabled and item.subreddit.quarantine item.show_new_post_sharing = feature.is_enabled('improved_sharing') @@ -1296,6 +1297,8 @@ class Comment(Thing, Printable): item.profilepage = c.profilepage item.link = links.get(item.link_id) + item.quarantine_enabled = feature.is_enabled('quarantine') + if (item.link._score <= 1 or item.score < 3 or item.link._spam or item._spam or item.author._spam): item.nofollow = True diff --git a/r2/r2/templates/comment.compact b/r2/r2/templates/comment.compact index f688a35f3..bfde45c2b 100644 --- a/r2/r2/templates/comment.compact +++ b/r2/r2/templates/comment.compact @@ -49,7 +49,7 @@ ${thing.link.url} %endif %endif - %if feature.is_enabled('quarantine'): + %if thing.quarantine_enabled: %if thing.subreddit.quarantine: ${quarantine_stamp()} diff --git a/r2/r2/templates/comment.html b/r2/r2/templates/comment.html index f6752f641..5bbdf16c3 100644 --- a/r2/r2/templates/comment.html +++ b/r2/r2/templates/comment.html @@ -146,7 +146,7 @@ ${parent.midcol(cls = cls)} <%def name="buttons()"> - %if c.profilepage and feature.is_enabled('quarantine'): + %if c.profilepage and thing.quarantine_enabled: %if thing.subreddit.quarantine:
  • ${quarantine_stamp()} diff --git a/r2/r2/templates/link.html b/r2/r2/templates/link.html index 6bf7d6e7a..922afbcc5 100644 --- a/r2/r2/templates/link.html +++ b/r2/r2/templates/link.html @@ -69,9 +69,9 @@ <%def name="bottom_buttons()">
      <% - stamp_style = 'bold-stamp' if feature.is_enabled('quarantine') else '' + stamp_style = 'bold-stamp' if thing.quarantine_enabled else '' %> - %if thing.quarantine and feature.is_enabled('quarantine'): + %if thing.quarantine_enabled and thing.quarantine:
    • ${quarantine_stamp()}
    • diff --git a/r2/r2/templates/sidebarmodlist.html b/r2/r2/templates/sidebarmodlist.html index ff553c8cf..da8b1f1a3 100644 --- a/r2/r2/templates/sidebarmodlist.html +++ b/r2/r2/templates/sidebarmodlist.html @@ -30,7 +30,7 @@ %for sr in thing.subreddits:
    • /r/${sr.name} - %if feature.is_enabled('quarantine'): + %if thing.quarantine_enabled: %if sr.quarantine: ${quarantine_stamp()} diff --git a/r2/r2/templates/subredditinfobar.html b/r2/r2/templates/subredditinfobar.html index cf90cc38d..048fdb499 100644 --- a/r2/r2/templates/subredditinfobar.html +++ b/r2/r2/templates/subredditinfobar.html @@ -37,7 +37,7 @@ ${plain_link(thing.sr.name, thing.sr.path, _sr_path=False, _class="hover")} - %if thing.sr.quarantine and feature.is_enabled('quarantine'): + %if thing.sr.quarantine and thing.quarantine_enabled:
      ${_md("This community is quarantined because of its distasteful and highly offensive content.", wrap=True)}