Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 33 additions & 12 deletions samples/show-fields/show_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Step 1) Use Datasource object from the Document API
############################################################
from tableaudocumentapi import Datasource
import lxml.etree
from xml.etree import ElementTree, ElementInclude
import xml.etree.ElementTree as ET

############################################################
# Step 2) Open the .tds we want to inspect
Expand All @@ -15,17 +18,35 @@
print('--- {} total fields in this datasource'.format(len(sourceTDS.fields)))
print('----------------------------------------------------------')
for count, field in enumerate(sourceTDS.fields.values()):
print('{:>4}: {} is a {}'.format(count+1, field.name, field.datatype))
blank_line = False
if field.calculation:
print(' the formula is {}'.format(field.calculation))
blank_line = True
if field.default_aggregation:
print(' the default aggregation is {}'.format(field.default_aggregation))
blank_line = True
if field.description:
print(' the description is {}'.format(field.description))
print(type(field))

if blank_line:
print('')
# print(field.name)
# # print(field.datatype)
# # print(field.role)
print(field.type)
# if field.description is not None:
# print(field.description.tag)
# # This will get the raw description from an element
# print(field.description[0][0])
# else:
# print("No Description")

# print(type(field.description))
print('-' * 70)



# print('{:>4}: {} is a {}'.format(count+1, field.name, field.datatype))
# blank_line = False
# if field.calculation:
# print(' the formula is {}'.format(field.calculation))
# blank_line = True
# if field.default_aggregation:
# print(' the default aggregation is {}'.format(field.default_aggregation))
# blank_line = True
# if field.description:
# print(' the description is {}'.format(field.description))
#
# if blank_line:
# print('')
print('----------------------------------------------------------')
2 changes: 2 additions & 0 deletions tableaudocumentapi/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ def _read_calculation(xmldata):
@staticmethod
def _read_description(xmldata):
description = xmldata.find('.//desc')
# description = xmldata.find('.//run')
if description is None:
return None

Expand All @@ -367,3 +368,4 @@ def _read_description(xmldata):
description_string = description_string.decode('utf-8')

return description_string
# return description