Revert "lazy-load discovery promo modules (bug 719305)"

This reverts commit 12f7b0fa1c.

Conflicts:

	apps/discovery/templates/discovery/pane.html
	apps/discovery/tests/test_views.py
	media/js/impala/promos.js
	media/js/zamboni/discovery_pane.js
This commit is contained in:
Chris Van 2012-01-26 15:34:40 -08:00
Родитель 0fca05bfdf
Коммит 37f665cd37
8 изменённых файлов: 80 добавлений и 121 удалений

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

@ -388,10 +388,9 @@ def home(request):
def homepage_promos(request):
from discovery.views import get_modules
platform, version = request.GET.get('platform'), request.GET.get('version')
if not (platform or version):
raise http.Http404
platform = amo.PLATFORM_DICT.get(version.lower(), amo.PLATFORM_ALL)
platform = amo.PLATFORM_DICT.get(request.GET.get('platform'),
amo.PLATFORM_ALL)
version = request.GET.get('version')
modules = get_modules(request, platform.api_name, version)
module_context = request.GET.get('context', 'home')
return jingo.render(request, 'addons/impala/homepage_promos.html',
@ -674,8 +673,7 @@ def contribute(request, addon):
amount = {
'suggested': addon.suggested_amount,
'onetime': request.POST.get('onetime-amount', '')
}.get(contrib_type, '')
'onetime': request.POST.get('onetime-amount', '')}.get(contrib_type, '')
if not amount:
amount = settings.DEFAULT_SUGGESTED_CONTRIBUTION

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

@ -6,8 +6,6 @@
{% block bodyclass %}pane no-recs{% endblock %}
{% block bodyattrs %}
data-version="{{ version }}"
data-platform="{{ platform }}"
data-services-url="{{ settings.SERVICES_URL }}"
data-recs-url="{{ services_url('discovery.recs', version, platform) }}"
data-account-url="{{ services_url('discovery.pane.account') }}"
@ -40,23 +38,25 @@ data-upandcoming-url="{{ services_url('discovery.pane.more_addons', 'up-and-comi
<section id="main">
<section id="promos" data-promo-url="{{ static(url('addons.homepage_promos')) }}">
{% if modules %}
{# TODO: Lazy-load promo modules. #}
<section id="promos">
<ul id="nav-features">
<li class="nav-prev"><a href="#" class="prev">{{ _('Previous') }}</a></li>
<li class="nav-next"><a href="#" class="next">{{ _('Next') }}</a></li>
</ul>
<ul class="slider">
{% for module in modules %}{{ module.render() }}{% endfor %}
</ul>
</section>
{% endif %}
{% if featured_addons %}
<section id="featured-addons">
<h2 class="translate" data-trans="featured">{{ _('Featured Add-ons') }}</h2>
<div class="addons">
{{ addon_list(featured_addons, limit=6) }}
</div>
</section>
{% endif %}
<section id="recs">
<div class="header">

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

@ -1,6 +1,7 @@
import json
from django import test
from django.conf import settings
from django.core.cache import cache
import mock
@ -176,6 +177,7 @@ class TestRecs(amo.tests.TestCase):
eq_(one['token2'], two['token2'])
# assert one['recommendations'] != two['recommendations']
assert one['addons'] != two['addons']
eq_(CollectionToken.objects.count(), 1)
eq_(len(Collection.objects.filter(type=amo.COLLECTION_SYNCHRONIZED)),
2)
@ -254,41 +256,16 @@ class TestPromos(amo.tests.TestCase):
fixtures = ['discovery/discoverymodules']
def setUp(self):
self.url = reverse('addons.homepage_promos')
self.url = reverse('discovery.pane', args=['3.7a1pre', 'Darwin'])
def test_no_params(self):
def test_promos_visible(self):
r = self.client.get(self.url)
eq_(r.status_code, 404)
eq_(pq(r.content)('#promos').length, 1)
def test_mac(self):
r_mac = self.client.get(self.url,
{'version': '5.0', 'platform': 'mac'})
r_darwin = self.client.get(self.url,
{'version': '5.0', 'platform': 'Darwin'})
eq_(r_mac.status_code, 200)
eq_(r_darwin.status_code, 200)
eq_(r_mac.content, r_darwin.content)
panels = pq(r_mac.content)('.panel')
eq_(panels.length, 1)
eq_(panels.find('.ryff').length, 1)
def test_win(self):
r_win = self.client.get(self.url,
{'version': '5.0', 'platform': 'win'})
r_winnt = self.client.get(self.url,
{'version': '5.0', 'platform': 'WINNT'})
eq_(r_win.status_code, 200)
eq_(r_winnt.status_code, 200)
eq_(r_win.content, r_winnt.content)
panels = pq(r_win.content)('.panel')
eq_(panels.length, 1)
eq_(panels.find('.ryff').length, 1)
def test_hidden(self):
def test_promos_hidden(self):
DiscoveryModule.objects.all().delete()
r = self.client.get(self.url, {'version': '5.0', 'platform': 'mac'})
eq_(r.status_code, 200)
eq_(r.content, '')
r = self.client.get(self.url)
eq_(pq(r.content)('#promos').length, 0)
class TestPane(amo.tests.TestCase):
@ -489,9 +466,7 @@ class TestMonthlyPick(amo.tests.TestCase):
fixtures = ['base/apps', 'base/addon_3615', 'discovery/discoverymodules']
def setUp(self):
self.url = reverse('addons.homepage_promos')
self.vars = {'version': '5.0', 'platform': 'mac',
'context': 'discovery'}
self.url = reverse('discovery.pane', args=['3.7a1pre', 'Darwin'])
self.addon = Addon.objects.get(id=3615)
DiscoveryModule.objects.create(
app=Application.objects.get(id=amo.FIREFOX.id), ordering=4,
@ -500,11 +475,10 @@ class TestMonthlyPick(amo.tests.TestCase):
def test_monthlypick(self):
mp = MonthlyPick.objects.create(addon=self.addon, blurb='BOOP',
image='http://mozilla.com')
r = self.client.get(self.url, self.vars)
r = self.client.get(self.url)
eq_(pq(r.content)('#monthly').length, 0)
mp.update(locale='')
r = self.client.get(self.url, self.vars)
r = self.client.get(self.url)
pick = pq(r.content)('#monthly')
eq_(pick.length, 1)
a = pick.find('h3 a')
@ -519,22 +493,22 @@ class TestMonthlyPick(amo.tests.TestCase):
.endswith('?src=discovery-promo'), True)
def test_monthlypick_no_image(self):
MonthlyPick.objects.create(addon=self.addon, blurb='BOOP', locale='',
image='')
mp = MonthlyPick.objects.create(addon=self.addon, blurb='BOOP',
locale='', image='')
# Tests for no image when screenshot not set.
r = self.client.get(self.url, self.vars)
r = self.client.get(self.url)
pick = pq(r.content)('#monthly')
eq_(pick.length, 1)
eq_(pick.find('img').length, 0)
# Tests for screenshot image when set.
Preview.objects.create(addon=self.addon)
r = self.client.get(self.url, self.vars)
p = Preview.objects.create(addon=self.addon)
r = self.client.get(self.url)
pick = pq(r.content)('#monthly')
eq_(pick.length, 1)
eq_(pick.find('img').attr('src'), self.addon.all_previews[0].image_url)
def test_no_monthlypick(self):
r = self.client.get(self.url, self.vars)
r = self.client.get(self.url)
eq_(pq(r.content)('#monthly').length, 0)

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

@ -48,7 +48,8 @@ def pane(request, version, platform, compat_mode='strict'):
promovideo = PromoVideoCollection().get_items()
return jingo.render(request, 'discovery/pane.html',
{'up_and_coming': from_api('hotness'),
{'modules': get_modules(request, platform, version),
'up_and_coming': from_api('hotness'),
'featured_addons': from_api('featured'),
'featured_personas': get_featured_personas(request),
'version': version, 'platform': platform,

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

@ -1,23 +1,46 @@
(function () {
$('.toplist .name').truncate({showTitle: true});
initPromos();
$(document).bind('promos_shown', function(e, $promos) {
$promos.slideDown('slow')
.append('<a href="#" class="control prev">&laquo;</a>\
})();
function initPromos($context) {
if (typeof $context === 'undefined') {
$context = $(document.body);
}
var $promos = $('#promos[data-promo-url]', $context);
if (!$promos.length) {
return;
}
var promos_base = $promos.attr('data-promo-url'),
promos_url = format('{0}?version={1}&platform={2}',
promos_base, z.browserVersion, z.platform);
if (z.badBrowser) {
promos_url = format('{0}?version={1}&platform={2}',
promos_base, '5.0', 'mac');
}
$.get(promos_url, function(resp) {
$('ul', $promos).append($(resp));
hideHomePromo();
$promos.append('<a href="#" class="control prev">&laquo;</a>\
<a href="#" class="control next">&raquo;</a>');
$('div', $promos).zCarousel({
circular: true,
btnPrev: $('.prev', $promos),
btnNext: $('.next', $promos)
});
var $panels = $('.panel', $promos);
if ($panels.length) {
// Show promo module only if we have at least panel.
$promos.show();
$('div', $promos).zCarousel({
circular: true,
btnPrev: $('.prev', $promos),
btnNext: $('.next', $promos)
});
}
$('.addons h3', $promos).truncate({dir: 'h'});
$('.addons .desc', $promos).truncate({dir: 'v'});
$('.install', $promos).installButton();
$('#monthly .blurb > p').lineclamp(4);
$('h2', $promos).linefit();
});
})();
$('.toplist .name').truncate({showTitle: true});
}
function hideHomePromo($context) {

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

@ -1,31 +0,0 @@
function initPromos($context, version, platform, context) {
if (typeof $context === 'undefined') {
$context = $(document.body);
}
var $promos = $('#promos[data-promo-url]', $context);
if (!$promos.length) {
return;
}
var promos_base = $promos.attr('data-promo-url');
if (!version) {
version = z.browserVersion;
}
if (!platform) {
platform = z.platform;
}
if (z.badBrowser && !version && !platform) {
version = '5.0';
platform = 'mac';
}
var data = {version: version, platform: platform};
if (context) {
data['context'] = context;
}
$.get(promos_base, data, function(resp) {
$('.slider', $promos).append($(resp));
if ($('.panel', $promos).length) {
// Show promo module only if we have at least panel.
$promos.trigger('promos_shown', [$promos]);
}
});
}

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

@ -16,32 +16,30 @@ z.discoStorage = z.Storage("discopane");
$(document).ready(function(){
if (!$('.pane').length) {
return;
}
if ($(".pane").length) {
initSidebar();
initSidebar();
// Store the pane URL so we can link back from the add-on detail pages.
z.discoStorage.set('url', location);
hideInstalled();
initRecs();
// Store the pane URL so we can link back from the add-on detail pages.
z.discoStorage.set("url", location);
var $body = $(document.body);
initPromos($body, $body.attr('data-version'), $body.attr('data-platform'),
'discovery');
$(this).bind('promos_shown', function(e, $promos) {
// Show "Starter Pack" panel only if user has fewer than 3 extensions.
hideInstalled();
// Show "Starter Pack" panel only if user has fewer than three extensions.
if (z.has_addons) {
$('#starter').closest('.panel').remove();
$("#starter").closest(".panel").remove();
}
initRecs();
// Set up the promo carousel.
$promos.fadeIn('slow').addClass('js').zCarousel({
btnNext: '#promos .nav-next a',
btnPrev: '#promos .nav-prev a',
$("#promos").fadeIn("slow").addClass("js").zCarousel({
btnNext: "#promos .nav-next a",
btnPrev: "#promos .nav-prev a",
circular: true
});
initTrunc();
});
}
});

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

@ -112,8 +112,8 @@ AMO_LANGUAGES = (
'uk', 'vi', 'zh-CN', 'zh-TW',
)
# Not shown on the site, but .po files exist and these are available on the
# L10n dashboard. Generally languages start here and move into AMO_LANGUAGES.
# Not shown on the site, but .po files exist and these are available on the L10n
# dashboard. Generally languages start here and move into AMO_LANGUAGES.
HIDDEN_LANGUAGES = ('cy', 'sr', 'sr-Latn', 'tr')
@ -588,7 +588,6 @@ MINIFY_BUNDLES = {
'js/zamboni/debouncer.js',
# Homepage
'js/impala/promos.js',
'js/zamboni/homepage.js',
# Add-ons details page
@ -672,7 +671,6 @@ MINIFY_BUNDLES = {
'js/impala/forms.js',
# Homepage
'js/impala/promos.js',
'js/impala/homepage.js',
# Add-ons details page
@ -741,8 +739,6 @@ MINIFY_BUNDLES = {
'js/zamboni/debouncer.js',
'js/zamboni/truncation.js',
'js/impala/promos.js',
'js/zamboni/discovery_addons.js',
'js/zamboni/discovery_pane.js',
),