[open-ils-commits] r8452 - trunk/Open-ILS/src/python/oils
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Jan 22 11:16:18 EST 2008
Author: erickson
Date: 2008-01-22 10:49:53 -0500 (Tue, 22 Jan 2008)
New Revision: 8452
Added:
trunk/Open-ILS/src/python/oils/org.py
Log:
beginnings of general purpose org_unit utility functions
Added: trunk/Open-ILS/src/python/oils/org.py
===================================================================
--- trunk/Open-ILS/src/python/oils/org.py (rev 0)
+++ trunk/Open-ILS/src/python/oils/org.py 2008-01-22 15:49:53 UTC (rev 8452)
@@ -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