From 50f955330cf61af1c7a433c93c5b59eefad2768f Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 4 Feb 2008 16:48:55 +0000 Subject: [PATCH] added a min-depth function for a group of orgs, changed some variable names to be more explicit git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@8607 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/python/oils/org.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/python/oils/org.py b/Open-ILS/src/python/oils/org.py index 734463631d..c37c9c7a6c 100644 --- a/Open-ILS/src/python/oils/org.py +++ b/Open-ILS/src/python/oils/org.py @@ -98,18 +98,18 @@ 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 ''' + def get_union_tree(org_id_list): + ''' Returns the smallest org tree which encompases all of the orgs in org_id_list ''' OrgUtil._verify_tree() - if len(org_list) == 0: + if len(org_id_list) == 0: return None - main_tree = OrgUtil.get_related_tree(OrgUtil.get_org_unit(org_list[0])) + main_tree = OrgUtil.get_related_tree(OrgUtil.get_org_unit(org_id_list[0])) - if len(org_list) == 1: + if len(org_id_list) == 1: return main_tree - for org in org_list[1:]: + for org in org_id_list[1:]: node = OrgUtil.get_related_tree(OrgUtil.get_org_unit(org)) main_node = main_tree @@ -139,6 +139,18 @@ class OrgUtil(object): return orglist @staticmethod + def get_min_depth(org_id_list): + ''' Returns the minimun depth (highest tree position) of all orgs in the list ''' + depth = None + for org in org_id_list: + new_depth = OrgUtil.get_org_type(OrgUtil.get_org_unit(org)).depth() + if depth is None: + depth = new_depth + elif new_depth < depth: + depth = new_depth + return depth + + @staticmethod def debug_tree(org_unit, indent=0): ''' Simple function to print the tree of orgs provided ''' for i in range(indent): -- 2.11.0