]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/python/oils/org.py
beginnings of general purpose org_unit utility functions
[Evergreen.git] / Open-ILS / src / python / oils / org.py
1 import osrf.ses
2 import oils.event, oils.const
3
4 class OrgUtil(object):
5     ''' Collection of general purpose org_unit utility functions '''
6
7     _org_tree = None  
8     _org_types = None  
9
10     @staticmethod
11     def fetch_org_tree():
12         ''' Returns the whole org_unit tree '''
13         if OrgUtil._org_tree:
14             return OrgUtil._org_tree
15         tree = osrf.ses.ClientSession.atomic_request(
16             oils.const.OILS_APP_ACTOR,
17             'open-ils.actor.org_tree.retrieve')
18         oils.event.Event.parse_and_raise(tree)
19         OrgUtil._org_tree = tree
20         return tree
21
22     @staticmethod
23     def fetch_org_types():
24         ''' Returns the list of org_unit_type objects '''
25         if OrgUtil._org_types:
26             return OrgUtil._org_types
27         types = osrf.ses.ClientSession.atomic_request(
28             oils.const.OILS_APP_ACTOR,
29             'open-ils.actor.org_types.retrieve')
30         oils.event.Event.parse_and_raise(types)
31         OrgUtil._org_types = types
32         return types
33
34
35     @staticmethod
36     def get_org_type(org_unit):
37         ''' Given an org_unit, this returns the org_unit_type object it's linked to '''
38         types = OrgUtil.fetch_org_types()
39         return [t for t in types if t.id() == org_unit.ou_type()][0]
40
41