starting the homepage: global stats

This commit is contained in:
Jeff Balogh 2010-02-26 17:43:48 -08:00
Родитель 99000a6b74
Коммит b9ac53ca48
8 изменённых файлов: 50 добавлений и 19 удалений

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

@ -0,0 +1,20 @@
{% extends "base_side_categories.html" %}
{% block site_stats %}
<ul class="stats">
{% set dl_text = ngettext('<strong>{0}</strong> <span>add-on downloaded</span>',
'<strong>{0}</strong> <span>add-ons downloaded</span>',
downloads.count) %}
{% set ping_text = ngettext('<strong>{0}</strong> <span>add-on in use</span>',
'<strong>{0}</strong> <span>add-ons in use</span>',
pings.count) %}
<li>
<a href="{{ url('statistics.dashboard') }}">
{{ dl_text|f(downloads.count|numberfmt)|safe }}</a>
</li>
<li>
<a href="{{ url('statistics.dashboard') }}">
{{ ping_text|f(pings.count|numberfmt)|safe }}</a>
</li>
</ul>
{% endblock %}

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

@ -13,6 +13,9 @@ detail_patterns = patterns('',
urlpatterns = patterns('',
# The homepage.
url('^$', views.home, name='home'),
# URLs for a single add-on.
('^addon/(?P<addon_id>\d+)/', include(detail_patterns)),
)

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

@ -1,6 +1,19 @@
from django import http
import jingo
from stats.models import GlobalStat
# pylint: disable-msg: W0613
def addon_detail(request, addon_id):
return http.HttpResponse('this is addon %s' % addon_id)
def home(request):
gs = GlobalStat.objects
downloads = gs.filter(name='addon_total_downloads').latest()
pings = gs.filter(name='addon_total_updatepings').latest()
return jingo.render(request, 'addons/home.html',
{'downloads': downloads, 'pings': pings})

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

@ -4,7 +4,7 @@ from django import test
class TestRedirects(test.TestCase):
fixtures = ['amo/test_redirects']
fixtures = ['amo/test_redirects', 'base/global-stats']
def test_reviews(self):
response = self.client.get('/reviews/display/4', follow=True)

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

@ -14,20 +14,8 @@ def test_404_no_app():
eq_(response.status_code, 404)
def test_heading():
c = test.Client()
def title_eq(url, expected):
response = c.get(url, follow=True)
actual = PyQuery(response.content)('#title').text()
eq_(expected, actual)
title_eq('/firefox', 'Add-ons for Firefox')
title_eq('/thunderbird', 'Add-ons for Thunderbird')
title_eq('/mobile', 'Mobile Add-ons for Firefox')
class TestStuff(test_utils.TestCase):
fixtures = ['base/addons']
fixtures = ['base/addons', 'base/global-stats']
def test_data_anonymous(self):
def check(expected):
@ -50,3 +38,13 @@ class TestStuff(test_utils.TestCase):
check(0)
self.client.login(username='admin@mozilla.com', password='password')
check(1)
def test_heading(self):
def title_eq(url, expected):
response = self.client.get(url, follow=True)
actual = PyQuery(response.content)('#title').text()
eq_(expected, actual)
title_eq('/firefox', 'Add-ons for Firefox')
title_eq('/thunderbird', 'Add-ons for Thunderbird')
title_eq('/mobile', 'Mobile Add-ons for Firefox')

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

@ -9,7 +9,7 @@ from cake.backends import SessionBackend
class CakeTestCase(TestCase):
fixtures = ['cake/sessions.json']
fixtures = ['cake/sessions.json', 'base/global-stats']
def test_login(self):
"""

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

@ -34,7 +34,7 @@
<a href="http://www.mozilla.com/" title="{{ _('Mozilla') }}"
accesskey="1">{{ _('Mozilla') }}</a>
</p>
{% block site_stats %}{% endblock %}
<div id="aux-nav" role="navigation">
<ul id="other-apps" class="change"
title="{{ _('Find add-ons for other applications') }}">

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

@ -9,9 +9,6 @@ handler404 = 'amo.views.handler404'
handler500 = 'amo.views.handler500'
urlpatterns = patterns('',
url('^$', 'jingo.views.direct_to_template',
{'template': 'base.html'}, name='home'),
# Add-ons.
('', include('addons.urls')),