From 60ebac3347871a6c8f598e042067ea988ce9f56a Mon Sep 17 00:00:00 2001 From: Jay Rosenthal Date: Sat, 25 May 2024 07:29:15 -0500 Subject: [PATCH] Add Layout Add class to alter the layout settings and add showing folders to enforce columns --- setup.py | 2 +- .../tableau_file/tableau_file.py | 12 ++++++++++ .../tableau_file/tableau_file_objects.py | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index eac07082..7380dd42 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ long_description=readme, long_description_content_type='text/markdown', name="tableau_utilities", - version="2.2.11", + version="2.2.12", requires_python=">=3.8", packages=[ 'tableau_utilities', diff --git a/tableau_utilities/tableau_file/tableau_file.py b/tableau_utilities/tableau_file/tableau_file.py index 8d55d56b..d205c9e3 100644 --- a/tableau_utilities/tableau_file/tableau_file.py +++ b/tableau_utilities/tableau_file/tableau_file.py @@ -151,6 +151,7 @@ def __init__(self, file_path): self.folders_common: tfo.FoldersCommon = self.__get_section(tfo.FoldersCommon) self.date_options: tfo.DateOptions = self.__get_section(tfo.DateOptions) self.extract: tfo.Extract = self.__get_section(tfo.Extract) + self.layout: tfo.Layout = self.__get_section(tfo.Layout) def __delattr__(self, attr): section = getattr(self, attr) @@ -172,6 +173,7 @@ def sections(self): yield self.folders_common yield self.date_options yield self.extract + yield self.layout @staticmethod def __remove_section_from_parent(parent, tag) -> list[tuple[int, ET.Element]]: @@ -198,7 +200,11 @@ def __get_section(self, obj, enforce_list=False): parent = self._root.find('.') # Gets elements within the parent element, with the appropriate section.tag section: list[dict] = list() + print('-'*50) + print(section) for element in parent: + print('-------------ELEMENT') + print(section) if element.tag.endswith(f'true...{obj.tag}') or element.tag == obj.tag: item = xmltodict.parse(ET.tostring(element))[element.tag] if not item: @@ -224,6 +230,7 @@ def enforce_column(self, column, folder_name=None, remote_name=None): - Create the folder if it doesn't exist - Updating the metadata local-name to map to the column name - Adding the column mapping to the mapping cols, if it doesn't exist + - Displaying the folders and sorting columns alphabetically Args: column (tfo.Column): The TableFile Column object @@ -255,6 +262,11 @@ def enforce_column(self, column, folder_name=None, remote_name=None): elif not folder: self.folders_common.folder.add(tfo.Folder(name=folder_name, folder_item=[folder_item])) + # Set display to show folders + self.layout.update(show_structure='true') + + + # If a remote_name was provided, and the column is not a Tableau Calculation - enforce metadata if not remote_name or column.calculation: return None diff --git a/tableau_utilities/tableau_file/tableau_file_objects.py b/tableau_utilities/tableau_file/tableau_file_objects.py index 7935f803..f5d29bf1 100644 --- a/tableau_utilities/tableau_file/tableau_file_objects.py +++ b/tableau_utilities/tableau_file/tableau_file_objects.py @@ -1071,6 +1071,30 @@ def dict(self): return dictionary +@dataclass +class Layout(TableauFileObject): + """ The Layout Tableau file object """ + dim_percentage: str = None + measure_percentage: str = None + dim_ordering: str = None # ordinal or alphabetic + measure_ordering: str = None # ordinal or alphabetic + show_structure: bool = None + tag: str = 'layout' + + def dict(self): + dictionary = dict() + if self.dim_percentage is not None: + dictionary['@dim-percentage'] = self.dim_percentage + if self.measure_percentage is not None: + dictionary['@measure-percentage'] = self.measure_percentage + if self.dim_ordering is not None: + dictionary['@dim-ordering'] = self.dim_ordering + if self.measure_ordering is not None: + dictionary['@measure-ordering'] = self.measure_ordering + if self.show_structure is not None: + dictionary['@show-structure'] = str(self.show_structure).lower() + return dictionary + @dataclass class Aliases(TableauFileObject): """ The Aliases Tableau file object """