Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Sample group filtering#199

Merged
acpana merged 6 commits intotableau:developmenttableau/server-client-python:developmentfrom
acpana:sample_group_filteringacpana/server-client-python:sample_group_filteringCopy head branch name to clipboard
Jun 23, 2017
Merged

Sample group filtering#199
acpana merged 6 commits intotableau:developmenttableau/server-client-python:developmentfrom
acpana:sample_group_filteringacpana/server-client-python:sample_group_filteringCopy head branch name to clipboard

Conversation

@acpana
Copy link

@acpana acpana commented Jun 12, 2017

Added a script for group filtering.

@acpana acpana changed the base branch from master to development June 12, 2017 22:53
group1 = TSC.GroupItem(group_name)
group1 = server.groups.create(group1)
print(group1)
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should catch a specific set of exceptions rather than all of them


group_name = 'SALES+ROMANIA'
options = TSC.RequestOptions()
options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment to explain what you are going here

@acpana
Copy link
Author

acpana commented Jun 14, 2017

Just pushed a commit addressing past feedback.

Copy link
Collaborator

@t8y8 t8y8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits but I think they're worth it

parser.add_argument('-p', default=None)
args = parser.parse_args()

password = ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary, the if/then should catch all cases

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, you mean it is not necessary to set passsword = '' ?

Copy link
Collaborator

@t8y8 t8y8 Jun 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, password gets set in all cases because args.p is either None, or it isn't.

So the initial password = '' is redundant. It doesn't hurt anything either :P

try:
group1 = TSC.GroupItem(group_name)
group1 = server.groups.create(group1)
print(group1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to print something more meaningful than the repr of a group?

eg "Group created: "

try:
group2 = TSC.GroupItem(group_name)
group2 = server.groups.create(group2)
print(group2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

TSC.RequestOptions.Operator.Equals,
filter_group_name))

filtered_group_paged = server.groups.get(req_options=options)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pager again (Samples aren't always just run against new servers, often it's existing servers)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore -- this is filtered

filtered_group_paged = server.groups.get(req_options=options)

# Return type is a tuple with the first entry as a list of matching groups
print(filtered_group_paged[0][0].name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tuple unpacking or comment please


filtered_groups, _ = server.groups.get(req_options=options)
# Result can either be a matching group or none
group_name = filtered_groups.pop().name if len(filtered_groups) != 0 else 'No project named \'' + str(filter_group_name) + '\' found '
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if filtered_groups:
    group_name = filtered_groups.pop()
else:
    error = "No project named '{}' found".format(filter_group_name)
    print(error)

Reads cleaner to me, then we aren't overloading the group_name as either a name OR an error string.

Empty lists in python are false-y, so you can just truth test it (if filtered_groups). Or there's a bug, because len(None) will through an error.

I may run over to clarify some things

Copy link
Collaborator

@t8y8 t8y8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One final nit.

🚀

import tableauserverclient as TSC


def create_example_group(group_name='Example Group', server=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None isn't actually a safe default, this should just be a standard required parameter.

@acpana acpana merged commit f82f2f9 into tableau:development Jun 23, 2017
t8y8 pushed a commit to t8y8/server-client-python that referenced this pull request Jun 28, 2017
* Sample group filtering script

* Added comments and specific error catching

* Renamed the file to follow the naming convention

* commented on return type, example group creation, cleaned up code

* Better way to call and catch return from rest api

* Proper printing instructions
t8y8 pushed a commit to t8y8/server-client-python that referenced this pull request Jun 28, 2017
* Sample group filtering script

* Added comments and specific error catching

* Renamed the file to follow the naming convention

* commented on return type, example group creation, cleaned up code

* Better way to call and catch return from rest api

* Proper printing instructions
bryceglarsen pushed a commit to bryceglarsen/server-client-python that referenced this pull request Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.