1. Chris Mutel
  2. django-directed-acyclic-graph

Commits

Chris Mutel  committed 017a87d

Bug fixes needed because of poor separation from Brightway LCA toolkit

  • Participants
  • Parent commits 4608f18
  • Branches default

Comments (0)

Files changed (2)

File django_dag/sql/__init__.py

View file
     """
     # TODO: Pass stringIO object as well?
     try:
-        filepath = os.path.join(__file__, obj)
+        filepath = os.path.join(os.path.dirname(__file__), obj)
         query = open(filepath, "r").read()
     except IOError:
         # Assume query is a string
         return dict_cursor(cursor)
     else:
         return cursor
+
+def dict_cursor(cursor):
+    """Turn SQL tuples into dictionaries. Returns generator."""
+    description = [x[0] for x in cursor.description]
+    for row in cursor:
+        yield dict(zip(description, row))
+

File django_dag/utils.py

View file
     if not node:
         # Can be called by get_children, etc., when node isn't created.
         return ()
-    query = "sql/objects_downwards.sql" if downwards else \
-        "sql/objects_upwards.sql"
+    query = "objects_downwards.sql" if downwards else "objects_upwards.sql"
     # Realize generator with list comprehension
     tc_query = [obj for obj in sql(query, (node.id, max_depth), using=using, 
         as_dict=True)]