Top tags box on front page (bug 532685)

This commit is contained in:
Fred Wenzel 2010-03-23 18:53:25 +01:00
Родитель 2fdee6d1ec
Коммит 278a881b19
3 изменённых файлов: 39 добавлений и 0 удалений

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

@ -133,6 +133,24 @@
{% endblock %}
{% block under_categories %}
{% cache top_tags %}
{% if top_tags %}
{% set max_tag_count = top_tags[0].popularity or 1 %}
<div class="highlight" id="tag-box">
<h3>{{ _('Popular Tags') }}</h3>
<div class="tag-cloud">
{% for tag in top_tags|list|shuffle %}
{{ tag_link(tag.tag_text, tag.tagstat.num_addons, max_tag_count) }}
{% endfor %}
</div>
<p class="more">
<a href="{{ remora_url('/tags/top') }}">{{
_('View Top 100 Tags &rsaquo;')|safe }}</a>
</p>
</div>
{% endif %}
{% endcache %}
<div class="highlight">
<h3>{{ _('Build a {0} Add-on')|f(request.APP.pretty) }}</h3>
<p>{{ _('Find all the tools and resouces you need to make your first add-on.') }}</p>
@ -140,3 +158,10 @@
<p><strong><a href="/developers">{{ _('Visit the Developer Hub') }}</a></strong></p>
</div>
{% endblock %}
{% macro tag_link(tag_text, tag_count, max_count) -%}
{% with factor=(tag_count/max_count*10)|wround(method='ceil') %}
<a class="tagLevel{{ factor }} tag" href="{{
remora_url('/tag/' + tag_text) }}">{{ tag_text }}</a>
{% endwith %}
{%- endmacro %}

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

@ -13,6 +13,7 @@ from amo.urlresolvers import reverse
from bandwagon.models import Collection, CollectionFeature, CollectionPromo
from users.models import UserProfile
from stats.models import GlobalStat
from tags.models import Tag
from .models import Addon
@ -163,10 +164,15 @@ def home(request):
except GlobalStat.DoesNotExist:
downloads = pings = None
# Top tags.
top_tags = Tag.objects.not_blacklisted().select_related(
'tagstat').order_by('-tagstat__num_addons')[:10]
return jingo.render(request, 'addons/home.html',
{'downloads': downloads, 'pings': pings,
'filter': filter, 'addon_sets': addon_sets,
'collections': collections, 'promobox': promobox,
'top_tags': top_tags,
})

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

@ -2,6 +2,7 @@ import cgi
import collections
import json as jsonlib
import math
import random
import urllib
import urlparse
@ -277,3 +278,10 @@ def strip_controls(s):
def external_url(url):
"""Bounce a URL off outgoing.mozilla.org."""
return urlresolvers.get_outgoing_url(unicode(url))
@register.filter
def shuffle(sequence):
"""Shuffle a sequence."""
random.shuffle(sequence)
return sequence