Login

Clouds Tag

Author:
ramdas
Posted:
November 19, 2007
Language:
Python
Version:
.96
Tags:
tag template-tag tagging clouds cloud
Score:
1 (after 1 ratings)

This is a simple template tag to create Tag Clouds. Based on the number of Posts (change the model_name according to your schema), Tags are provided different size ( most number of posts => most popular => and hence the largest.

We create a property called cloudsize for each tag, which is an integer between minsize and maxsize.

Check the example of sample template use here http://www.djangosnippets.org/snippets/472/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from django.template import Library, Node
from project.app.models import Tag
import random

     
register = Library()

maxsize =220 # maximum size of the most popular tag
minsize = 55 # minimum size of the least popular tag



     
class LatestTagsNode(Node):
	def gen_clouds(self):
		p=Tag.objects.all()
		max1=max([int(p-item.video_set.count()) for p-item in p])
		
		for i in range(p.count()):
			size =int(round(int(p[i].video_set.count())*maxsize/max1))
			if size<minsize:
				size=minsize
			cloudsize =str(size) +"%"
			p[i].cloudsize=cloudsize
		return p

	def render(self, context):
		self.__init__()
		context['content_tagclouds'] = self.gen_clouds()
		return ''
    
def get_latest_cloudtag(parser, token):
    	
	return LatestTagsNode()
get_latest_cloudtag= register.tag(get_latest_cloudtag)

More like this

  1. Clouds Tag by ramdas 7 years, 7 months ago
  2. Tagging System by macmichael01 7 years, 4 months ago
  3. simple tag-cloud Template Tag by metty 5 years, 9 months ago
  4. Using the {% widthratio %} template tag with CSS to create a bar graph by jcroft 8 years, 4 months ago
  5. Cloud Tag template example by ramdas 7 years, 7 months ago

Comments

Please login first before commenting.