disco pane download sources (bug 631668)

This commit is contained in:
Chris Van 2011-02-10 13:43:21 -05:00
Родитель c541c71337
Коммит 2ade344c4e
14 изменённых файлов: 246 добавлений и 20 удалений

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

@ -2,7 +2,7 @@
<div class="persona-inner">
<div class="persona-preview">
{% set tag = 'a' if linked else 'div' %}
{% with url = services_url('discovery.addons.detail', addon.slug)
{% with url = services_url('discovery.addons.detail', addon.slug, src='discovery-top')
if disco_link else addon.get_url_path() %}
<{{ tag }} {{ ('href="%s" ' % url)|safe if linked else '' }}
{% endwith %}

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

@ -69,10 +69,14 @@ def url(viewname, *args, **kwargs):
"""Helper for Django's ``reverse`` in templates."""
add_prefix = kwargs.pop('add_prefix', True)
host = kwargs.pop('host', '')
return '%s%s' % (host, urlresolvers.reverse(viewname,
args=args,
kwargs=kwargs,
add_prefix=add_prefix))
src = kwargs.pop('src', '')
url = '%s%s' % (host, urlresolvers.reverse(viewname,
args=args,
kwargs=kwargs,
add_prefix=add_prefix))
if src:
url = urlparams(url, src=src)
return url
@register.function

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

@ -154,6 +154,11 @@ def test_url(mock_reverse):
add_prefix=True)
def test_url_src():
s = render('{{ url("addons.detail", "a3615", src="xxx") }}')
assert s.endswith('?src=xxx')
def test_urlparams():
url = '/en-US/firefox/themes/category'
c = {'base': url,

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

@ -40,8 +40,8 @@ class UtilsTest(TestCase):
d = api.utils.addon_to_dict(a)
assert d['learnmore'].endswith('/addon/a3615/?src=api')
d = api.utils.addon_to_dict(a, disco=True)
u = settings.SERVICES_URL + reverse('discovery.addons.detail',
args=['a3615'])
u = '%s%s?src=discovery-personalrec' % (settings.SERVICES_URL,
reverse('discovery.addons.detail', args=['a3615']))
eq_(d['learnmore'], u)
@ -444,7 +444,12 @@ class ListTest(TestCase):
sorted_vals = sorted(vals, reverse=True)
eq_(vals, sorted_vals)
def test_featured_no_persona(self):
def test_adu_no_personas(self):
"""Verify that average daily users does not return Persona add-ons."""
response = make_call('list/by_adu')
self.assertNotContains(response, """<type id="9">Persona</type>""")
def test_featured_no_personas(self):
"""Verify that featured does not return Persona add-ons."""
response = make_call('list/featured')
self.assertNotContains(response, """<type id="9">Persona</type>""")

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

@ -15,6 +15,7 @@ def addon_to_dict(addon, disco=False):
if disco:
learnmore = settings.SERVICES_URL + reverse('discovery.addons.detail',
args=[addon.slug])
learnmore = urlparams(learnmore, src='discovery-personalrec')
else:
learnmore = url(addon.get_url_path(), src=src)

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

@ -257,6 +257,9 @@ class ListView(APIView):
qs = Addon.objects.listed(APP)
shuffle = True
if list_type in ('by_adu', 'featured'):
qs = qs.exclude(type=amo.ADDON_PERSONA)
if list_type == 'newest':
new = date.today() - timedelta(days=NEW_DAYS)
addons = (qs.filter(created__gte=new)
@ -265,8 +268,6 @@ class ListView(APIView):
addons = qs.order_by('-average_daily_users')[:limit + BUFFER]
shuffle = False # By_adu is an ordered list.
else:
if list_type == 'featured':
qs = qs.exclude(type=amo.ADDON_PERSONA)
addons = Addon.objects.featured(APP) & qs
args = (addon_type, limit, APP, platform, version, shuffle)

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

@ -0,0 +1,151 @@
[
{
"pk": 1,
"model": "discovery.discoverymodule",
"fields": {
"created": "2010-05-13 16:38:37",
"ordering": 2,
"app": 1,
"modified": "2010-09-14 16:35:11",
"module": "Rock Your Firefox",
"locales": "en-US"
}
},
{
"pk": 2,
"model": "discovery.discoverymodule",
"fields": {
"created": "2010-05-13 16:38:40",
"ordering": 3,
"app": 1,
"modified": "2010-09-14 16:35:37",
"module": "Shopping Collection",
"locales": ""
}
},
{
"pk": 3,
"model": "discovery.discoverymodule",
"fields": {
"created": "2010-05-13 16:38:41",
"ordering": null,
"app": 1,
"modified": "2010-09-14 16:35:11",
"module": "Webdev Collection",
"locales": ""
}
},
{
"pk": 5,
"model": "discovery.discoverymodule",
"fields": {
"created": "2010-09-14 16:34:54",
"ordering": 1,
"app": 1,
"modified": "2010-09-14 16:35:11",
"module": "Firefox Tester Tools",
"locales": ""
}
},
{
"pk": 10,
"model": "bandwagon.collection",
"fields": {
"rating": 566.80700000000002,
"downvotes": 58,
"uuid": "c37b85ec-f029-9ef1-1801-0e1ea52ca728",
"recommended_collection": null,
"author": 4757633,
"application": 1,
"listed": true,
"upvotes": 163,
"icontype": "image/png",
"type": 2,
"description": 394382,
"default_locale": "en-US",
"monthly_subscribers": 26,
"downloads": 468012,
"addon_index": "40e0f91e2ab3a5e666aedfbb6aca99ca",
"subscribers": 8609,
"nickname": "reference",
"slug": "reference",
"name": 394381,
"created": "2009-06-09 21:43:45",
"weekly_subscribers": 6,
"modified": "2010-10-01 14:06:19",
"addon_count": 5,
"all_personas": false
}
},
{
"pk": 16651,
"model": "bandwagon.collection",
"fields": {
"rating": 25434.900000000001,
"downvotes": 339,
"uuid": "c194cfdd-3be7-5724-27bf-d5571e12aa30",
"recommended_collection": null,
"author": 1023702,
"application": 1,
"listed": true,
"upvotes": 3428,
"icontype": "image/png",
"type": 0,
"description": 443766,
"default_locale": "en-US",
"monthly_subscribers": 195,
"downloads": 736229,
"addon_index": "a4dd4d4d92de179ede5aee586cbf1fbc",
"subscribers": 53767,
"nickname": "enkei",
"slug": "enkei",
"name": 443765,
"created": "2009-06-26 12:51:09",
"weekly_subscribers": 43,
"modified": "2010-10-05 04:39:06",
"addon_count": 11,
"all_personas": false
}
},
{
"pk": 82266,
"model": "bandwagon.collection",
"fields": {
"rating": 0.0,
"downvotes": 0,
"uuid": "9f471268-43f0-49db-9cac-14927c04c261",
"recommended_collection": null,
"author": 9945,
"application": 1,
"listed": true,
"upvotes": 1,
"icontype": "",
"type": 0,
"description": 1330518,
"default_locale": "en-US",
"monthly_subscribers": 6,
"downloads": 0,
"addon_index": "5bc6f1600288d91084eef30fffa6fa25",
"subscribers": 6,
"nickname": null,
"slug": "firefox-tester-tools",
"name": 1330517,
"created": "2010-09-14 12:06:10",
"weekly_subscribers": 1,
"modified": "2010-09-21 16:17:44",
"addon_count": 3,
"all_personas": false
}
},
{
"pk": 1,
"model": "discovery.blogcacheryf",
"fields": {
"permalink": "http://rockyourfirefox.com/2010/10/hyperwords/",
"excerpt": "Start by selecting any word on any webpage and search, share, translate, and much more in just a few clicks.",
"date_posted": "2010-10-04 18:22:05",
"image": "/uploads/2010/09/HighlightAWord-444x305.png",
"title": "Hyperwords"
}
}
]

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

@ -14,17 +14,17 @@
<ul id="install">
<li class="install-action">
{% if addon.has_eula %}
<a href="{{ url('discovery.addons.eula', addon.slug) }}"
<a href="{{ services_url('discovery.addons.eula', addon.slug) }}"
class="button eula go installer">
{# L10n: please keep &nbsp; in the string so the &rarr; does not wrap #}
{{ _('Continue to Download&nbsp;&rarr;')|safe }}</a>
{% else %}
{{ install_button(addon, show_contrib=False, show_warning=False) }}
{% endif %}</li>
<li><a href="{{ url('addons.detail', addon.slug)|urlparams(src=src) }}"
<li><a href="{{ url('addons.detail', addon.slug)|urlparams(src='discovery-learnmore') }}"
class="button">{{ _('Learn More') }}</a></li>
{% if addon.privacy_policy %}
<li><a href="{{ url('addons.privacy', addon.slug)|urlparams(src=src) }}">
<li><a href="{{ url('addons.privacy', addon.slug)|urlparams(src='discovery-learnmore') }}">
{{ _('View Privacy Policy') }}</a></li>
{% endif %}
</ul>

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

@ -23,7 +23,7 @@
{{ install_button(addon, version=version, show_contrib=False,
show_eula=False, show_warning=False) }}
</li>
<li><a href="{{ url('discovery.addons.detail', addon.slug) }}" class="button">
<li><a href="{{ services_url('discovery.addons.detail', addon.slug) }}" class="button">
{{ _('Cancel Installation') }}</a></li>
</ul>
{% endblock %}

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

@ -1,10 +1,11 @@
{% macro addon_list(list, limit=5, sidebar=False) %}
<ul>
{% set src = 'discovery-top' if sidebar else 'discovery-featured' %}
{# These are JSON add-ons from the API, not Addon objects. #}
{% for addon in list[:limit] %}
<li data-guid="{{ addon.guid }}" data-summary="{{ addon.summary }}">
{{ addon.type }}
<a href="{{ services_url('discovery.addons.detail', addon.id) }}"
<a href="{{ services_url('discovery.addons.detail', addon.id, src=src) }}"
target="_self" class="addon-title">
<img src="{{ addon.icon }}" width="32" height="32">
{% if sidebar %}

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

@ -4,7 +4,8 @@
<ul class="addons">
{% for addon in addons %}
<li>
<a href="{{ services_url('discovery.addons.detail', addon.slug) }}" target="_self">
<a href="{{ services_url('discovery.addons.detail', addon.slug)|
urlparams(src='discovery-promo') }}" target="_self">
<img src="{{ addon.icon_url }}" width="32" height="32">
<h3>{{ addon.name }}</h3>
<p class="desc">{{ addon.summary.localized_string|strip_html }}</p>
@ -12,7 +13,9 @@
</li>
{% endfor %}
</ul>
<p class="more">{% trans name=collection.name, url=collection.get_url_path() %}
<p class="more">
{% trans name=collection.name,
url=collection.get_url_path()|urlparams(src='discovery-promo') %}
Find more add-ons in the <a href="{{ url }}">{{ name }}</a> collection.
{% endtrans %}</p>
</div>

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

@ -4,6 +4,7 @@ from django import test
import mock
from nose.tools import eq_
from pyquery import PyQuery as pq
import test_utils
import amo
@ -18,7 +19,7 @@ from discovery.models import DiscoveryModule
from discovery.modules import registry
class RecsTest(test_utils.TestCase):
class TestRecs(test_utils.TestCase):
fixtures = ['base/apps', 'base/appversion', 'base/addon-recs',
'base/addon_5299_gcal', 'base/category', 'base/featured']
@ -205,3 +206,52 @@ class TestUrls(test_utils.TestCase):
follow=True)
url = reverse('discovery.pane', args=['4.0b8', 'Darwin'])
self.assertRedirects(r, url, 301)
class TestDownloadSources(test_utils.TestCase):
fixtures = ['base/apps', 'base/addon_3615', 'base/collections',
'base/featured', 'addons/featured',
'discovery/discoverymodules']
def setUp(self):
self.url = reverse('discovery.pane', args=['3.7a1pre', 'Darwin'])
def test_promo(self):
r = self.client.get(self.url)
doc = pq(r.content)
urls = doc('#main-feature .collection a[href$="?src=discovery-promo"]')
eq_(urls.length, 2)
def test_featured_addons(self):
r = self.client.get(self.url)
doc = pq(r.content)
urls = doc('#featured-addons li a[href$="?src=discovery-featured"]')
eq_(urls.length, 2)
def test_top_addons(self):
r = self.client.get(self.url)
doc = pq(r.content)
urls = doc('#top-addons li a[href$="?src=discovery-top"]')
eq_(urls.length, 3)
def test_featured_personas(self):
r = self.client.get(self.url)
doc = pq(r.content)
assert doc('#featured-personas li a').attr('href').endswith(
'?src=discovery-top')
def test_detail(self):
url = reverse('discovery.addons.detail', args=['a3615'])
r = self.client.get(url)
doc = pq(r.content)
assert doc('#install li:eq(1)').find('a').attr('href').endswith(
'?src=discovery-learnmore')
assert doc('#install li:eq(2)').find('a').attr('href').endswith(
'?src=discovery-learnmore')
def test_eula(self):
url = reverse('discovery.addons.eula', args=['a3615'])
r = self.client.get(url)
doc = pq(r.content)
assert doc('#install a.download').attr('href').endswith(
'?src=discovery-details')

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

@ -193,7 +193,7 @@ def addon_detail(request, addon):
return jingo.render(request, 'discovery/addons/detail.html',
{'addon': addon, 'reviews': reviews,
'get_replies': Review.get_replies,
'src': 'discovery-pane-details'})
'src': 'discovery-details'})
@addon_view
@ -206,4 +206,4 @@ def addon_eula(request, addon, file_id):
version = addon.current_version
return jingo.render(request, 'discovery/addons/eula.html',
{'addon': addon, 'version': version,
'src': 'discovery-pane-eula'})
'src': 'discovery-details'})

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

@ -0,0 +1,5 @@
DELETE FROM download_sources WHERE name
IN ('discovery-pane', 'discovery-pane-details', 'discovery-pane-eula');
INSERT INTO download_sources (name, type, created)
VALUES ('discovery-', 'prefix', NOW());