show weekly/monthly subscribers for collections search results (bug 733129)

This commit is contained in:
Chris Van 2012-03-05 17:41:35 -08:00
Родитель 74f4a1bd57
Коммит f9e2c5f561
5 изменённых файлов: 86 добавлений и 21 удалений

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

@ -13,11 +13,9 @@ from amo.urlresolvers import reverse
@register.inclusion_tag('bandwagon/collection_listing_items.html')
@jinja2.contextfunction
def collection_listing_items(context, collections, show_weekly=False,
show_date=None):
def collection_listing_items(context, collections, field=None):
c = dict(context.items())
c.update(collections=collections, show_weekly=show_weekly,
show_date=show_date)
c.update(collections=collections, field=field)
return c

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

@ -4,18 +4,41 @@
<ul>
<li>{{ barometer(c) }}</li>
<li class="followers">
{# L10n: People "follow" collections to get notified of updates.
Like Twitter followers. #}
{% trans cnt=c.subscribers, num=c.subscribers|numberfmt %}
<span>{{ num }}</span> follower
{% pluralize %}
<span>{{ num }}</span> followers
{% endtrans %}
{% if field == 'weekly' %}
{# L10n: People "follow" collections to get notified of updates.
Like Twitter followers. #}
{% trans cnt=c.weekly_subscribers, num=c.weekly_subscribers|numberfmt %}
{{ num }} weekly follower
{% pluralize %}
{{ num }} weekly followers
{% endtrans %}
{% elif field == 'monthly' %}
{# L10n: People "follow" collections to get notified of updates.
Like Twitter followers. #}
{% trans cnt=c.monthly_subscribers, num=c.monthly_subscribers|numberfmt %}
{{ num }} monthly follower
{% pluralize %}
{{ num }} monthly followers
{% endtrans %}
{% else %}
{# L10n: People "follow" collections to get notified of updates.
Like Twitter followers. #}
{% trans cnt=c.subscribers, num=c.subscribers|numberfmt %}
{{ num }} follower
{% pluralize %}
{{ num }} followers
{% endtrans %}
{% endif %}
</li>
{% if show_date in ['created', 'newest'] %}
{% if field in ('created', 'updated') %}
<li class="modified">
{# L10n: {0} is a date. #}
{{ _('Added {0}')|f(c.created|datetime) }}
{% if field == 'created' %}
{# L10n: {0} is a date. #}
{{ _('Added {0}')|f(c.created|datetime) }}
{% elif field == 'updated' %}
{# L10n: {0} is a date. #}
{{ _('Updated {0}')|f(c.modified|datetime) }}
{% endif %}
</li>
{% endif %}
</ul>

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

@ -28,7 +28,10 @@ collection_sort_by = (
('rating', _lazy(u'Highest Rated')),
('created', _lazy(u'Newest')),
)
es_collection_sort_by = collection_sort_by + (('name', _lazy(u'Name')),)
es_collection_sort_by = collection_sort_by + (
('updated', _lazy(u'Recently Updated')),
('name', _lazy(u'Name')),
)
per_page = (20, 50, )

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

@ -36,8 +36,7 @@
</div>
</form>
</div>
{{ collection_listing_items(pager.object_list,
show_date=opts.sort) }}
{{ collection_listing_items(pager.object_list, field=opts.sort) }}
</div>
<div class="listing-footer">{{ pager|paginator }}</div>
{% else %}

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

@ -6,10 +6,12 @@ from django.conf import settings
from django.http import QueryDict
from django.test import client
from jingo.helpers import datetime as datetime_filter
from mock import Mock, patch
from nose import SkipTest
from nose.tools import eq_
from pyquery import PyQuery as pq
from tower import strip_whitespace
import waffle
import amo
@ -166,9 +168,12 @@ class TestSearchboxTarget(amo.tests.ESTestCase):
class SearchBase(amo.tests.ESTestCase):
def get_results(self, r):
def get_results(self, r, sort=True):
"""Return pks of add-ons shown on search results page."""
return sorted(a.id for a in r.context['pager'].object_list)
results = [a.id for a in r.context['pager'].object_list]
if sort:
results = sorted(results)
return results
def check_sort_links(self, key, title=None, sort_by=None, reverse=True,
params={}):
@ -838,6 +843,10 @@ class TestCollectionSearch(SearchBase):
r = self.client.get(urlparams(self.url, sort='newest'))
self.assertRedirects(r, urlparams(self.url, sort='created'), 301)
def test_sort_order_unknown(self):
self._generate()
self.check_sort_links('xxx')
def test_sort_order_default(self):
self._generate()
self.check_sort_links(None, sort_by='weekly_subscribers')
@ -880,9 +889,42 @@ class TestCollectionSearch(SearchBase):
self._generate()
self.check_sort_links('updated', sort_by='modified')
def test_sort_order_unknown(self):
def test_created_timestamp(self):
self._generate()
self.check_sort_links('xxx')
r = self.client.get(urlparams(self.url, sort='created'))
items = pq(r.content)('.primary .item')
for idx, c in enumerate(r.context['pager'].object_list):
eq_(strip_whitespace(items.eq(idx).find('.modified').text()),
'Added %s' % strip_whitespace(datetime_filter(c.created)))
def test_updated_timestamp(self):
self._generate()
r = self.client.get(urlparams(self.url, sort='updated'))
items = pq(r.content)('.primary .item')
for idx, c in enumerate(r.context['pager'].object_list):
eq_(strip_whitespace(items.eq(idx).find('.modified').text()),
'Updated %s' % strip_whitespace(datetime_filter(c.modified)))
def check_followers_count(self, sort, column):
# Checks that we show the correct type/number of followers.
r = self.client.get(urlparams(self.url, sort=sort))
items = pq(r.content)('.primary .item')
for idx, c in enumerate(r.context['pager'].object_list):
eq_(items.eq(idx).find('.followers').text().split()[0],
numberfmt(getattr(c, column)))
def test_followers_all(self):
self._generate()
for sort in ('', 'all', 'rating', 'created', 'modified', 'name'):
self.check_followers_count(sort, column='subscribers')
def test_followers_monthly(self):
self._generate()
self.check_followers_count('monthly', column='monthly_subscribers')
def test_followers_weekly(self):
self._generate()
self.check_followers_count('weekly', column='weekly_subscribers')
def test_heading(self):
# One is a lonely number. But that's all we need.