Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start of layout class #86

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JustinGrilli This code seems to be working except I'm getting stuck on altering the layout tags. Can you tell me how to apply this change?




# 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