Skip to content

Commit 395bbe6

Browse files
authored
Merge pull request #210 from tableau/jac/dashboards
add list of dashboard names to workbook object
2 parents 1770342 + 8e69bb7 commit 395bbe6

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

tableaudocumentapi/workbook.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ def __init__(self, filename):
2020
self._workbookTree = xml_open(self._filename, 'workbook')
2121

2222
self._workbookRoot = self._workbookTree.getroot()
23-
# prepare our datasource objects
23+
24+
self._dashboards = self._prepare_dashboards(self._workbookRoot)
25+
2426
self._datasources = self._prepare_datasources(
25-
self._workbookRoot) # self.workbookRoot.find('datasources')
27+
self._workbookRoot)
2628

2729
self._datasource_index = self._prepare_datasource_index(self._datasources)
2830

@@ -31,6 +33,10 @@ def __init__(self, filename):
3133

3234
self._shapes = self._prepare_shapes(self._workbookRoot)
3335

36+
@property
37+
def dashboards(self):
38+
return self._dashboards
39+
3440
@property
3541
def datasources(self):
3642
return self._datasources
@@ -99,6 +105,20 @@ def _prepare_datasources(xml_root):
99105

100106
return datasources
101107

108+
@staticmethod
109+
def _prepare_dashboards(xml_root):
110+
dashboards = []
111+
112+
dashboard_elements = xml_root.find('.//dashboards')
113+
if dashboard_elements is None:
114+
return []
115+
116+
for dash_element in dashboard_elements:
117+
dash_name = dash_element.attrib['name']
118+
dashboards.append(dash_name)
119+
120+
return dashboards
121+
102122
@staticmethod
103123
def _prepare_worksheets(xml_root, ds_index):
104124
worksheets = []

test/test_workbook.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
'shapes_test.twb'
1818
)
1919

20+
DASHBOARDS_FILE = os.path.join(
21+
TEST_ASSET_DIR,
22+
'filtering.twb'
23+
)
24+
2025

2126
class EphemeralFields(unittest.TestCase):
2227
def test_ephemeral_fields_do_not_cause_errors(self):
@@ -37,3 +42,10 @@ def test_shape_exist(self):
3742
def test_shape_count(self):
3843
wb = Workbook(SHAPES_FILE)
3944
self.assertEqual(len(wb.shapes), 4)
45+
46+
47+
class Dashboards(unittest.TestCase):
48+
def test_dashboards_setup(self):
49+
wb = Workbook(DASHBOARDS_FILE)
50+
self.assertIsNotNone(wb)
51+
self.assertEqual(wb.dashboards, ['setTest'])

0 commit comments

Comments
 (0)