diff --git a/gergelypolonkai_django/settings.py b/gergelypolonkai_django/settings.py index 3a088a0..3391f5b 100644 --- a/gergelypolonkai_django/settings.py +++ b/gergelypolonkai_django/settings.py @@ -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', +) diff --git a/gergelypolonkai_django/taghelper.py b/gergelypolonkai_django/taghelper.py new file mode 100644 index 0000000..b94a0f5 --- /dev/null +++ b/gergelypolonkai_django/taghelper.py @@ -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} diff --git a/gergelypolonkai_django/templates/front_base.html b/gergelypolonkai_django/templates/front_base.html index e389ce6..920f8c1 100644 --- a/gergelypolonkai_django/templates/front_base.html +++ b/gergelypolonkai_django/templates/front_base.html @@ -48,10 +48,10 @@
-{% if tagCloud|length > 0 %} +{% if tagcloud|length > 0 %}
-{% for cloudItem in tagCloud %} - {{ cloudItem.name }}{% if not loop.last %} | {% endif %} +{% for cloudItem in tagcloud %} + {{ cloudItem.name }}{% if not loop.last %} | {% endif %} {% endfor %}
{% endif %}