From 7c9d7930bbc72fc9071ec87d9184590e77b361cc Mon Sep 17 00:00:00 2001 From: Keith Mitchell Date: Mon, 7 Jan 2013 16:39:42 -0800 Subject: [PATCH] Promote_Graph: Move logic out of template --- r2/r2/lib/pages/pages.py | 42 ++++-- r2/r2/public/static/css/reddit.css | 37 +++-- r2/r2/templates/promote_graph.html | 218 +++++++++++++---------------- 3 files changed, 147 insertions(+), 150 deletions(-) diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index af322150e..dc7e2f21b 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -39,7 +39,7 @@ from pylons.i18n import _, ungettext from pylons import c, request, g from pylons.controllers.util import abort -from r2.lib import media +from r2.lib import media, inventory from r2.lib import promote, tracking from r2.lib.captcha import get_iden from r2.lib.filters import spaceCompress, _force_unicode, _force_utf8 @@ -3518,6 +3518,7 @@ class Promote_Graph(Templated): size = (end_date - start_date).days + self.dates = [start_date + datetime.timedelta(i) for i in xrange(size)] # these will be cached queries market, promo_counter = self.get_market(None, start_date, end_date) @@ -3589,13 +3590,38 @@ class Promote_Graph(Templated): self.promo_traffic = dict(self.promo_traffic) - Templated.__init__(self, - total_size = size, - market = market, - my_market = my_market, - promo_counter = promo_counter, - start_date = start_date, - promote_blocks = sorted_blocks) + self.cpc = {} + self.cpm = {} + self.delivered = {} + self.clicked = {} + self.my_market = {} + self.promo_counter = {} + + today = self.now.date() + for i in xrange(size): + day = start_date + datetime.timedelta(i) + cpc = cpm = delivered = clicks = "---" + if day in self.promo_traffic: + delivered, clicks = self.promo_traffic[day] + if i in market and day < today: + cpm = "$%.2f" % (market[i] * 1000. / max(delivered, 1)) + cpc = "$%.2f" % (market[i] * 1. / max(clicks, 1)) + delivered = format_number(delivered, c.locale) + clicks = format_number(clicks, c.locale) + if day == today: + delivered = "(%s)" % delivered + clicks = "(%s)" % clicks + self.cpc[day] = cpc + self.cpm[day] = cpm + self.delivered[day] = delivered + self.clicked[day] = clicks + if day in my_market: + self.my_market[day] = "$%.2f" % my_market[day] + else: + self.my_market[day] = "---" + self.promo_counter[day] = promo_counter.get(i, "---") + + Templated.__init__(self, today=today, promote_blocks=sorted_blocks) def to_iter(self, localize = True): locale = c.locale diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index bd262e26b..ef29c727b 100755 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -4616,41 +4616,40 @@ button.new-campaign:disabled { color: gray; } dt { margin-left: 10px; font-weight: bold; } dd { margin-left: 20px; } -.calendar { +table.calendar { white-space: nowrap; - overflow: hidden; - width: 100%; + overflow: hidden; + width: 90%; + margin-top: 20px; position: relative; - padding-top: 120px; - padding-bottom: 100px; - margin: 20px 0; + padding-top: 120px; + padding-bottom: 100px; + empty-cells: show; } -.calendar div.grid { - position: absolute; - top: 0px; - bottom: 0px; -} - -.calendar div.grid.today { +.calendar .today { background-color: yellow; } -.calendar div.grid div.header { - font-weight: bold; +.calendar thead tr { border-bottom: 2px solid gray; - text-align: center; } -.calendar div.grid + div.grid { - border-left: 1px dashed gray; +.calendar thead th, .calendar thead td { + font-weight: bold; + text-align: center; + min-width: 125px; +} + +.calendar td, .calendar th[scope="col"] { + border-left: 1px dashed gray; + min-width: 125px; } .calendar .blob { margin: 0; padding: 0px; z-index: 10; - float: left; cursor: pointer; } diff --git a/r2/r2/templates/promote_graph.html b/r2/r2/templates/promote_graph.html index fd221fb51..b6229a7cb 100644 --- a/r2/r2/templates/promote_graph.html +++ b/r2/r2/templates/promote_graph.html @@ -21,26 +21,15 @@ ############################################################################### <%! - from r2.lib.template_helpers import static, format_number - from r2.lib import js - import datetime - from r2.lib import promote - import babel.numbers - - locale = c.locale - - def num(x): - return format_number(x, locale) - def money(x): - return babel.numbers.format_currency(x, 'USD', locale) - %> + from r2.lib.template_helpers import static +%> <%namespace file="reddittraffic.html" import="load_timeseries_js"/> ${load_timeseries_js()}

${_("Sponsored link calendar")}

-%if not c.user_is_sponsor: +%if not thing.admin_view:

Below is a calendar of your scheduled and completed promotions (if you have any, of course), along with some site-wide averages to use as a guide for setting up future promotions. These values are:

@@ -57,117 +46,100 @@ ${load_timeseries_js()} %endif -<% max_percent = 97. %> + + + + + %for date in thing.dates: + + %endfor + + + + %for date in thing.dates: + + %endfor + + + + %for date in thing.dates: + + %endfor + + + + %for date in thing.dates: + + %endfor + + + + %for date in thing.dates: + + %endfor + + -
- <% - today = thing.now.date() - %> -
-
- DATE -
-
- COUNT -
-
- %if c.user_is_sponsor: - IMPRESSIONS
- %endif - CPM -
-
- %if c.user_is_sponsor: - CLICKS
- %endif - CPC -
-
- %if c.user_is_sponsor: - TOTAL COMMIT - %else: - YOUR COMMIT - %endif -
-
- %for i in xrange(thing.total_size): - <% - left = "%.2f" % (max_percent*float(i+1)/(thing.total_size+1)) - right = "%.2f" % (100 - max_percent*float(i+2)/(thing.total_size+1)) - day = thing.start_date + datetime.timedelta(i) - CPC = CPM = imp_traffic = cli_traffic = "---" - if thing.promo_traffic.has_key(day): - imp_traffic, cli_traffic = thing.promo_traffic[day] - if thing.market.has_key(i) and day < today: - CPM = "$%.2f" % (thing.market[i] * 1000./max(imp_traffic, 1)) - CPC = "$%.2f" % (thing.market[i] * 1./max(cli_traffic, 1)) - imp_traffic = num(imp_traffic) - cli_traffic = num(cli_traffic) - if day == today: - imp_traffic = "(%s)" % imp_traffic - cli_traffic = "(%s)" % cli_traffic - %> -
-
- ${day} -
-
- ${thing.promo_counter.get(i, unsafe(" "))} -
-
- %if c.user_is_sponsor: - ${imp_traffic}
- %endif - ${CPM} -
-
- %if c.user_is_sponsor: - ${cli_traffic}
- %endif - ${CPC} -
-
- ${"$%.2f" % thing.my_market[i] if thing.my_market.has_key(i) else "---"} -
-
- %endfor +
+ %for link, start, end, campaign in thing.promote_blocks: + + + %for i in xrange(start): + + %endfor + + %for i in xrange(end, len(thing.dates)): + + %endfor + + %endfor + +
${_("DATE")} + +
${_("COUNT")} + ${thing.promo_counter[date]} +
+ %if thing.admin_view: + ${_("DELIVERED IMPRESSIONS")}
+ %endif + ${_("CPM")} +
+ ${thing.delivered[date]}
+ ${thing.cpm[date]} +
+ %if thing.admin_view: + ${_("CLICKS")}
+ %endif + ${_("CPC")} +
+ %if thing.admin_view: + ${thing.clicked[date]}
+ %endif + ${thing.cpc[date]} +
+ %if c.user_is_sponsor: + ${_("TOTAL COMMIT")} + %else: + ${_("YOUR COMMIT")} + %endif + + ${thing.my_market[date]} +
+ +
-<% - prev_end = 0 - %> -%for link, start, end, campaign in thing.promote_blocks: - <% - start += 1 - end += 1 - sr = campaign.sr_name + ':' if campaign.sr_name else '' - %> - %if start != end: - %if prev_end > start: - <% prev_end = 0 %> -
- %endif - <% - margin = "%.2f" % (float(max_percent*(start-prev_end))/(thing.total_size+1)) - width = "%.2f" % (float(max_percent*(end-start))/(thing.total_size+1)) - prev_end = end - %> - - %endif -%endfor -

${_("historical site performance")}