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

Remove sample code showing group name encoding #1486

Merged
merged 8 commits into from
Oct 23, 2024
Merged
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
44 changes: 25 additions & 19 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,36 @@ 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)
)
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
if filtered_groups:
group_name = filtered_groups.pop().name
print(group_name)
group = filtered_groups.pop()
print(group)
else:
error = f"No project named '{filter_group_name}' found"
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 +97,20 @@ def main():
for group in matching_groups:
print(group.name)

print("----")
# or, try the above with the django style filtering.

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"):
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)

for group in server.groups.filter(name__in=groups).order_by("-name"):
print(group.name)

print("done")


if __name__ == "__main__":
main()
Loading