def get_total_run(thing):
 campaigns = []
 if isinstance(thing, Link):
  campaigns = PromoCampaign._by_link(thing._id)
 elif isinstance(thing, PromoCampaign):
  campaigns = [thing]
 else:
  campaigns = []
 earliest = None
 latest = None
 for campaign in campaigns:
  if (not charged_or_not_needed(campaign)):
   continue
  if ((not earliest) or (campaign.start_date < earliest)):
   earliest = campaign.start_date
  if ((not latest) or (campaign.end_date > latest)):
   latest = campaign.end_date
 if ((not earliest) or (not latest)):
  latest = datetime.datetime.utcnow()
  earliest = (latest - datetime.timedelta(days=30))
 earliest = (earliest.replace(tzinfo=g.tz) - timezone_offset)
 latest = (latest.replace(tzinfo=g.tz) - timezone_offset)
 return (earliest, latest)

def get_total_run ( thing ) : campaigns = [ ] if isinstance ( thing , Link ) : campaigns = PromoCampaign . _by_link ( thing . _id ) elif isinstance ( thing , PromoCampaign ) : campaigns = [ thing ] else : campaigns = [ ] earliest = None latest = None for campaign in campaigns : if ( not charged_or_not_needed ( campaign ) ) : continue if ( ( not earliest ) or ( campaign . start_date < earliest ) ) : earliest = campaign . start_date if ( ( not latest ) or ( campaign . end_date > latest ) ) : latest = campaign . end_date if ( ( not earliest ) or ( not latest ) ) : latest = datetime . datetime . utcnow ( ) earliest = ( latest - datetime . timedelta ( days = 30 ) ) earliest = ( earliest . replace ( tzinfo = g . tz ) - timezone_offset ) latest = ( latest . replace ( tzinfo = g . tz ) - timezone_offset ) return ( earliest , latest )
return the total time span this link or campaign will run .