diff wsgraph/model.py @ 23:24d57daaca21

well, now the request dispatches
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 10 Dec 2012 21:15:24 -0800
parents ee45f44394a0
children d1a8c1436ded
line wrap: on
line diff
--- a/wsgraph/model.py	Mon Dec 10 17:51:50 2012 -0800
+++ b/wsgraph/model.py	Mon Dec 10 21:15:24 2012 -0800
@@ -30,6 +30,23 @@
     def edges(self):
         """returns a list of all edges"""
 
+    def __call__(self):
+        """
+        returns JSGN format of graph:
+        {'nodes': {'node1': {},
+                   'node2': {}, ...},
+         'edges': {'node1': {'node2': {},
+                             'node3': {}, ...},
+                   'node2': {'node1': {}, ...}}
+        }
+        """
+        retval = {'nodes': {}, 'edges': {}}
+        for node in self.nodes():
+            retval['nodes'][node] = self.node(node)
+        for node1, node2 in self.edges():
+            retval['edges'].setdefault(node1, {})[node2] = self.edge(node1, node2)
+        return retval
+
     def __getitem__(self, key):
         """
         if key is a basestring, return the node of that name;