Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
do not show adu on apps search - desktop (bug 702408)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvan committed Nov 18, 2011
1 parent 38ae137 commit 4f9a0df
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 41 deletions.
3 changes: 3 additions & 0 deletions apps/addons/models.py
Expand Up @@ -689,6 +689,9 @@ def transformer(addons):
def show_beta(self):
return self.status == amo.STATUS_PUBLIC and self.current_beta_version

def show_adu(self):
return self.type not in (amo.ADDON_SEARCH, amo.ADDON_WEBAPP)

@amo.cached_property
def current_beta_version(self):
"""Retrieves the latest version of an addon, in the beta channel."""
Expand Down
16 changes: 8 additions & 8 deletions apps/addons/templates/addons/impala/details.html
Expand Up @@ -26,14 +26,7 @@
{% endtrans %}
</a></div>

{% if addon.is_webapp() %}
{% set dls = addon.weekly_downloads %}
{% if dls %}
<div id="weekly-downloads">
{{ _('{0} weekly downloads')|f(dls|numberfmt) }}
</div>
{% endif %}
{% else %}
{% if addon.show_adu() %}
{% set adu = addon.average_daily_users %}
{% if adu %}
<div id="daily-users">
Expand All @@ -47,6 +40,13 @@
{% endwith %}
</div>
{% endif %}
{% else %}
{% set dls = addon.weekly_downloads %}
{% if dls %}
<div id="weekly-downloads">
{{ _('{0} weekly downloads')|f(dls|numberfmt) }}
</div>
{% endif %}
{% endif %}

<div class="widgets">
Expand Down
12 changes: 7 additions & 5 deletions apps/addons/templates/addons/impala/listing/items.html
Expand Up @@ -25,20 +25,22 @@ <h3>
<div class="vitals c">
{{ impala_reviews_link(addon) }}
{{ price(addon) }}
<div class="adu">
{% if field in ('popular', 'downloads') or addon.type == amo.ADDON_SEARCH %}
{% if field in ('popular', 'downloads') or not addon.show_adu() %}
<div class="adu downloads">
{% with num=addon.weekly_downloads %}
{# L10n: {0} is the number of downloads. #}
{{ ngettext('{0} weekly download', '{0} weekly downloads',
num)|f(num|numberfmt) }}
{% endwith %}
{% else %}
</div>
{% else %}
<div class="adu">
{% with num=addon.average_daily_users %}
{# L10n: {0} is the number of users. #}
{{ ngettext('{0} user', '{0} users', num)|f(num|numberfmt) }}
{% endwith %}
{% endif %}
</div>
</div>
{% endif %}
{% if field in ('created', 'updated') %}
<div class="updated">
{% if field == 'created' %}
Expand Down
34 changes: 19 additions & 15 deletions apps/addons/templates/addons/listing/items_mobile.html
@@ -1,11 +1,14 @@
{% from "addons/macros.html" import price, refund_info %}
{% set amo_user = request.amo_user if request.user.is_authenticated() else None %}
{% for addon in addons %}

{% set is_refunded = show_refunds and addon.is_refunded(request.amo_user) %}
{% set is_chargeback = show_refunds and addon.is_chargeback(request.amo_user) %}
{% set is_refunded = show_refunds and addon.is_refunded(request.amo_user) %}
{% set is_chargeback = show_refunds and addon.is_chargeback(request.amo_user) %}
<li class="item{{ ' refunded' if is_refunded or is_chargeback }}">
<a href="{{ addon.get_url_path() }}">
{% set dl_url = addon.get_url_path() %}
{% if src %}
{% set dl_url = dl_url|urlparams(src=src) %}
{% endif %}
<a href="{{ dl_url }}">
<img class="icon" width="32" height="32" src="{{ addon.icon_url }}">
<h3>{{ addon.name }}</h3>
<details>
Expand All @@ -18,15 +21,8 @@ <h3>{{ addon.name }}</h3>
<i>{{ _('Not Yet Rated') }}</i>
{% endif %}
{% endwith %}
{% if sort in ('newest', 'created') %}
<span class="vital">
{{ _('Added {0}')|f(addon.created|datetime) }}
</span>
{% elif sort == 'updated' %}
<span class="vital">
{{ _('Updated {0}')|f(addon.last_updated|datetime) }}
<span>
{% elif sort in ('downloads', 'popular', None) %}
{{ price(addon) }}
{% if sort in ('downloads', 'popular') or not addon.show_adu() %}
<span class="vital downloads">
{% with num=addon.weekly_downloads %}
{# L10n: {0} is the number of downloads. #}
Expand All @@ -35,7 +31,7 @@ <h3>{{ addon.name }}</h3>
num)|f(num|numberfmt)|safe }}
{% endwith %}
</span>
{% elif sort == 'users' %}
{% elif sort == 'users' or addon.show_adu() %}
<span class="vital adu">
{% with num=addon.average_daily_users %}
{# L10n: {0} is the number of users. #}
Expand All @@ -45,8 +41,16 @@ <h3>{{ addon.name }}</h3>
{% endwith %}
</span>
{% endif %}
{% if sort in ('newest', 'created') %}
<span class="vital">
{{ _('Added {0}')|f(addon.created|datetime) }}
</span>
{% elif sort == 'updated' %}
<span class="vital">
{{ _('Updated {0}')|f(addon.last_updated|datetime) }}
<span>
{% endif %}
{% if waffle.switch('marketplace') %}
{{ price(addon) }}
{% if show_refunds %}
{{ refund_info(amo, addon, contributions, is_refunded, is_chargeback) }}
{% endif %}
Expand Down
14 changes: 7 additions & 7 deletions apps/addons/templates/addons/mobile/details.html
Expand Up @@ -67,14 +67,14 @@ <h4 class="author">{{ _('by') }} {{ users_list(addon.listed_authors) }}</h4>
<td>{{ addon.compatible_apps[APP] }}</td>
</tr>
{% endif %}
{% if addon.average_daily_users %}
<tr class="adu">
<th>{{ _('Users') }}</th>
<td>{{ addon.average_daily_users|numberfmt }}</td>
</tr>
{% endif %}
{% endif %}
{% if addon.weekly_downloads %}
{% if addon.show_adu() and addon.average_daily_users %}
<tr class="adu">
<th>{{ _('Users') }}</th>
<td>{{ addon.average_daily_users|numberfmt }}</td>
</tr>
{% endif %}
{% if not addon.show_adu() or addon.weekly_downloads %}
<tr class="downloads">
<th>{{ _('Weekly Downloads') }}</th>
<td>{{ addon.weekly_downloads|numberfmt }}</td>
Expand Down
27 changes: 21 additions & 6 deletions apps/search/tests/test_views.py
Expand Up @@ -147,10 +147,9 @@ def test_get_mobile(self):

@amo.tests.mobile_test
def test_mobile_results_downloads(self):
for sort in ('', 'downloads'):
r = self.client.get(urlparams(self.url, sort=sort))
assert pq(r.content)('#content .item .vital.downloads'), (
'Expected weekly downloads')
r = self.client.get(urlparams(self.url, sort='downloads'))
assert pq(r.content)('#content .item .vital.downloads'), (
'Expected weekly downloads')

def check_sort_links(self, key, title, sort_by=None, reverse=True):
r = self.client.get('%s?sort=%s' % (self.url, key))
Expand Down Expand Up @@ -509,17 +508,33 @@ def test_mobile_get(self):
eq_(r.status_code, 200)
self.assertTemplateUsed(r, 'search/mobile/results.html')

def test_results(self):
r = self.client.get(self.url)
item = pq(r.content)('.items .item')
eq_(item.length, 1)
a = item.find('h3 a')
eq_(a.text(), unicode(self.webapp.name))
eq_(a.attr('href'),
urlparams(self.webapp.get_url_path(), src='search'))

@amo.tests.mobile_test
def test_mobile_results(self):
r = self.client.get(self.url)
item = pq(r.content)('#content .item')
eq_(item.length, 1)
eq_(item.find('h3').text(), unicode(self.webapp.name))
eq_(item.children('a').attr('href'), self.webapp.get_url_path())
eq_(item.children('a').attr('href'),
urlparams(self.webapp.get_url_path(), src='search'))

def test_results_downloads(self):
for sort in ('', 'downloads', 'rating', 'created'):
r = self.client.get(urlparams(self.url, sort=sort))
dls = pq(r.content)('.item .vitals .downloads')
eq_(dls.text().split()[0], numberfmt(self.webapp.weekly_downloads))

@amo.tests.mobile_test
def test_mobile_results_downloads(self):
for sort in ('', 'downloads'):
for sort in ('', 'downloads', 'rating', 'created'):
r = self.client.get(urlparams(self.url, sort=sort))
dls = pq(r.content)('#content .item .vital.downloads')
eq_(dls.text().split()[0], numberfmt(self.webapp.weekly_downloads))
Expand Down

0 comments on commit 4f9a0df

Please sign in to comment.