#NEWLINE# @ app . context_processor #NEWLINE# def inject_tag_cloud( ) : #NEWLINE# #INDENT# 'Add tagcloud to template context.' #NEWLINE# tags = db_session . query ( Tag ) . filter ( ( Tag . count >= 1 ) ) . order_by ( Tag . count . desc ( ) ) [ 0 : app . config [ 'TAGCLOUD_NR_OF_TAGS' ] ] #NEWLINE# min_size = app . config [ 'TAGCLOUD_MIN_FONTSIZE' ] #NEWLINE# max_size = app . config [ 'TAGCLOUD_MAX_FONTSIZE' ] #NEWLINE# size_diff = ( max_size - min_size ) #NEWLINE# min_count = tags [ ( - 1 ) ] . count #NEWLINE# max_count = tags [ 0 ] . count #NEWLINE# count_diff = ( max_count - min_count ) #NEWLINE# tags_sizes = [ ] #NEWLINE# for tag in tags : #NEWLINE# #INDENT# tag_relcount = ( tag . count - min_count ) #NEWLINE# size = ( min_size + ( ( tag_relcount * size_diff ) / count_diff ) ) #NEWLINE# tags_sizes . append ( [ tag , size ] ) #NEWLINE# #UNINDENT# return dict ( tags = sorted ( size_diff , key = ( lambda tag : tag [ 0 ] . value ) ) )