mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Add a notification on comments page when promoted link is geotargeted.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
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
BIN
r2/r2/public/static/world.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 923 B |
29
r2/r2/templates/geotargetnotice.html
Normal file
29
r2/r2/templates/geotargetnotice.html
Normal 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>
|
||||
Reference in New Issue
Block a user