From 81da0d75f8b1fca9d81cbc7a57bff62ebc0d9af2 Mon Sep 17 00:00:00 2001 From: "jac.fitzgerald" Date: Fri, 4 Oct 2024 14:08:46 -0700 Subject: [PATCH 1/5] Remove sample code showing group name encoding This is no longer needed - ran the sample and verified that it works now. --- samples/filter_sort_groups.py | 37 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/samples/filter_sort_groups.py b/samples/filter_sort_groups.py index 042af32e2..d580acee2 100644 --- a/samples/filter_sort_groups.py +++ b/samples/filter_sort_groups.py @@ -47,7 +47,7 @@ def main(): logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) - server = TSC.Server(args.server, use_server_version=True) + server = TSC.Server(args.server, use_server_version=True, http_options={"verify":False}) with server.auth.sign_in(tableau_auth): group_name = "SALES NORTHWEST" # Try to create a group named "SALES NORTHWEST" @@ -57,37 +57,39 @@ def main(): # Try to create a group named "SALES ROMANIA" create_example_group(group_name, server) - # URL Encode the name of the group that we want to filter on - # i.e. turn spaces into plus signs - filter_group_name = urllib.parse.quote_plus(group_name) + # we no longer need to encode the space options = TSC.RequestOptions() options.filter.add( - TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, filter_group_name) + TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, group_name + ) ) filtered_groups, _ = server.groups.get(req_options=options) # Result can either be a matching group or an empty list if filtered_groups: - group_name = filtered_groups.pop().name - print(group_name) + group = filtered_groups.pop() + print(group) else: - error = "No project named '{}' found".format(filter_group_name) + error = f"No group named '{group_name}' found" print(error) + print("---") + # Or, try the above with the django style filtering try: - group = server.groups.filter(name=filter_group_name)[0] + group = server.groups.filter(name=group_name)[0] + print(group) except IndexError: - print(f"No project named '{filter_group_name}' found") - else: - print(group.name) + print(f"No group named '{group_name}' found") + + print("====") options = TSC.RequestOptions() options.filter.add( TSC.Filter( TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.In, - ["SALES+NORTHWEST", "SALES+ROMANIA", "this_group"], + ["SALES NORTHWEST", "SALES ROMANIA", "this_group"], ) ) @@ -98,13 +100,16 @@ def main(): for group in matching_groups: print(group.name) + print("----") # or, try the above with the django style filtering. - + """ + bug: hangs getting the version for this request? Also should be order_by, not sort groups = ["SALES NORTHWEST", "SALES ROMANIA", "this_group"] groups = [urllib.parse.quote_plus(group) for group in groups] - for group in server.groups.filter(name__in=groups).sort("-name"): + for group in server.groups.filter(name__in=groups).order_by("-name"): print(group.name) - + """ + if __name__ == "__main__": main() From 7c58b5aa02057d6281db6a1b62d8ae16ce285fe4 Mon Sep 17 00:00:00 2001 From: "jac.fitzgerald" Date: Fri, 4 Oct 2024 14:12:24 -0700 Subject: [PATCH 2/5] format --- samples/explore_favorites.py | 3 +-- samples/filter_sort_groups.py | 13 +++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/samples/explore_favorites.py b/samples/explore_favorites.py index 243e91954..09f465439 100644 --- a/samples/explore_favorites.py +++ b/samples/explore_favorites.py @@ -3,7 +3,6 @@ import argparse import logging import tableauserverclient as TSC -from tableauserverclient import Resource def main(): @@ -47,7 +46,7 @@ def main(): all_workbook_items, pagination_item = server.workbooks.get() if all_workbook_items is not None and len(all_workbook_items) > 0: my_workbook: TSC.WorkbookItem = all_workbook_items[0] - server.favorites.add_favorite(server, user, Resource.Workbook.name(), all_workbook_items[0]) + server.favorites.add_favorite(server, user, TSC.Resource.Workbook.name(), all_workbook_items[0]) print( "Workbook added to favorites. Workbook Name: {}, Workbook ID: {}".format( my_workbook.name, my_workbook.id diff --git a/samples/filter_sort_groups.py b/samples/filter_sort_groups.py index d580acee2..bb76ff44f 100644 --- a/samples/filter_sort_groups.py +++ b/samples/filter_sort_groups.py @@ -47,7 +47,7 @@ def main(): logging.basicConfig(level=logging_level) tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) - server = TSC.Server(args.server, use_server_version=True, http_options={"verify":False}) + server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False}) with server.auth.sign_in(tableau_auth): group_name = "SALES NORTHWEST" # Try to create a group named "SALES NORTHWEST" @@ -59,10 +59,7 @@ def main(): # we no longer need to encode the space options = TSC.RequestOptions() - options.filter.add( - TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, group_name - ) - ) + options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, group_name)) filtered_groups, _ = server.groups.get(req_options=options) # Result can either be a matching group or an empty list @@ -74,14 +71,14 @@ def main(): print(error) print("---") - + # Or, try the above with the django style filtering try: group = server.groups.filter(name=group_name)[0] print(group) except IndexError: print(f"No group named '{group_name}' found") - + print("====") options = TSC.RequestOptions() @@ -109,7 +106,7 @@ def main(): for group in server.groups.filter(name__in=groups).order_by("-name"): print(group.name) """ - + if __name__ == "__main__": main() From af6f2901b7ba301f6600cc86aad676dc55a8de14 Mon Sep 17 00:00:00 2001 From: "jac.fitzgerald" Date: Fri, 11 Oct 2024 15:12:56 -0700 Subject: [PATCH 3/5] fix comment in sample --- samples/filter_sort_groups.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/samples/filter_sort_groups.py b/samples/filter_sort_groups.py index bb76ff44f..2b0a835ec 100644 --- a/samples/filter_sort_groups.py +++ b/samples/filter_sort_groups.py @@ -99,13 +99,18 @@ def main(): print("----") # or, try the above with the django style filtering. - """ - bug: hangs getting the version for this request? Also should be order_by, not sort - groups = ["SALES NORTHWEST", "SALES ROMANIA", "this_group"] - groups = [urllib.parse.quote_plus(group) for group in groups] - for group in server.groups.filter(name__in=groups).order_by("-name"): - print(group.name) - """ + all_g = server.groups.all() + print(f"Searching locally among {all_g.total_available} groups") + for a in all_g: + print(a) + groups = [urllib.parse.quote_plus(group) for group in ["SALES NORTHWEST", "SALES ROMANIA", "this_group"]] + print(groups) + + # BUG: this loop seems to continue making requests long after we've seen all groups + #for group in server.groups.filter(name__in=groups).order_by("-name"): + # print(group.name) + + print("done") if __name__ == "__main__": From 1427a28f9aa8b4f90c3f2d1ef9877b147d63e340 Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Wed, 16 Oct 2024 21:08:50 -0700 Subject: [PATCH 4/5] black format samples --- samples/explore_favorites.py | 1 - samples/filter_sort_groups.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/samples/explore_favorites.py b/samples/explore_favorites.py index bdf7e3430..f199522ed 100644 --- a/samples/explore_favorites.py +++ b/samples/explore_favorites.py @@ -46,7 +46,6 @@ def main(): # get list of workbooks all_workbook_items, pagination_item = server.workbooks.get() if all_workbook_items is not None and len(all_workbook_items) > 0: - my_workbook = all_workbook_items[0] server.favorites.add_favorite(user, Resource.Workbook, all_workbook_items[0]) print( diff --git a/samples/filter_sort_groups.py b/samples/filter_sort_groups.py index 2b0a835ec..abf2506d0 100644 --- a/samples/filter_sort_groups.py +++ b/samples/filter_sort_groups.py @@ -105,11 +105,11 @@ def main(): print(a) groups = [urllib.parse.quote_plus(group) for group in ["SALES NORTHWEST", "SALES ROMANIA", "this_group"]] print(groups) - + # BUG: this loop seems to continue making requests long after we've seen all groups - #for group in server.groups.filter(name__in=groups).order_by("-name"): + # for group in server.groups.filter(name__in=groups).order_by("-name"): # print(group.name) - + print("done") From 35ee1194c258375ee2c08bb778777819867b476a Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Wed, 16 Oct 2024 22:06:19 -0700 Subject: [PATCH 5/5] uncomment code that now works --- samples/filter_sort_groups.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/samples/filter_sort_groups.py b/samples/filter_sort_groups.py index abf2506d0..1694bf0f5 100644 --- a/samples/filter_sort_groups.py +++ b/samples/filter_sort_groups.py @@ -106,9 +106,8 @@ def main(): groups = [urllib.parse.quote_plus(group) for group in ["SALES NORTHWEST", "SALES ROMANIA", "this_group"]] print(groups) - # BUG: this loop seems to continue making requests long after we've seen all groups - # for group in server.groups.filter(name__in=groups).order_by("-name"): - # print(group.name) + for group in server.groups.filter(name__in=groups).order_by("-name"): + print(group.name) print("done")