From ca4ba0b45b265ac2379aed93aee0a4bc87bb541e Mon Sep 17 00:00:00 2001 From: Brian Simpson Date: Tue, 8 Apr 2014 03:11:22 -0400 Subject: [PATCH] Add a notification on comments page when promoted link is geotargeted. --- r2/r2/controllers/front.py | 6 ++++++ r2/r2/lib/pages/pages.py | 16 +++++++++++++++ r2/r2/lib/promote.py | 18 +++++++++++++++++ r2/r2/public/static/css/reddit.less | 20 ++++++++++++++++++ r2/r2/public/static/map.png | Bin 0 -> 804 bytes r2/r2/public/static/world.png | Bin 0 -> 923 bytes r2/r2/templates/geotargetnotice.html | 29 +++++++++++++++++++++++++++ 7 files changed, 89 insertions(+) create mode 100755 r2/r2/public/static/map.png create mode 100755 r2/r2/public/static/world.png create mode 100644 r2/r2/templates/geotargetnotice.html diff --git a/r2/r2/controllers/front.py b/r2/r2/controllers/front.py index 2c60b0f1d..04fdecbc6 100755 --- a/r2/r2/controllers/front.py +++ b/r2/r2/controllers/front.py @@ -340,6 +340,12 @@ class FrontController(RedditController): age = c.start_time - article._date if article.promoted or age.days < g.REPLY_AGE_LIMIT: display = True + + if article.promoted: + geotargeted, city_target = promote.is_geotargeted_promo(article) + if geotargeted: + displayPane.append(GeotargetNotice(city_target=city_target)) + displayPane.append(UserText(item=article, creating=True, post_form='comment', display=display, diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 240fa2292..a5091dae7 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -4392,3 +4392,19 @@ class TrendingSubredditsBar(Templated): self.comment_count = comment_count self.comment_label, self.comment_label_cls = \ comment_label(comment_count) + + +class GeotargetNotice(Templated): + def __init__(self, city_target=False): + self.targeting_level = "city" if city_target else "country" + if city_target: + text = _("this promoted link uses city level targeting and may " + "have been shown to you because of your location. " + "([learn more](%(link)s))") + else: + text = _("this promoted link uses country level targeting and may " + "have been shown to you because of your location. " + "([learn more](%(link)s))") + more_link = "/wiki/targetingbycountrycity" + self.text = text % {"link": more_link} + Templated.__init__(self) diff --git a/r2/r2/lib/promote.py b/r2/r2/lib/promote.py index 9cabd3f2e..36cd3c962 100644 --- a/r2/r2/lib/promote.py +++ b/r2/r2/lib/promote.py @@ -475,6 +475,24 @@ def is_live_promo(link, campaign): return is_promoted(link) and is_scheduled_promo(now, link, campaign) +def _is_geotargeted_promo(link): + campaigns = live_campaigns_by_link(link) + geotargeted = filter(lambda camp: camp.location, campaigns) + city_target = any(camp.location.metro for camp in geotargeted) + return bool(geotargeted), city_target + + +def is_geotargeted_promo(link): + key = 'geotargeted_promo_%s' % link._id + from_cache = g.cache.get(key) + if not from_cache: + ret = _is_geotargeted_promo(link) + g.cache.set(key, ret, time=60) + return ret + else: + return from_cache + + def get_promos(date, sr_names=None, link=None): pws = PromotionWeights.get_campaigns(date, sr_names=sr_names, link=link) campaign_ids = {pw.promo_idx for pw in pws} diff --git a/r2/r2/public/static/css/reddit.less b/r2/r2/public/static/css/reddit.less index f02cc76b7..a2b659956 100755 --- a/r2/r2/public/static/css/reddit.less +++ b/r2/r2/public/static/css/reddit.less @@ -1573,6 +1573,26 @@ body.with-listing-chooser.explore-page #header .pagename { right: 0; } +.geotarget-notice { + margin: 5px 10px; + height: 16px; + background-repeat: no-repeat; + text-indent: 20px; + + .md p { + font-size: smaller; + margin: 0; + } + + &.city { + background-image: url(../map.png); /* SPRITE */ + } + + &.country { + background-image: url(../world.png); /* SPRITE */ + } +} + .promote-pixel { position: absolute; top: -1000px; diff --git a/r2/r2/public/static/map.png b/r2/r2/public/static/map.png new file mode 100755 index 0000000000000000000000000000000000000000..f90ef25ec7f1cb0fdae38d9fe2d9edeee9928ef1 GIT binary patch literal 804 zcmV+<1Ka$GP)mbpQb1@7I~O+ue5CWtZi#AZox@gcwb{Xkx^Rf;Ty8yn6DWhJV4kC*wg94<7Vt zlteKm5+jKLV^qM1yt2HO4YZw^&a^Wfzb_m+@y40e_0^+M6ajz$03Zl}fU=sqfA9W} z@#^~O(a%3QB{YI^J_A4y)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 000000000..dfa7f02fb --- /dev/null +++ b/r2/r2/templates/geotargetnotice.html @@ -0,0 +1,29 @@ +## The contents of this file are subject to the Common Public Attribution +## License Version 1.0. (the "License"); you may not use this file except in +## compliance with the License. You may obtain a copy of the License at +## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public +## License Version 1.1, but Sections 14 and 15 have been added to cover use of +## software over a computer network and provide for limited attribution for the +## Original Developer. In addition, Exhibit A has been modified to be +## consistent with Exhibit B. +## +## Software distributed under the License is distributed on an "AS IS" basis, +## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +## the specific language governing rights and limitations under the License. +## +## The Original Code is reddit. +## +## The Original Developer is the Initial Developer. The Initial Developer of +## the Original Code is reddit Inc. +## +## All portions of the code written by reddit are Copyright (c) 2006-2013 +## reddit Inc. All Rights Reserved. +############################################################################### + +<%! + from r2.lib.filters import unsafe, safemarkdown +%> + +
+ ${unsafe(safemarkdown(thing.text))} +