Fix tag cloud generating code
It now works even if there are no tags.
This commit is contained in:
parent
4f8db2dc97
commit
8820dd89ba
@ -11,25 +11,24 @@ def randomheader(request):
|
||||
return {'header': header_file}
|
||||
|
||||
def tagcloud(request):
|
||||
tagcloud = []
|
||||
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
|
||||
if (tmax == tmin):
|
||||
tmax += 1
|
||||
|
||||
tagcloud = []
|
||||
for cloudelement in tagcloudlist:
|
||||
tagcount = cloudelement.ct
|
||||
|
||||
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})
|
||||
|
||||
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=itemgetter('name'))
|
||||
tagcloud.sort(key=itemgetter('name'))
|
||||
|
||||
return {'tagcloud': tagcloud}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user