-
Notifications
You must be signed in to change notification settings - Fork 447
Support favorites retrieval and modification #591
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
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d49acbb
Create FavoriteRequest factory
c135ce1
Create favorites_endpoint
75ec3f5
Enable addition of favorites
0bcd050
Enabled deletion of favorites
969ee26
Fix XML response calls
9023ffa
Genericize descriptor
jorwoods fcbce9d
Fix typo
jorwoods d4259ee
Remove outdated content
jorwoods 13b025e
Use more descriptive variable names
jorwoods 214b36a
Adjust API version
jorwoods afcf234
Create Favorite "enum"
jorwoods b4f775e
Factor response parsing logic to model
jorwoods 5ffee44
Test favorites.get
jorwoods 1520060
Test adding a favorite workbook
jorwoods b2c4989
Test adding favorite view
jorwoods 0cae6c6
Test adding favorite data source
jorwoods 961fac1
Test adding favorite project
jorwoods f5f5917
Test favorite deletion
jorwoods 4f9ca59
Expand favorites test_get
jorwoods 40cd444
Unpack list of views in class method response
jorwoods 5ce527a
Add Favorites back to import
301c257
Repalce deprecated assertEquals with assertEqual
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import xml.etree.ElementTree as ET | ||
| import logging | ||
| from .workbook_item import WorkbookItem | ||
| from .view_item import ViewItem | ||
| from .project_item import ProjectItem | ||
| from .datasource_item import DatasourceItem | ||
|
|
||
| logger = logging.getLogger('tableau.models.favorites_item') | ||
|
|
||
|
|
||
| class Favorite: | ||
| Workbook = 'workbook' | ||
| Datasource = 'datasource' | ||
| View = 'view' | ||
| Project = 'project' | ||
|
|
||
|
|
||
| def get_favorites(server_response, namespace): | ||
| favorites = { | ||
| 'datasources': [], | ||
| 'projects': [], | ||
| 'views': [], | ||
| 'workbooks': [], | ||
| } | ||
|
|
||
| parsed_response = ET.fromstring(server_response.content) | ||
| for workbook in parsed_response.findall('.//t:favorite/t:workbook', namespace): | ||
| fav_workbook = WorkbookItem('') | ||
| fav_workbook._set_values(*fav_workbook._parse_element(workbook, namespace)) | ||
| if fav_workbook: | ||
| favorites['workbooks'].append(fav_workbook) | ||
| for view in parsed_response.findall('.//t:favorite[t:view]', namespace): | ||
| fav_views = ViewItem.from_xml_element(view, namespace) | ||
| if fav_views: | ||
| for fav_view in fav_views: | ||
| favorites['views'].append(fav_view) | ||
| for datasource in parsed_response.findall('.//t:favorite/t:datasource', namespace): | ||
| fav_datasource = DatasourceItem('') | ||
| fav_datasource._set_values(*fav_datasource._parse_element(datasource, namespace)) | ||
| if fav_datasource: | ||
| favorites['datasources'].append(fav_datasource) | ||
| for project in parsed_response.findall('.//t:favorite/t:project', namespace): | ||
| fav_project = ProjectItem('p') | ||
| fav_project._set_values(*fav_project._parse_element(project)) | ||
| if fav_project: | ||
| favorites['projects'].append(fav_project) | ||
|
|
||
| return favorites |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| from .endpoint import Endpoint, api | ||
| from .exceptions import MissingRequiredFieldError | ||
| from .. import RequestFactory | ||
| from ...models import get_favorites | ||
| from ..pager import Pager | ||
| import xml.etree.ElementTree as ET | ||
| import logging | ||
| import copy | ||
|
|
||
| logger = logging.getLogger('tableau.endpoint.favorites') | ||
|
|
||
|
|
||
| class Favorites(Endpoint): | ||
| @property | ||
| def baseurl(self): | ||
| return "{0}/sites/{1}/favorites".format(self.parent_srv.baseurl, self.parent_srv.site_id) | ||
|
|
||
| # Gets all favorites | ||
| @api(version="2.5") | ||
| def get(self, user_item, req_options=None): | ||
| logger.info('Querying all favorites for user {0}'.format(user_item.name)) | ||
| url = '{0}/{1}'.format(self.baseurl, user_item.id) | ||
| server_response = self.get_request(url, req_options) | ||
|
|
||
| user_item._favorites = get_favorites(server_response, self.parent_srv.namespace) | ||
|
|
||
| @api(version="2.0") | ||
| def add_favorite_workbook(self, user_item, workbook_item): | ||
| url = '{0}/{1}'.format(self.baseurl, user_item.id) | ||
| add_req = RequestFactory.Favorite.add_workbook_req(workbook_item.id, workbook_item.name) | ||
| server_response = self.put_request(url, add_req) | ||
| logger.info('Favorited {0} for user (ID: {1})'.format(workbook_item.name, user_item.id)) | ||
|
|
||
| @api(version="2.0") | ||
| def add_favorite_view(self, user_item, view_item): | ||
| url = '{0}/{1}'.format(self.baseurl, user_item.id) | ||
| add_req = RequestFactory.Favorite.add_view_req(view_item.id, view_item.name) | ||
| server_response = self.put_request(url, add_req) | ||
| logger.info('Favorited {0} for user (ID: {1})'.format(view_item.name, user_item.id)) | ||
|
|
||
| @api(version="2.3") | ||
| def add_favorite_datasource(self, user_item, datasource_item): | ||
| url = '{0}/{1}'.format(self.baseurl, user_item.id) | ||
| add_req = RequestFactory.Favorite.add_datasource_req(datasource_item.id, datasource_item.name) | ||
| server_response = self.put_request(url, add_req) | ||
| logger.info('Favorited {0} for user (ID: {1})'.format(datasource_item.name, user_item.id)) | ||
|
|
||
| @api(version="3.1") | ||
| def add_favorite_project(self, user_item, project_item): | ||
| url = '{0}/{1}'.format(self.baseurl, user_item.id) | ||
| add_req = RequestFactory.Favorite.add_project_req(project_item.id, project_item.name) | ||
| server_response = self.put_request(url, add_req) | ||
| logger.info('Favorited {0} for user (ID: {1})'.format(project_item.name, user_item.id)) | ||
|
|
||
| @api(version="2.0") | ||
| def delete_favorite_workbook(self, user_item, workbook_item): | ||
| url = '{0}/{1}/workbooks/{2}'.format(self.baseurl, user_item.id, workbook_item.id) | ||
| logger.info('Removing favorite {0} for user (ID: {1})'.format(workbook_item.id, user_item.id)) | ||
| self.delete_request(url) | ||
|
|
||
| @api(version="2.0") | ||
| def delete_favorite_view(self, user_item, view_item): | ||
| url = '{0}/{1}/views/{2}'.format(self.baseurl, user_item.id, view_item.id) | ||
| logger.info('Removing favorite {0} for user (ID: {1})'.format(view_item.id, user_item.id)) | ||
| self.delete_request(url) | ||
|
|
||
| @api(version="2.3") | ||
| def delete_favorite_datasource(self, user_item, datasource_item): | ||
| url = '{0}/{1}/datasources/{2}'.format(self.baseurl, user_item.id, datasource_item.id) | ||
| logger.info('Removing favorite {0} for user (ID: {1})'.format(datasource_item.id, user_item.id)) | ||
| self.delete_request(url) | ||
|
|
||
| @api(version="3.1") | ||
| def delete_favorite_project(self, user_item, project_item): | ||
| url = '{0}/{1}/projects/{2}'.format(self.baseurl, user_item.id, project_item.id) | ||
| logger.info('Removing favorite {0} for user (ID: {1})'.format(project_item.id, user_item.id)) | ||
| self.delete_request(url) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version='1.0' encoding='UTF-8'?> | ||
| <tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.3.xsd"> | ||
| <favorites> | ||
| <favorite> | ||
| <datasource id="e76a1461-3b1d-4588-bf1b-17551a879ad9" | ||
| name="SampleDS" | ||
| contentUrl="SampleDS" | ||
| type="dataengine" | ||
| createdAt="2016-08-11T21:22:40Z" | ||
| updatedAt="2016-08-11T21:34:17Z"> | ||
| <project id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760" name="default" /> | ||
| <owner id="5de011f8-5aa9-4d5b-b991-f462c8dd6bb7" /> | ||
| <tags /> | ||
| </datasource> | ||
| </favorite> | ||
| </favorites> | ||
| </tsResponse> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version='1.0' encoding='UTF-8'?> | ||
| <tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.3.xsd"> | ||
| <favorites> | ||
| <favorite> | ||
| <project id="1d0304cd-3796-429f-b815-7258370b9b74" | ||
| name="Tableau" | ||
| description="" | ||
| contentPermissions="ManagedByOwner" /> | ||
| </favorite> | ||
| </favorites> | ||
| </tsResponse> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <tsResponse> | ||
| <favorites> | ||
| <favorite label="favorite-labe1"> | ||
| <view id="d79634e1-6063-4ec9-95ff-50acbf609ff5" | ||
| name="ENDANGERED SAFARI" | ||
| contentUrl="SafariSample/sheets/ENDANGEREDSAFARI" | ||
| createdAt="2016-08-03T20:34:04Z" | ||
| updatedAt="2016-08-04T17:56:41Z" | ||
| viewUrlName="view-url-name"> | ||
| <workbook id="3cc6cd06-89ce-4fdc-b935-5294135d6d42"/> | ||
| <project id="5241e88d-d384-4fd7-9c2f-648b5247efc5"/> | ||
| <tags /> | ||
| </view> | ||
| </tsResponse> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version='1.0' encoding='UTF-8'?> | ||
| <tsResponse xmlns="http://tableau.com/api" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.3.xsd"> | ||
| <favorites> | ||
| <favorite label="Superstore"> | ||
| <workbook id="6d13b0ca-043d-4d42-8c9d-3f3313ea3a00" | ||
| name="Superstore" | ||
| description="description for Superstore" | ||
| contentUrl="Superstore" | ||
| showTabs="false" | ||
| size="1" | ||
| createdAt="2016-08-03T20:34:04Z" | ||
| updatedAt="2016-08-04T17:56:41Z"> | ||
| <project id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760" name="default" /> | ||
| <owner id="5de011f8-5aa9-4d5b-b991-f462c8dd6bb7" /> | ||
| <tags /> | ||
| </workbook> | ||
| </favorite> | ||
| </favorites> | ||
| </tsResponse> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?xml version='1.0' encoding='UTF-8'?> | ||
| <tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.3.xsd"> | ||
| <favorites> | ||
| <favorite label="favorite-label"> | ||
| <view id="d79634e1-6063-4ec9-95ff-50acbf609ff5" | ||
| name="ENDANGERED SAFARI" | ||
| contentUrl="SafariSample/sheets/ENDANGEREDSAFARI"> | ||
| <workbook id="3cc6cd06-89ce-4fdc-b935-5294135d6d42" /> | ||
| <owner id="5de011f8-5aa9-4d5b-b991-f462c8dd6bb7" /> | ||
| <project id="5241e88d-d384-4fd7-9c2f-648b5247efc5" /> | ||
| <tags /> | ||
| </view> | ||
| </favorite> | ||
| <favorite> | ||
| <workbook id="6d13b0ca-043d-4d42-8c9d-3f3313ea3a00" | ||
| name="Superstore" | ||
| description="description for Superstore" | ||
| contentUrl="Superstore" | ||
| showTabs="false" | ||
| size="1" | ||
| createdAt="2016-08-03T20:34:04Z" | ||
| updatedAt="2016-08-04T17:56:41Z"> | ||
| <project id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760" name="default" /> | ||
| <owner id="5de011f8-5aa9-4d5b-b991-f462c8dd6bb7" /> | ||
| <tags /> | ||
| </workbook> | ||
| </favorite> | ||
| <favorite> | ||
| <project id="1d0304cd-3796-429f-b815-7258370b9b74" | ||
| name="Tableau" | ||
| description="" | ||
| contentPermissions="ManagedByOwner" /> | ||
| </favorite> | ||
| <favorite> | ||
| <datasource id="e76a1461-3b1d-4588-bf1b-17551a879ad9" | ||
| name="SampleDS" | ||
| contentUrl="SampleDS" | ||
| type="dataengine" | ||
| createdAt="2016-08-11T21:22:40Z" | ||
| updatedAt="2016-08-11T21:34:17Z"> | ||
| <project id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760" name="default" /> | ||
| <owner id="5de011f8-5aa9-4d5b-b991-f462c8dd6bb7" /> | ||
| <tags /> | ||
| </datasource> | ||
| </favorite> | ||
| </favorites> | ||
| </tsResponse> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.