Skip to content

Commit

Permalink
Add Layout
Browse files Browse the repository at this point in the history
Add class to alter the layout settings and add showing folders to enforce columns
  • Loading branch information
jaybythebay committed May 26, 2024
1 parent 41b5b8a commit 60ebac3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 12 additions & 0 deletions tableau_utilities/tableau_file/tableau_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]]:
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tableau_utilities/tableau_file/tableau_file_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down

0 comments on commit 60ebac3

Please sign in to comment.