diff --git a/r2/r2/controllers/front.py b/r2/r2/controllers/front.py index 342712f48..4abd05c0f 100644 --- a/r2/r2/controllers/front.py +++ b/r2/r2/controllers/front.py @@ -290,7 +290,7 @@ class FrontController(RedditController): # listing = LinkListing(builder) # pane = listing.listing() pane = InfoBar(message = "There doesn't seem to be anything here.") - elif c.user_is_admin and location == 'traffic': + elif is_moderator and location == 'traffic': pane = RedditTraffic() else: return self.abort404() @@ -599,7 +599,7 @@ class FrontController(RedditController): return self.abort404() - @validate(VAdmin(), + @validate(VSponsor(), article = VLink('article')) def GET_traffic(self, article): res = LinkInfoPage(link = article, diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index ae539b9c8..0e8ee7a33 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -270,7 +270,6 @@ class SubredditInfoBar(Wrapped): buttons.append(NamedButton('edit')) buttons.extend([NavButton(menu.banusers, 'banned'), NamedButton('spam')]) - if c.user_is_admin: buttons.append(NamedButton('traffic')) return [NavMenu(buttons, type = "flatlist", base_path = "/about/")] @@ -457,6 +456,7 @@ class LinkInfoPage(Reddit): if c.user_is_admin: buttons += [info_button('details')] + if c.user_is_sponsor: if self.link.promoted is not None: buttons += [info_button('traffic')] @@ -1245,6 +1245,12 @@ class PromotedTraffic(Traffic): self.traffic = load_traffic('hour', "thing", thing._fullname, start_time = d, stop_time = until) + self.totals = load_traffic('month', "thing", thing._fullname) + if not self.totals: + self.totals = load_traffic('day', "thing", thing._fullname) + if self.totals: + self.totals = map(sum, zip(*zip(*self.totals)[1])) + imp = self.slice_traffic(self.traffic, 0, 1) if len(imp) > 2: diff --git a/r2/r2/lib/traffic.py b/r2/r2/lib/traffic.py index df9a64055..873093654 100644 --- a/r2/r2/lib/traffic.py +++ b/r2/r2/lib/traffic.py @@ -23,7 +23,7 @@ from httplib import HTTPConnection from urlparse import urlparse from cPickle import loads from utils import query_string -import os, socket +import os, socket, time, datetime from pylons import g from r2.lib.memoize import memoize, clear_memo @@ -64,9 +64,17 @@ def load_traffic_uncached(interval, what, iden, def load_traffic(interval, what, iden, start_time = None, stop_time = None, npoints = None): - return load_traffic_uncached(interval, what, iden, - start_time = start_time, stop_time = stop_time, - npoints = npoints) + res = load_traffic_uncached(interval, what, iden, + start_time = start_time, stop_time = stop_time, + npoints = npoints) + + if res and isinstance(res[0][0], datetime.datetime): + res = zip(*res) + res[0] = [x.replace(tzinfo=None) - datetime.timedelta(0, time.timezone) + for x in res[0]] + res = zip(*res) + return res + def load_summary(what, interval = "month", npoints = 50): return load_traffic(interval, "summary", what, npoints = npoints) diff --git a/r2/r2/templates/promotedtraffic.html b/r2/r2/templates/promotedtraffic.html index 1c4958555..79fdfabe4 100644 --- a/r2/r2/templates/promotedtraffic.html +++ b/r2/r2/templates/promotedtraffic.html @@ -19,6 +19,12 @@ ## All portions of the code written by CondeNet are Copyright (c) 2006-2009 ## CondeNet, Inc. All Rights Reserved. ################################################################################ +<%! + import locale + from r2.models.subreddit import DomainSR, FakeSubreddit + def num(x): + return locale.format('%d', x, True) + %> %if thing.traffic: %if thing.imp_graph: @@ -34,6 +40,7 @@