#NEWLINE# def convert_bucket( facet , bucket ) : #NEWLINE# #INDENT# key = bucket . get ( 'key_as_string' , bucket . get ( 'key' ) ) #NEWLINE# data = { #NEWLINE# #INDENT# 'count' : bucket . get ( 'doc_count' ) , #NEWLINE# 'id' : key , #NEWLINE# 'label' : data , #NEWLINE# #UNINDENT# } #NEWLINE# if ( facet == 'languages' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# locale = Locale ( key . strip ( ) . lower ( ) ) #NEWLINE# data [ 'label' ] = locale . get_display_name ( 'en_US' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( facet == 'countries' ) and ( key is not None ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# country = countries . get ( alpha2 = key . strip ( ) . upper ( ) ) #NEWLINE# data [ 'label' ] = country . name #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return data