Commits

wilsaj  committed 04f9c7a

add a constraints column to the graphviz output tables that will
contain a set of constraints per column; this requires objects['cols']
to contain the actual SQLAlchemy column objects not just their name
and type, since we need to deal with the actual column objects to
determine if for example, a column is a PK or what constraints it has
on it

  • Participants
  • Parent commits c86d02b
  • Branches show-constraints

Comments (0)

Files changed (3)

File sadisplay/describe.py

 
         result_item = {
             'name': entry.name,
-            'cols': [(col.type.__class__.__name__, col.name)
-                            for col in entry.columns],
+            'cols': tuple(entry.columns),
             'props': [],
             'methods': [],
         }

File sadisplay/render.py

 
     classes, relations, inherits = desc
 
+    for cls in classes:
+        cls['cols'] = [(col.type.__class__.__name__, col.name)
+                    for col in cls['cols']]
+
     CLASS_TEMPLATE = "Class %(name)s {\n%(cols)s\n%(props)s\n%(methods)s\n}\n"
 
     COLUMN_TEMPLATE = "\t%(name)s \t\t%(type)s"
     result = env.get_template('dot.tpl').render(
         classes=classes,
         inherits=inherits,
-        relations=relations)
+        relations=relations,
+        show_constraints=True)
 
     return result

File sadisplay/templates/dot.tpl

     {{class.name}} [label=<
       <TABLE BGCOLOR="#E0E4CC" BORDER="0"
              CELLBORDER="0" CELLSPACING="0">
-        <TR><TD COLSPAN="2" CELLPADDING="4"
+        <TR><TD COLSPAN="{% if show_constraints %}3{% else %}}2{% endif %}" CELLPADDING="4"
                  ALIGN="CENTER" BGCOLOR="#F38630"
              ><FONT FACE="Helvetica Bold" COLOR="#FCFFFF" POINT-SIZE="10"
              >{{class.name}}</FONT></TD></TR>
 
   {%- for col in class.cols %}
-        <TR><TD ALIGN="LEFT" BORDER="0" PORT="{{col[1]}}"
-            ><FONT FACE="Bitstream Vera Sans">{{col[1]}}</FONT
-            ></TD><TD ALIGN="LEFT" PORT="{{col[1]}}_type"
-            ><FONT FACE="Bitstream Vera Sans">{{col[0]}}</FONT
+        <TR><TD ALIGN="LEFT" BORDER="0" PORT="{{col.name}}"
+            ><FONT FACE="Bitstream Vera Sans">{{col.name}}</FONT
+            ></TD>
+            {%- if show_constraints %}
+            <TD ALIGN="LEFT" BORDER="0"
+            ><FONT FACE="Bitstream Vera Sans"
+            >{% if col.primary_key %}PK{% else %} {% endif %}</FONT></TD>
+            {%- endif -%}
+            <TD ALIGN="LEFT" PORT="{{col.name}}_type"
+            ><FONT FACE="Bitstream Vera Sans">{{col.type.__class__.__name__}}</FONT
             ></TD></TR>
   {%- endfor %}
 
         <TR><TD ALIGN="LEFT" BORDER="0"
                 BGCOLOR="#A7DBD8"
             ><FONT FACE="Bitstream Vera Sans">{{prop}}</FONT></TD
-            ><TD BGCOLOR="#A7DBD8" ALIGN="LEFT"
+            >
+            {%- if show_constraints %}
+            <TD ALIGN="LEFT" BORDER="0" BGCOLOR="#A7DBD8"></TD>
+            {%- endif -%}
+            <TD BGCOLOR="#A7DBD8" ALIGN="LEFT"
             ><FONT FACE="Bitstream Vera Sans">PROPERTY</FONT
             ></TD></TR>
   {%- endfor %}
   {%- for method in class.methods %}
         <TR><TD ALIGN="LEFT" BORDER="0"
                 BGCOLOR="#A7DBD8"
-             ><FONT FACE="Bitstream Vera Sans">{{method}}()</FONT></TD
-             ><TD BGCOLOR="#A7DBD8" ALIGN="LEFT"
-             ><FONT FACE="Bitstream Vera Sans">METHOD</FONT
-             ></TD></TR>
+            ><FONT FACE="Bitstream Vera Sans">{{method}}()</FONT></TD
+            >
+            {%- if show_constraints %}
+            <TD ALIGN="LEFT" BORDER="0" BGCOLOR="#A7DBD8"></TD>
+            {%- endif -%}
+            <TD BGCOLOR="#A7DBD8" ALIGN="LEFT"
+            ><FONT FACE="Bitstream Vera Sans">METHOD</FONT
+            ></TD></TR>
   {%- endfor %}
       </TABLE>
       >]