From 068f416c3ddedcb895ad8c2b15e87add5b2fdd44 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 22 Jan 2008 15:49:53 +0000 Subject: [PATCH] beginnings of general purpose org_unit utility functions git-svn-id: svn://svn.open-ils.org/ILS/trunk@8452 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/python/oils/org.py | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Open-ILS/src/python/oils/org.py diff --git a/Open-ILS/src/python/oils/org.py b/Open-ILS/src/python/oils/org.py new file mode 100644 index 0000000000..6fc60e550c --- /dev/null +++ b/Open-ILS/src/python/oils/org.py @@ -0,0 +1,41 @@ +import osrf.ses +import oils.event, oils.const + +class OrgUtil(object): + ''' Collection of general purpose org_unit utility functions ''' + + _org_tree = None + _org_types = None + + @staticmethod + def fetch_org_tree(): + ''' Returns the whole org_unit tree ''' + if OrgUtil._org_tree: + return OrgUtil._org_tree + tree = osrf.ses.ClientSession.atomic_request( + oils.const.OILS_APP_ACTOR, + 'open-ils.actor.org_tree.retrieve') + oils.event.Event.parse_and_raise(tree) + OrgUtil._org_tree = tree + return tree + + @staticmethod + def fetch_org_types(): + ''' Returns the list of org_unit_type objects ''' + if OrgUtil._org_types: + return OrgUtil._org_types + types = osrf.ses.ClientSession.atomic_request( + oils.const.OILS_APP_ACTOR, + 'open-ils.actor.org_types.retrieve') + oils.event.Event.parse_and_raise(types) + OrgUtil._org_types = types + return types + + + @staticmethod + def get_org_type(org_unit): + ''' Given an org_unit, this returns the org_unit_type object it's linked to ''' + types = OrgUtil.fetch_org_types() + return [t for t in types if t.id() == org_unit.ou_type()][0] + + -- 2.43.2