Changes between Version 11 and Version 12 of DjangoGraphviz
- Timestamp:
- Aug 6, 2006, 2:59:52 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DjangoGraphviz
v11 v12 33 33 Changelog 34 34 35 0.5.1 36 Got rid of print statements, now the generate_dot() function returns 37 a string with the file contents 38 35 39 0.5 36 40 Cleaned up code, now the relationship arrows start from the … … 52 56 """ 53 57 54 __version__ = "0. 4"58 __version__ = "0.5.1" 55 59 __svnid__ = "$Id: modelviz.py 4 2006-08-06 19:48:42Z verbosus $" 56 60 __license__ = "Python" … … 70 74 app = models.get_app(app_label) 71 75 72 print "digraph %s {" % ('"' + app.__name__ + '"') 73 print """ fontname = "Helvetica" 76 graph = [] 77 graph.append("digraph %s {" % ('"' + app.__name__ + '"')) 78 graph.append(""" fontname = "Helvetica" 74 79 fontsize = 8 75 80 … … 83 88 fontsize = 8 84 89 ] 85 """ 90 """) 86 91 for o in get_models(app): 87 nodes = [] 88 nodes.append(""" subgraph cluster_%(model)s { 92 graph.append(""" subgraph cluster_%(model)s { 89 93 shape = "record"; 90 94 label = "%(model)s"; … … 96 100 # model attributes 97 101 def add_attributes(): 98 nodes.append("<%(model)s_%(field)s>%(field)s : %(related)s|" % \102 graph.append("<%(model)s_%(field)s>%(field)s : %(related)s|" % \ 99 103 {'model': o.__name__, 'field': field.name, 100 104 'related': type(field).__name__}) … … 107 111 add_attributes() 108 112 109 nodes.append(""" }"] [color="white" shape="record"];\n }\n""") 110 print "".join(nodes) 113 graph.append(""" }"] [color="white" shape="record"];\n }\n""") 111 114 112 115 # relations 113 116 rel = [] 114 115 117 def add_relation(extras=""): 116 118 _rel = """ %(model)s:%(model)s_%(field)s -> %(related)s 117 [label="%(relationship)s"] %(extras)s; """ % {119 [label="%(relationship)s"] %(extras)s;\n""" % { 118 120 'model': o.__name__, 'field': field.name, 119 121 'related': field.rel.to.__name__, … … 136 138 add_relation( 137 139 '[style="dotted"] [arrowhead=normal arrowtail=normal]') 140 graph.append("".join(rel)) 138 141 139 print "\n".join(rel) 140 141 print "}" 142 graph.append('}') 143 return "".join(graph) 142 144 143 145 if __name__ == "__main__": 144 146 import sys 145 147 app_label = sys.argv[1] 146 generate_dot(app_label)148 print generate_dot(app_label) 147 149 }}}