Skip to content

Commit

Permalink
refactor request_options, add language param (#1481)
Browse files Browse the repository at this point in the history
* refactor request_options, add language param

I have refactored the classes to separate options that can be used in querying content, and options that can be used for exporting data. "language" is only available for data exporting.
  • Loading branch information
jacalata authored Oct 11, 2024
1 parent f8728b2 commit 89e1ddf
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 144 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ target-version = ['py39', 'py310', 'py311', 'py312', 'py313']
check_untyped_defs = false
disable_error_code = [
'misc',
# tableauserverclient\server\endpoint\datasources_endpoint.py:48: error: Cannot assign multiple types to name "FilePath" without an explicit "Type[...]" annotation [misc]
'annotation-unchecked' # can be removed when check_untyped_defs = true
]
files = ["tableauserverclient", "test", "samples"]
show_error_codes = true
ignore_missing_imports = true # defusedxml library has no types
no_implicit_reexport = true
implicit_optional = true

[tool.pytest.ini_options]
testpaths = ["test"]
Expand Down
14 changes: 9 additions & 5 deletions samples/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def main():
"--csv", dest="type", action="store_const", const=("populate_csv", "CSVRequestOptions", "csv", "csv")
)
# other options shown in explore_workbooks: workbook.download, workbook.preview_image

parser.add_argument(
"--language", help="Text such as 'Average' will appear in this language. Use values like fr, de, es, en"
)
parser.add_argument("--workbook", action="store_true")

parser.add_argument("--file", "-f", help="filename to store the exported data")
Expand Down Expand Up @@ -74,16 +76,18 @@ def main():
populate = getattr(server.workbooks, populate_func_name)

option_factory = getattr(TSC, option_factory_name)
options: TSC.PDFRequestOptions = option_factory()

if args.filter:
options = option_factory().vf(*args.filter.split(":"))
else:
options = None
options = options.vf(*args.filter.split(":"))

if args.language:
options.language = args.language

if args.file:
filename = args.file
else:
filename = f"out.{extension}"
filename = f"out-{options.language}.{extension}"

populate(item, options)
with open(filename, "wb") as f:
Expand Down
48 changes: 26 additions & 22 deletions tableauserverclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
PermissionsRule,
PersonalAccessTokenAuth,
ProjectItem,
Resource,
RevisionItem,
ScheduleItem,
SiteItem,
ServerInfoItem,
SubscriptionItem,
TableauItem,
TableItem,
TableauAuth,
Target,
Expand Down Expand Up @@ -66,66 +68,68 @@
)

__all__ = [
"get_versions",
"DEFAULT_NAMESPACE",
"BackgroundJobItem",
"BackgroundJobItem",
"ColumnItem",
"ConnectionCredentials",
"ConnectionItem",
"CSVRequestOptions",
"CustomViewItem",
"DQWItem",
"DailyInterval",
"DataAlertItem",
"DatabaseItem",
"DataFreshnessPolicyItem",
"DatasourceItem",
"DEFAULT_NAMESPACE",
"DQWItem",
"ExcelRequestOptions",
"FailedSignInError",
"FavoriteItem",
"FileuploadItem",
"Filter",
"FlowItem",
"FlowRunItem",
"FileuploadItem",
"get_versions",
"GroupItem",
"GroupSetItem",
"HourlyInterval",
"ImageRequestOptions",
"IntervalItem",
"JobItem",
"JWTAuth",
"LinkedTaskFlowRunItem",
"LinkedTaskItem",
"LinkedTaskStepItem",
"MetricItem",
"MissingRequiredFieldError",
"MonthlyInterval",
"NotSignedInError",
"Pager",
"PaginationItem",
"PDFRequestOptions",
"Permission",
"PermissionsRule",
"PersonalAccessTokenAuth",
"ProjectItem",
"RequestOptions",
"Resource",
"RevisionItem",
"ScheduleItem",
"SiteItem",
"Server",
"ServerInfoItem",
"ServerResponseError",
"SiteItem",
"Sort",
"SubscriptionItem",
"TableItem",
"TableauAuth",
"TableauItem",
"TableItem",
"Target",
"TaskItem",
"UserItem",
"ViewItem",
"VirtualConnectionItem",
"WebhookItem",
"WeeklyInterval",
"WorkbookItem",
"CSVRequestOptions",
"ExcelRequestOptions",
"ImageRequestOptions",
"PDFRequestOptions",
"RequestOptions",
"MissingRequiredFieldError",
"NotSignedInError",
"ServerResponseError",
"Filter",
"Pager",
"Server",
"Sort",
"LinkedTaskItem",
"LinkedTaskStepItem",
"LinkedTaskFlowRunItem",
"VirtualConnectionItem",
]
Loading

0 comments on commit 89e1ddf

Please sign in to comment.