[open-ils-commits] r8581 - branches/acq-experiment/Open-ILS/src/python/oils

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Feb 1 17:55:07 EST 2008


Author: erickson
Date: 2008-02-01 17:27:19 -0500 (Fri, 01 Feb 2008)
New Revision: 8581

Modified:
   branches/acq-experiment/Open-ILS/src/python/oils/org.py
Log:
created method to return the thinnest full tree which contains a list of org IDs

Modified: branches/acq-experiment/Open-ILS/src/python/oils/org.py
===================================================================
--- branches/acq-experiment/Open-ILS/src/python/oils/org.py	2008-02-01 22:25:53 UTC (rev 8580)
+++ branches/acq-experiment/Open-ILS/src/python/oils/org.py	2008-02-01 22:27:19 UTC (rev 8581)
@@ -41,6 +41,8 @@
     @staticmethod
     def get_org_unit(org_id):
         OrgUtil._verify_tree()
+        if isinstance(org_id, osrf.net_obj.NetworkObject):
+            return org_id
         return OrgUtil._flat_org_tree[org_id]
         
 
@@ -95,6 +97,23 @@
         return root
 
     @staticmethod
+    def get_union_tree(org_list):
+        ''' Returns the smallest org tree which encompases all of the orgs in org_list '''
+        main_tree = OrgUtil.get_related_tree(OrgUtil.get_org_unit(org_list.pop(0)))
+        for org in org_list:
+            node = OrgUtil.get_related_tree(OrgUtil.get_org_unit(org))
+            main_node = main_tree
+
+            while node.id() == main_node.id():
+                node = node.children()[0]
+                main_node = main_node.children()[0]
+
+            print main_node.id()
+            OrgUtil.get_org_unit(main_node.parent_ou()).children().append(node)
+
+        return main_tree
+
+    @staticmethod
     def get_related_list(org_unit):
         ''' Returns a flat list of related org_units '''
         OrgUtil._verify_tree()



More information about the open-ils-commits mailing list