Skip to content

Commit 60ebac3

Browse files
committed
Add Layout
Add class to alter the layout settings and add showing folders to enforce columns
1 parent 41b5b8a commit 60ebac3

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
long_description=readme,
1313
long_description_content_type='text/markdown',
1414
name="tableau_utilities",
15-
version="2.2.11",
15+
version="2.2.12",
1616
requires_python=">=3.8",
1717
packages=[
1818
'tableau_utilities',

tableau_utilities/tableau_file/tableau_file.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def __init__(self, file_path):
151151
self.folders_common: tfo.FoldersCommon = self.__get_section(tfo.FoldersCommon)
152152
self.date_options: tfo.DateOptions = self.__get_section(tfo.DateOptions)
153153
self.extract: tfo.Extract = self.__get_section(tfo.Extract)
154+
self.layout: tfo.Layout = self.__get_section(tfo.Layout)
154155

155156
def __delattr__(self, attr):
156157
section = getattr(self, attr)
@@ -172,6 +173,7 @@ def sections(self):
172173
yield self.folders_common
173174
yield self.date_options
174175
yield self.extract
176+
yield self.layout
175177

176178
@staticmethod
177179
def __remove_section_from_parent(parent, tag) -> list[tuple[int, ET.Element]]:
@@ -198,7 +200,11 @@ def __get_section(self, obj, enforce_list=False):
198200
parent = self._root.find('.')
199201
# Gets elements within the parent element, with the appropriate section.tag
200202
section: list[dict] = list()
203+
print('-'*50)
204+
print(section)
201205
for element in parent:
206+
print('-------------ELEMENT')
207+
print(section)
202208
if element.tag.endswith(f'true...{obj.tag}') or element.tag == obj.tag:
203209
item = xmltodict.parse(ET.tostring(element))[element.tag]
204210
if not item:
@@ -224,6 +230,7 @@ def enforce_column(self, column, folder_name=None, remote_name=None):
224230
- Create the folder if it doesn't exist
225231
- Updating the metadata local-name to map to the column name
226232
- Adding the column mapping to the mapping cols, if it doesn't exist
233+
- Displaying the folders and sorting columns alphabetically
227234
228235
Args:
229236
column (tfo.Column): The TableFile Column object
@@ -255,6 +262,11 @@ def enforce_column(self, column, folder_name=None, remote_name=None):
255262
elif not folder:
256263
self.folders_common.folder.add(tfo.Folder(name=folder_name, folder_item=[folder_item]))
257264

265+
# Set display to show folders
266+
self.layout.update(show_structure='true')
267+
268+
269+
258270
# If a remote_name was provided, and the column is not a Tableau Calculation - enforce metadata
259271
if not remote_name or column.calculation:
260272
return None

tableau_utilities/tableau_file/tableau_file_objects.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,30 @@ def dict(self):
10711071
return dictionary
10721072

10731073

1074+
@dataclass
1075+
class Layout(TableauFileObject):
1076+
""" The Layout Tableau file object """
1077+
dim_percentage: str = None
1078+
measure_percentage: str = None
1079+
dim_ordering: str = None # ordinal or alphabetic
1080+
measure_ordering: str = None # ordinal or alphabetic
1081+
show_structure: bool = None
1082+
tag: str = 'layout'
1083+
1084+
def dict(self):
1085+
dictionary = dict()
1086+
if self.dim_percentage is not None:
1087+
dictionary['@dim-percentage'] = self.dim_percentage
1088+
if self.measure_percentage is not None:
1089+
dictionary['@measure-percentage'] = self.measure_percentage
1090+
if self.dim_ordering is not None:
1091+
dictionary['@dim-ordering'] = self.dim_ordering
1092+
if self.measure_ordering is not None:
1093+
dictionary['@measure-ordering'] = self.measure_ordering
1094+
if self.show_structure is not None:
1095+
dictionary['@show-structure'] = str(self.show_structure).lower()
1096+
return dictionary
1097+
10741098
@dataclass
10751099
class Aliases(TableauFileObject):
10761100
""" The Aliases Tableau file object """

0 commit comments

Comments
 (0)