render_to project index html def index request tags cursor connection

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
@render_to('project/index.html')
def index(request):
tags = []
cursor = connection.cursor()
cursor.execute("""SELECT tagging_tag.name, COUNT(*) as counter
FROM tagging_tag JOIN tagging_taggeditem
ON tagging_tag.id = tagging_taggeditem.tag_id
GROUP BY tagging_tag.id
ORDER BY counter DESC""")
for name, counter in cursor.fetchmany(size=60):
tag = get_tag(name)
tag.count = counter
tags.append(tag)
tags.sort(key=lambda x: x.name)
cloud = calculate_cloud(tags)
return {'tags': cloud}