mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Enable per-user global selfserve cpm override.
Setting Account.selfserve_cpm_override_pennies will let the user create campaigns with ANY targeting at that price.
This commit is contained in:
@@ -883,7 +883,7 @@ class PromoteApiController(ApiController):
|
||||
if not allowed_location_and_target(location, target):
|
||||
return abort(403, 'forbidden')
|
||||
|
||||
cpm = PromotionPrices.get_price(target, location)
|
||||
cpm = PromotionPrices.get_price(c.user, target, location)
|
||||
|
||||
if (form.has_errors('startdate', errors.BAD_DATE,
|
||||
errors.DATE_TOO_EARLY, errors.DATE_TOO_LATE) or
|
||||
|
||||
@@ -3907,7 +3907,7 @@ class PromoteLinkEdit(PromoteLinkBase):
|
||||
'faq': 'http://www.reddit.com/wiki/selfserve',
|
||||
}
|
||||
self.infobar = InfoBar(message=message)
|
||||
self.price_dict = PromotionPrices.get_price_dict()
|
||||
self.price_dict = PromotionPrices.get_price_dict(c.user)
|
||||
|
||||
|
||||
class RenderableCampaign(Templated):
|
||||
|
||||
@@ -138,6 +138,7 @@ class Account(Thing):
|
||||
num_failed_payments=0,
|
||||
pref_show_snoovatar=False,
|
||||
gild_reveal_username=False,
|
||||
selfserve_cpm_override_pennies=None,
|
||||
)
|
||||
_preference_attrs = tuple(k for k in _defaults.keys()
|
||||
if k.startswith("pref_"))
|
||||
|
||||
@@ -666,7 +666,10 @@ class PromotionPrices(tdb_cassandra.View):
|
||||
return columns.get(column_name)
|
||||
|
||||
@classmethod
|
||||
def get_price(cls, target, location):
|
||||
def get_price(cls, user, target, location):
|
||||
if user.selfserve_cpm_override_pennies:
|
||||
return user.selfserve_cpm_override_pennies
|
||||
|
||||
prices = []
|
||||
|
||||
# set location specific prices or use defaults
|
||||
@@ -695,48 +698,60 @@ class PromotionPrices(tdb_cassandra.View):
|
||||
return max(prices)
|
||||
|
||||
@classmethod
|
||||
def get_price_dict(cls):
|
||||
r = {
|
||||
"COLLECTION": {},
|
||||
"SUBREDDIT": {},
|
||||
"COUNTRY": {},
|
||||
"METRO": {},
|
||||
"COLLECTION_DEFAULT": g.cpm_selfserve_collection.pennies,
|
||||
"SUBREDDIT_DEFAULT": g.cpm_selfserve.pennies,
|
||||
"COUNTRY_DEFAULT": g.cpm_selfserve_collection.pennies,
|
||||
"METRO_DEFAULT": g.cpm_selfserve_geotarget_metro.pennies,
|
||||
}
|
||||
def get_price_dict(cls, user):
|
||||
if user.selfserve_cpm_override_pennies:
|
||||
r = {
|
||||
"COLLECTION": {},
|
||||
"SUBREDDIT": {},
|
||||
"COUNTRY": {},
|
||||
"METRO": {},
|
||||
"COLLECTION_DEFAULT": user.selfserve_cpm_override_pennies,
|
||||
"SUBREDDIT_DEFAULT": user.selfserve_cpm_override_pennies,
|
||||
"COUNTRY_DEFAULT": user.selfserve_cpm_override_pennies,
|
||||
"METRO_DEFAULT": user.selfserve_cpm_override_pennies,
|
||||
}
|
||||
else:
|
||||
r = {
|
||||
"COLLECTION": {},
|
||||
"SUBREDDIT": {},
|
||||
"COUNTRY": {},
|
||||
"METRO": {},
|
||||
"COLLECTION_DEFAULT": g.cpm_selfserve_collection.pennies,
|
||||
"SUBREDDIT_DEFAULT": g.cpm_selfserve.pennies,
|
||||
"COUNTRY_DEFAULT": g.cpm_selfserve_collection.pennies,
|
||||
"METRO_DEFAULT": g.cpm_selfserve_geotarget_metro.pennies,
|
||||
}
|
||||
|
||||
try:
|
||||
collections = cls._cf.get("COLLECTION")
|
||||
except tdb_cassandra.NotFoundException:
|
||||
collections = {}
|
||||
try:
|
||||
collections = cls._cf.get("COLLECTION")
|
||||
except tdb_cassandra.NotFoundException:
|
||||
collections = {}
|
||||
|
||||
try:
|
||||
subreddits = cls._cf.get("SUBREDDIT")
|
||||
except tdb_cassandra.NotFoundException:
|
||||
subreddits = {}
|
||||
try:
|
||||
subreddits = cls._cf.get("SUBREDDIT")
|
||||
except tdb_cassandra.NotFoundException:
|
||||
subreddits = {}
|
||||
|
||||
try:
|
||||
countries = cls._cf.get("COUNTRY")
|
||||
except tdb_cassandra.NotFoundException:
|
||||
countries = {}
|
||||
try:
|
||||
countries = cls._cf.get("COUNTRY")
|
||||
except tdb_cassandra.NotFoundException:
|
||||
countries = {}
|
||||
|
||||
try:
|
||||
metros = cls._cf.get("METRO")
|
||||
except tdb_cassandra.NotFoundException:
|
||||
metros = {}
|
||||
try:
|
||||
metros = cls._cf.get("METRO")
|
||||
except tdb_cassandra.NotFoundException:
|
||||
metros = {}
|
||||
|
||||
for name, cpm in collections.iteritems():
|
||||
r["COLLECTION"][name] = cpm
|
||||
for name, cpm in collections.iteritems():
|
||||
r["COLLECTION"][name] = cpm
|
||||
|
||||
for name, cpm in subreddits.iteritems():
|
||||
r["SUBREDDIT"][name] = cpm
|
||||
for name, cpm in subreddits.iteritems():
|
||||
r["SUBREDDIT"][name] = cpm
|
||||
|
||||
for name, cpm in countries.iteritems():
|
||||
r["COUNTRY"][name] = cpm
|
||||
for name, cpm in countries.iteritems():
|
||||
r["COUNTRY"][name] = cpm
|
||||
|
||||
for name, cpm in metros.iteritems():
|
||||
r["METRO"][name] = cpm
|
||||
for name, cpm in metros.iteritems():
|
||||
r["METRO"][name] = cpm
|
||||
|
||||
return r
|
||||
|
||||
Reference in New Issue
Block a user