Skip to content

Commit

Permalink
Remove sample code showing group name encoding
Browse files Browse the repository at this point in the history
This is no longer needed - ran the sample and verified that it works now.
  • Loading branch information
jacalata committed Oct 4, 2024
1 parent 4259316 commit 81da0d7
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions samples/filter_sort_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"],
)
)

Expand All @@ -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()

0 comments on commit 81da0d7

Please sign in to comment.