def tag_cloud current_tags def process q1 Tag objects query Tag func c

 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
def tag_cloud(current_tags):
def process():
q1 = Tag.objects.query(Tag, func.count().label('count'))
related_tag_id = Tag.avatars.property.secondary.get_related_id(Tag)
related_avatar_id = Tag.avatars.property.secondary.get_related_id(Avatar)
q1 = q1.filter(Tag.id==related_tag_id)
if current_tags:
count, q2 = avatars(current_tags, 0, True)
q2 = q2.subquery()
q1 = q1.outerjoin((q2, related_avatar_id==q2.c.id))
q1 = q1.filter(~Tag.name.in_(current_tags))
tag_cloud = q1.group_by(Tag.id).limit(TAGS_COUNT).all()
# Calculate max
m = 0
for i in tag_cloud:
if i[1] > m:
m = i[1]
# Calculate tag rating
tags = ((t[0], int(float(t[1]) / m * 4.0)) for t in tag_cloud)
return tags
return process