allow subreddit moderators to see their subreddit's traffic. Allow sponsors to see traffic of promoted links.

This commit is contained in:
KeyserSosa
2009-04-16 15:41:15 -07:00
parent 486ed581a1
commit c139744886
5 changed files with 54 additions and 14 deletions

View File

@@ -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,

View File

@@ -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:

View File

@@ -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)

View File

@@ -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 @@
<th>date</th>
<th colspan="2">Impresions</th>
<th colspan="2">Clicks</th>
<th colspan="2">click-thru (%)</th>
</tr>
<tr>
<th></th>
@@ -41,15 +48,34 @@
<th>total</th>
<th>unique</th>
<th>total</th>
<th>unique</th>
<th>total</th>
</tr>
%for date, (uimp, nimp, ucli, ncli) in thing.traffic:
<tr>
<td>${date.strftime("%Y-%m-%d %H:%M")}</td>
<td>${uimp}</td>
<td>${nimp}</td>
<td>${ucli}</td>
<td>${ncli}</td>
<td>${num(uimp)}</td>
<td>${num(nimp)}</td>
<td>${num(ucli)}</td>
<td>${num(ncli)}</td>
<td>${("%.2f%%" % (float(100*ucli) / uimp)) if nimp else "--.--%"}</td>
<td>${("%.2f%%" % (float(100*ncli) / nimp)) if nimp else "--.--%"}</td>
</tr>
%endfor
%if thing.totals:
<%
uimp, nimp, ucli, ncli = thing.totals
%>
<tr style="font-weight:bold">
<td>total (users approx)</td>
<td>${num(uimp)}</td>
<td>${num(nimp)}</td>
<td>${num(ucli)}</td>
<td>${num(ncli)}</td>
<td>${("%.2f%%" % (float(100*ucli) / uimp)) if nimp else "--.--%"}</td>
<td>${("%.2f%%" % (float(100*ncli) / nimp)) if nimp else "--.--%"}</td>
</tr>
%endif
</table>
%endif

View File

@@ -110,16 +110,16 @@
<div style="float:left">
<div>
<img class="traffic-graph" alt='hourly uniques' style="float:right;"
<img class="traffic-graph" alt='hourly uniques'
src="${thing.uniques_hour}"/>
</div>
<div>
<img class="traffic-graph" alt='daily uniques' style="float:right;"
<img class="traffic-graph" alt='daily uniques'
src="${thing.uniques_day}"/>
</div>
%if c.default_sr:
<div>
<img class="traffic-graph" alt='monthly uniques' style="float:right;"
<img class="traffic-graph" alt='monthly uniques'
src="${thing.uniques_month}"/>
</div>
%endif