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

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jan 22 11:17:05 EST 2008


Author: erickson
Date: 2008-01-22 10:50:42 -0500 (Tue, 22 Jan 2008)
New Revision: 8453

Added:
   branches/acq-experiment/Open-ILS/src/python/oils/org.py
Log:
beginnings of general purpose org_unit utility functions

Added: branches/acq-experiment/Open-ILS/src/python/oils/org.py
===================================================================
--- branches/acq-experiment/Open-ILS/src/python/oils/org.py	                        (rev 0)
+++ branches/acq-experiment/Open-ILS/src/python/oils/org.py	2008-01-22 15:50:42 UTC (rev 8453)
@@ -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]
+
+



More information about the open-ils-commits mailing list