Add a notification on comments page when promoted link is geotargeted.

This commit is contained in:
Brian Simpson
2014-04-08 03:11:22 -04:00
parent a453758924
commit ca4ba0b45b
7 changed files with 89 additions and 0 deletions

View File

@@ -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,

View File

@@ -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)

View File

@@ -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}

View File

@@ -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;

BIN
r2/r2/public/static/map.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 804 B

BIN
r2/r2/public/static/world.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 923 B

View File

@@ -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
%>
<div class="geotarget-notice ${thing.targeting_level}">
${unsafe(safemarkdown(thing.text))}
</div>