FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add list of dashboard names to workbook object by jacalata · Pull Request #210 · tableau/document-api-python · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
24 changes: 22 additions & 2 deletions tableaudocumentapi/workbook.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down
12 changes: 12 additions & 0 deletions test/test_workbook.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'])

Back | FazBrowse Home | New Git URL