Changes between Version 11 and Version 12 of DjangoGraphviz


Ignore:
Timestamp:
Aug 6, 2006, 2:59:52 PM (18 years ago)
Author:
Antonio Cavedoni
Comment:

More code refactoring (no more print statements)

Legend:

Unmodified
Added
Removed
Modified
  • DjangoGraphviz

    v11 v12  
    3333Changelog
    3434
     350.5.1
     36Got rid of print statements, now the generate_dot() function returns
     37a string with the file contents
     38
    35390.5
    3640Cleaned up code, now the relationship arrows start from the
     
    5256"""
    5357
    54 __version__ = "0.4"
     58__version__ = "0.5.1"
    5559__svnid__ = "$Id: modelviz.py 4 2006-08-06 19:48:42Z verbosus $"
    5660__license__ = "Python"
     
    7074   app = models.get_app(app_label)
    7175
    72    print "digraph %s {" % ('"' + app.__name__ + '"')
    73    print """  fontname = "Helvetica"
     76   graph = []
     77   graph.append("digraph %s {" % ('"' + app.__name__ + '"'))
     78   graph.append("""  fontname = "Helvetica"
    7479  fontsize = 8
    7580     
     
    8388    fontsize = 8
    8489  ]
    85 """
     90""")
    8691   for o in get_models(app):
    87       nodes = []
    88       nodes.append(""" subgraph cluster_%(model)s {
     92      graph.append(""" subgraph cluster_%(model)s {
    8993  shape = "record";
    9094  label = "%(model)s";
     
    96100      # model attributes
    97101      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|" % \
    99103                      {'model': o.__name__, 'field': field.name,
    100104                       'related': type(field).__name__})
     
    107111            add_attributes()
    108112
    109       nodes.append(""" }"] [color="white" shape="record"];\n }\n""")
    110       print "".join(nodes)
     113      graph.append(""" }"] [color="white" shape="record"];\n }\n""")
    111114
    112115      # relations
    113116      rel = []
    114 
    115117      def add_relation(extras=""):
    116118         _rel = """ %(model)s:%(model)s_%(field)s -> %(related)s
    117          [label="%(relationship)s"] %(extras)s;""" % {
     119         [label="%(relationship)s"] %(extras)s;\n""" % {
    118120            'model': o.__name__, 'field': field.name,
    119121            'related': field.rel.to.__name__,
     
    136138               add_relation(
    137139                  '[style="dotted"] [arrowhead=normal arrowtail=normal]')
     140      graph.append("".join(rel))
    138141
    139       print "\n".join(rel)
    140 
    141    print "}"
     142   graph.append('}')
     143   return "".join(graph)
    142144
    143145if __name__ == "__main__":
    144146   import sys
    145147   app_label = sys.argv[1]
    146    generate_dot(app_label)
     148   print generate_dot(app_label)
    147149}}}
Back to Top