The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ

Finished tag cloud

master
Gergely Polonkai 9 years ago
parent e04a7c6fda
commit 84fd0e38e3
  1. 11
      gergelypolonkai_django/settings.py
  2. 26
      gergelypolonkai_django/taghelper.py
  3. 6
      gergelypolonkai_django/templates/front_base.html

@ -161,3 +161,14 @@ LOGGING = {
},
}
}
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
'gergelypolonkai_django.taghelper.tagcloud',
)

@ -0,0 +1,26 @@
from django.db.models import Count
from taggit.models import Tag
from math import floor
def tagcloud(request):
tagcloudlist = Tag.objects.annotate(ct=Count('taggit_taggeditem_items')).order_by('-ct')
if (len(tagcloudlist) > 0):
tmax = tagcloudlist[0].ct
tmin = 1
if (tmax == tmin):
tmax += 1
tagcloud = []
for cloudelement in tagcloudlist:
tagcount = cloudelement.ct
if (tagcount >= tmin):
size = int(floor((5.0 * (tagcount - tmin)) / (tmax - tmin)))
tagcloud.append({'name': cloudelement.name, 'slug': cloudelement.slug, 'size': size})
tagcloud.sort(key=lambda k: k['name'])
return {'tagcloud': tagcloud}

@ -48,10 +48,10 @@
</ul>
<br class="clear" />
</div>
{% if tagCloud|length > 0 %}
{% if tagcloud|length > 0 %}
<div id="tag-cloud">
{% for cloudItem in tagCloud %}
<a href="{% url 'blog_tag_list' cloudItem.name %}" class="size{{ cloudItem.size }}">{{ cloudItem.name }}</a>{% if not loop.last %} | {% endif %}
{% for cloudItem in tagcloud %}
<a href="{% url 'blog:taglist' cloudItem.slug %}" class="size{{ cloudItem.size }}">{{ cloudItem.name }}</a>{% if not loop.last %} | {% endif %}
{% endfor %}
</div>
{% endif %}

Loading…
Cancel
Save