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 000000000..f90ef25ec Binary files /dev/null and b/r2/r2/public/static/map.png differ diff --git a/r2/r2/public/static/world.png b/r2/r2/public/static/world.png new file mode 100755 index 000000000..68f21d301 Binary files /dev/null and b/r2/r2/public/static/world.png differ diff --git a/r2/r2/templates/geotargetnotice.html b/r2/r2/templates/geotargetnotice.html new file mode 100644 index 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))} +