zamboni version of collection stats (bug 722558)

This commit is contained in:
Davor Spasovski 2012-03-01 17:29:09 -08:00
Родитель 17197a2985
Коммит 064a3479e6
10 изменённых файлов: 70 добавлений и 22 удалений

Просмотреть файл

@ -233,6 +233,10 @@ class Collection(CollectionBase, amo.models.ModelBase):
return reverse('collections.detail.rss',
args=[self.author_username, self.slug])
def stats_url(self):
return reverse('collections.stats',
args=[self.author_username, self.slug])
@property
def author_username(self):
return self.author.username if self.author else 'anonymous'

Просмотреть файл

@ -12,7 +12,14 @@
<a title="{{ _('Copy this Collection') }}" class="copy" href="#"></a>
#}
{% if request.check_ownership(c, require_owner=False) and condensed %}
<a title="{{ _('Edit this Collection') }}" class="widget edit tooltip" href="{{ c.edit_url() }}"></a>
<a title="{{ _('Edit this Collection') }}"
class="widget edit tooltip condensed" href="{{ c.edit_url() }}"></a>
{% endif %}
{% if waffle.switch('collection-stats') %}
<a href="{{ c.stats_url() }}" title="{{ _('Statistics') }}"
class="widget stats{{ ' tooltip' if condensed }}">
{{ _('Statistics') if not condensed }}
</a>
{% endif %}
{% endif %}
</div>

Просмотреть файл

@ -1,6 +1,7 @@
from django.conf.urls.defaults import patterns, url, include
from . import views, feeds
from stats.views import collection_stats
edit_urls = patterns('',
url('^$', views.edit, name='collections.edit'),
@ -25,6 +26,7 @@ detail_urls = patterns('',
url('^share$', views.share, name='collections.share'),
url('^format:rss$', feeds.CollectionDetailFeed(),
name='collections.detail.rss'),
url('^statistics', collection_stats, name='collections.stats'),
)
ajax_urls = patterns('',

Просмотреть файл

@ -4,6 +4,7 @@ from jingo import env, register
from tower import ugettext as _
from access import acl
from addons.models import Addon
from bandwagon.models import Collection
from amo.urlresolvers import reverse
@ -24,6 +25,12 @@ def report_menu(context, request, report, obj=None):
'has_privs': has_privs
}
return jinja2.Markup(t.render(c))
if isinstance(obj, Collection):
t = env.get_template('stats/collection_report_menu.html')
c = {
'collection': obj,
}
return jinja2.Markup(t.render(c))
t = env.get_template('stats/global_report_menu.html')
return jinja2.Markup(t.render())

Просмотреть файл

@ -0,0 +1,17 @@
<nav id="side-nav" class="report-menu">
<ul>
<li data-report="overview" data-layout="overview">
<a href="#">
{{ _('Subscribers') }}
</a>
</li>
<li data-report="downloads">
<a href="#">{{ _('Ratings') }}</a>
</li>
<li data-report="sources">
<a href="#">
{{ _('Downloads') }}
</a>
</li>
</ul>
</nav>

Просмотреть файл

@ -0,0 +1,9 @@
{% extends "stats/stats.html" %}
{# extends "impala/base_shared.html" #}
{% set page_name = _('Statistics for {0}')|f(collection.name) %}
{% block title %}
{{ page_name }}
{% endblock %}
{% block content %}
<h1>{{ page_name }}</h1>
{% endblock %}

Просмотреть файл

@ -460,27 +460,13 @@ def site(request, format, group, start=None, end=None):
return render_json(request, None, series)
def collection(request, uuid, format):
"""
Collection data taken from the stats_collections and the
stats_addons_collections_counts table.
"""
collection = get_object_or_404(Collection, uuid=uuid)
if (not acl.action_allowed(request, 'Admin', 'ViewAnyCollectionStats') and
not (request.amo_user and collection.author and
collection.author.id == request.amo_user.pk)):
return http.HttpResponseForbidden()
start = date.today() - timedelta(days=365)
end = date.today()
series = get_series(CollectionCount, id=int(collection.pk),
date__range=(start, end), extra_field='data')
if format == 'csv':
series, fields = csv_fields(series)
return render_csv(request, collection, series,
['date', 'count'] + list(fields))
return render_json(request, collection, series)
def collection_stats(request, username, slug):
c = {'name': 'Sample Collection'}
view = get_report_view(request)
return jingo.render(request, 'stats/collections.html',
{'collection': c,
'view': view,
})
def fudge_headers(response, stats):

Просмотреть файл

@ -466,6 +466,7 @@ MINIFY_BUNDLES = {
'css/impala/moz-tab.css',
'css/impala/footer.less',
'css/impala/faux-zamboni.less',
'css/impala/collection-stats.less',
),
'zamboni/impala': (
'css/impala/base.css',

Просмотреть файл

@ -0,0 +1,12 @@
@import 'lib';
.widgets {
.stats {
background: url("../../img/impala/stats.png") no-repeat left top;
padding-left: 20px;
margin: 0;
&:hover {
background-position: left -20px;
}
}
}

Просмотреть файл

@ -0,0 +1,3 @@
INSERT INTO waffle_switch_amo (name, active, note)
VALUES ('collection-stats', 0,
'This enables the collections stats pages.');