#NEWLINE# def get( self , request , name = 'root' , * args , **kwargs ) : #NEWLINE# #INDENT# import networkx as nx #NEWLINE# import matplotlib as mpl #NEWLINE# mpl . use ( 'Agg' ) #NEWLINE# import matplotlib.pyplot as plt #NEWLINE# import nxedges #NEWLINE# plt . figure ( figsize = ( 10 , 8 ) ) #NEWLINE# g = nx . DiGraph ( ) #NEWLINE# labels = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for service in Service . objects . all ( ) : #NEWLINE# #INDENT# g . add_node ( service . id ) #NEWLINE# if ( len ( service . name ) > 8 ) : #NEWLINE# #INDENT# labels [ service . id ] = ( ( service . name [ : 8 ] + '\n' ) + service . name [ 8 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# labels [ service . id ] = service . name #NEWLINE# #UNINDENT# #UNINDENT# for tenant in CoarseTenant . objects . all ( ) : #NEWLINE# #INDENT# if ( ( not tenant . provider_service ) or ( not tenant . subscriber_service ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# g . add_edge ( tenant . subscriber_service . id , tenant . provider_service . id ) #NEWLINE# #UNINDENT# pos = nx . graphviz_layout ( g ) #NEWLINE# nxedges . xos_draw_networkx_edges ( g , pos , arrow_len = 30 ) #NEWLINE# nx . draw_networkx_nodes ( g , pos , node_size = 5000 ) #NEWLINE# nx . draw_networkx_labels ( g , pos , labels , font_size = 12 ) #NEWLINE# plt . savefig ( '/tmp/foo.png' ) #NEWLINE# return HttpResponse ( open ( '/tmp/foo.png' , 'r' ) . read ( ) , content_type = 'image/png' )