diff --git a/tableaudocumentapi/workbook.py b/tableaudocumentapi/workbook.py index 17b5cd5..950c83a 100644 --- a/tableaudocumentapi/workbook.py +++ b/tableaudocumentapi/workbook.py @@ -20,9 +20,11 @@ def __init__(self, filename): self._workbookTree = xml_open(self._filename, 'workbook') self._workbookRoot = self._workbookTree.getroot() - # prepare our datasource objects + + self._dashboards = self._prepare_dashboards(self._workbookRoot) + self._datasources = self._prepare_datasources( - self._workbookRoot) # self.workbookRoot.find('datasources') + self._workbookRoot) self._datasource_index = self._prepare_datasource_index(self._datasources) @@ -31,6 +33,10 @@ def __init__(self, filename): self._shapes = self._prepare_shapes(self._workbookRoot) + @property + def dashboards(self): + return self._dashboards + @property def datasources(self): return self._datasources @@ -99,6 +105,20 @@ def _prepare_datasources(xml_root): return datasources + @staticmethod + def _prepare_dashboards(xml_root): + dashboards = [] + + dashboard_elements = xml_root.find('.//dashboards') + if dashboard_elements is None: + return [] + + for dash_element in dashboard_elements: + dash_name = dash_element.attrib['name'] + dashboards.append(dash_name) + + return dashboards + @staticmethod def _prepare_worksheets(xml_root, ds_index): worksheets = [] diff --git a/test/test_workbook.py b/test/test_workbook.py index eb1a5a9..41501db 100644 --- a/test/test_workbook.py +++ b/test/test_workbook.py @@ -17,6 +17,11 @@ 'shapes_test.twb' ) +DASHBOARDS_FILE = os.path.join( + TEST_ASSET_DIR, + 'filtering.twb' +) + class EphemeralFields(unittest.TestCase): def test_ephemeral_fields_do_not_cause_errors(self): @@ -37,3 +42,10 @@ def test_shape_exist(self): def test_shape_count(self): wb = Workbook(SHAPES_FILE) self.assertEqual(len(wb.shapes), 4) + + +class Dashboards(unittest.TestCase): + def test_dashboards_setup(self): + wb = Workbook(DASHBOARDS_FILE) + self.assertIsNotNone(wb) + self.assertEqual(wb.dashboards, ['setTest'])