8000 Django-style filters by scuml · Pull Request #615 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

Django-style filters #615

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

Merged
merged 13 commits into from
Oct 29, 2020
Merged

Conversation

scuml
Copy link
Contributor
@scuml scuml commented May 5, 2020

This adds a django-style filtering and sorting mechanism to tableau which significantly decreases implementation code complexity.

For instance, this:

request_options = tsc.RequestOptions()
request_options.filter.add(tsc.Filter(
    tsc.RequestOptions.Field.ProjectName, tsc.RequestOptions.Operator.Equals, project_name
))
request_options.sort.add(tsc.Sort(
    tsc.RequestOptions.Field.ProjectName, TSC.RequestOptions.Direction.Desc))
all_workbooks, pagination_item = server.workbooks.get(request_options)

...can now be written in one line:

all_workbooks = server.workbooks.filter(project_name=project_name).sort("-project_name")

This method returns a queryset, which can be iterated to access members.

for workbook in all_workbooks:
    print(workbook)

Full example...

# return queryset with no filters
workbooks = server.workbooks.all() 

# filters can be appended in new lines
workbooks = workbooks.filter(project_name=project_name)

# sort can take multiple args, with desc direction added as a (-) prefix 
workbooks = workbooks.sort("project_name", "-created_at")

# pagination take these two keywords
workbooks = workbooks.paginate(page_size=10, page_number=2) 

# query is executed at time of access
for workbook in workbooks: 
    print(workbook)

# pagination item is still accessible  
print(workbooks.total_available, workbooks.page_size, workbooks.page_number) 

# methods can be chained
all_workbooks = server.workbooks.filter(project_name=project_name).sort("-project_name")

# operators are implemented using dunderscore
all_workbooks = server.workbooks.filter(project_name__in=["Project A", "Project B"])


Documentation will need to be updated if accepted.

Chris Shin and others added 12 commits October 4, 2019 14:20
Release v0.9
## 0.9 (4 Oct 2019)

* Added Metadata API endpoints (tableau#431)
* Added site settings for Data Catalog and Prep Conductor (tableau#434)
* Added new fields to ViewItem (tableau#331)
* Added support and samples for Tableau Server Personal Access Tokens (tableau#465)
* Added Permissions endpoints (tableau#429)
* Added tags to ViewItem (tableau#470)
* Added Databases and Tables endpoints (tableau#445)
* Added Flow endpoints (tableau#494)
* Added ability to filter projects by topLevelProject attribute (tableau#497)
* Improved server_info endpoint error handling (tableau#439)
* Improved Pager to take in keyword arguments (tableau#451)
* Fixed UUID serialization error while publishing workbook (tableau#449)
* Fixed materalized views in request body for update_workbook (tableau#461)
* delete folder

* add back readme for docs
Merging v0.10 changes from development to master

* Added a way to handle non-xml errors (tableau#515)
* Added Webhooks endpoints for create, delete, get, list, and test (tableau#523, tableau#532)
* Added delete method in the tasks endpoint (tableau#524)
* Added description attribute to WorkbookItem (tableau#533)
* Added support for materializeViews as schedule and task types (tableau#542)
* Added warnings to schedules (tableau#550, tableau#551)
* Added ability to update parent_id attribute of projects (tableau#560, tableau#567)
* Improved filename behavior for download endpoints (tableau#517)
* Improved logging (tableau#508)
* Fixed runtime error in permissions endpoint (tableau#513)
* Fixed move_workbook_sites sample (tableau#503)
* Fixed project permissions endpoints (tableau#527)
* Fixed login.py sample to accept site name (tableau#549)
The logger statement is using the parameter to output the id of the user, but that isnt set until line 67 and saved to a new variable. We want the logger statement to use that new user
Merge development into master for v0.11 release

v0.11 (1 May 2020)

-Added more fields to Data Acceleration config (tableau#588)
-Added OpenID as an auth setting enum (tableau#610)
-Added support for Data Acceleration Reports (tableau#596)
-Added support for view permissions (tableau#526)
-Materialized views changed to Data Acceleration (tableau#576)
-Improved consistency across workbook/datasource endpoints (tableau#570)
-Fixed print error in update_connection.py (tableau#602)
-Fixed log error in add user endpoint (tableau#608)
@t8y8 t8y8 requested a review from graysonarts May 12, 2020 17:44
@scuml
Copy link
Contributor Author
scuml commented Jun 2, 2020

Looking for repo owners to take a look at this and comment/merge.

@jorwoods
Copy link
Contributor
jorwoods commented Aug 8, 2020

This will be really handy, and remove the need for some custom code to enact filters.

@bcantoni
Copy link
Contributor

@shinchris and @RussTheAerialist please review.

@bcantoni bcantoni requested a review from shinchris August 14, 2020 20:54
@shinchris
Copy link
Contributor

Overall, looks good to me. It will definitely make querying a lot simpler, especially with filtering and sorting. And allows the old methods to continue to work.

@RussTheAerialist what are you thoughts on style for querying?

@scuml
Copy link
Contributor Author
scuml commented Oct 27, 2020

@RussTheAerialist Would you be able to look at this?

@graysonarts
Copy link
Contributor

Sorry for the delay in reviewing, at the surface this looks great, I need to spend a little more time to think through implications around compatibility with the original implementation. I also validated that we have a valid CLA signed for this change.

Copy link
Contributor
@graysonarts graysonarts left a comment

Choose a reason for hiding this comment

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

Yup, I have no concerns on backcompat, so I'm going to merge this in. Thank you @scuml for the amazing contribution!

@graysonarts graysonarts merged commit 87b7456 into tableau:development Oct 29, 2020
This was referenced Nov 6, 2020
@abubakar343
Copy link

This code filters the views. But how can we filter a specific view? For example, I have view which has multiple regions and I want to fetch the view where regions=='UK' for example.

@jorwoods
Copy link
Contributor

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.

7 participants
0