From 97caffc934cdabbe4ef5f898926caba04b5215a6 Mon Sep 17 00:00:00 2001 From: bsimpson63 Date: Thu, 25 Apr 2013 10:17:54 -0400 Subject: [PATCH] Take PromoCampaigns as inputs in promote.get_total_run. --- r2/r2/lib/pages/trafficpages.py | 2 +- r2/r2/lib/promote.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/r2/r2/lib/pages/trafficpages.py b/r2/r2/lib/pages/trafficpages.py index a52f4d1fa..2af363833 100644 --- a/r2/r2/lib/pages/trafficpages.py +++ b/r2/r2/lib/pages/trafficpages.py @@ -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)) diff --git a/r2/r2/lib/promote.py b/r2/r2/lib/promote.py index 1ac41fe72..b9d7bde84 100644 --- a/r2/r2/lib/promote.py +++ b/r2/r2/lib/promote.py @@ -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