Take PromoCampaigns as inputs in promote.get_total_run.

This commit is contained in:
bsimpson63
2013-04-25 10:17:54 -04:00
parent b717296dd6
commit 97caffc934
2 changed files with 7 additions and 4 deletions

View File

@@ -464,7 +464,7 @@ def get_traffic_dates(thing):
start, end = start.replace(tzinfo=g.tz), end.replace(tzinfo=g.tz)
elif isinstance(thing, PromoCampaign):
# PromoCampaigns store their dates as UTC, promote changes occur
# at 12 AM EST
# at UTC-5
promo_tz = pytz.timezone("US/Eastern")
start = (thing.start_date.replace(tzinfo=promo_tz)
.astimezone(pytz.utc))

View File

@@ -842,15 +842,18 @@ def sample_promoted_links(user, site, n=10):
return random.sample(promo_tuples, n)
def get_total_run(link):
"""Return the total time span this promotion has run for.
def get_total_run(thing):
"""Return the total time span this link or campaign will run.
Starts at the start date of the earliest campaign and goes to the end date
of the latest campaign.
"""
campaigns = PromoCampaign._by_link(link._id)
if isinstance(thing, Link):
campaigns = PromoCampaign._by_link(thing._id)
elif isinstance(thing, PromoCampaign):
campaigns = [thing]
earliest = None
latest = None