2 import oils.event, oils.const
5 ''' Collection of general purpose org_unit utility functions '''
12 ''' Returns the whole org_unit 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
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
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]