8000 Remove sample code showing group name encoding (#1486) · TrimPeachu/server-client-python@b65d8d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b65d8d4

Browse files
authored
Remove sample code showing group name encoding (tableau#1486)
* Remove sample code showing group name encoding This is no longer needed - ran the sample and verified that it works now.
1 parent 63ece82 commit b65d8d4

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

samples/filter_sort_groups.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def main():
4747
logging.basicConfig(level=logging_level)
4848

4949
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
50-
server = TSC.Server(args.server, use_server_version=True)
50+
server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False})
5151
with server.auth.sign_in(tableau_auth):
5252
group_name = "SALES NORTHWEST"
5353
# Try to create a group named "SALES NORTHWEST"
@@ -57,37 +57,36 @@ def main():
5757
# Try to create a group named "SALES ROMANIA"
5858
create_example_group(group_name, server)
5959

60-
# URL Encode the name of the group that we want to filter on
61-
# i.e. turn spaces into plus signs
62-
filter_group_name = urllib.parse.quote_plus(group_name)
60+
# we no longer need to encode the space
6361
options = TSC.RequestOptions()
64-
options.filter.add(
65-
TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, filter_group_name)
66-
)
62+
options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, group_name))
6763

6864
filtered_groups, _ = server.groups.get(req_options=options)
6965
# Result can either be a matching group or an empty list
7066
if filtered_groups:
71-
group_name = filtered_groups.pop().name
72-
print(group_name)
67+
group = filtered_groups.pop()
68+
print(group)
7369
else:
74-
error = f"No project named '{filter_group_name}' found"
70+
error = f"No group named '{group_name}' found"
7571
print(error)
7672

73+
print("---")
74+
7775
# Or, try the above with the django style filtering
7876
try:
79-
group = server.groups.filter(name=filter_group_name)[0]
77+
group = server.groups.filter(name=group_name)[0]
78+
print(group)
8079
except IndexError:
81-
print(f"No project named '{filter_group_name}' found")
82-
else:
83-
print(group.name)
80+
print(f"No group named '{group_name}' found")
81+
82+
print("====")
8483

8584
options = TSC.RequestOptions()
8685
options.filter.add(
8786
TSC.Filter(
8887
TSC.RequestOptions.Field.Name,
8988
TSC.RequestOptions.Operator.In,
90-
["SALES+NORTHWEST", "SALES+ROMANIA", "this_group"],
89+
["SALES NORTHWEST", "SALES ROMANIA", "this_group"],
9190
)
9291
)
9392

@@ -98,13 +97,20 @@ def main():
9897
for group in matching_groups:
9998
print(group.name)
10099

100+
print("----")
101101
# or, try the above with the django style filtering.
102-
103-
groups = ["SALES NORTHWEST", "SALES ROMANIA", "this_group"]
104-
groups = [urllib.parse.quote_plus(group) for group in groups]
105-
for group in server.groups.filter(name__in=groups).sort("-name"):
102+
all_g = server.groups.all()
103+
print(f"Searching locally among {all_g.total_available} groups")
104+
for a in all_g:
105+
print(a)
106+
groups = [urllib.parse.quote_plus(group) for group in ["SALES NORTHWEST", "SALES ROMANIA", "this_group"]]
107+
print(groups)
108+
109+
for group in server.groups.filter(name__in=groups).order_by("-name"):
106110
print(group.name)
107111

112+
print("done")
113+
108114

109115
if __name__ == "__main__":
110116
main()

0 commit comments

Comments
 (0)
0