From 8b6827813cf26a0d8b755fab7db7c2776950648c Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 1 Feb 2008 22:25:53 +0000 Subject: [PATCH] created method to return the thinnest full tree which contains a list of org IDs git-svn-id: svn://svn.open-ils.org/ILS/trunk@8580 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/python/oils/org.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Open-ILS/src/python/oils/org.py b/Open-ILS/src/python/oils/org.py index d5f45b60a9..431fc6dd05 100644 --- a/Open-ILS/src/python/oils/org.py +++ b/Open-ILS/src/python/oils/org.py @@ -41,6 +41,8 @@ class OrgUtil(object): @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 @@ class OrgUtil(object): 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() -- 2.11.0