From abff5e5879222e90c0dd1a4cf0fc8883fb56d876 Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Tue, 19 Oct 2021 00:15:08 -0700 Subject: [PATCH 1/3] add publish-samples option to create/update project --- contributing.md | 5 +++++ samples/create_project.py | 19 ++++++++++++------- .../server/endpoint/endpoint.py | 2 ++ .../server/endpoint/projects_endpoint.py | 14 ++++++++------ tableauserverclient/server/request_options.py | 1 + 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/contributing.md b/contributing.md index 3d5cd3d43..fc8502b11 100644 --- a/contributing.md +++ b/contributing.md @@ -62,6 +62,11 @@ python setup.py build python setup.py test ``` +### To use your locally built version +```shell +pip install . +``` + ### Before Committing Our CI runs include a Python lint run, so you should run this locally and fix complaints before committing as this will fail your checkin. diff --git a/samples/create_project.py b/samples/create_project.py index 814d35617..ffb66b84d 100644 --- a/samples/create_project.py +++ b/samples/create_project.py @@ -14,9 +14,9 @@ import tableauserverclient as TSC -def create_project(server, project_item): +def create_project(server, project_item, samples=False): try: - project_item = server.projects.create(project_item) + project_item = server.projects.create(project_item, samples) print('Created a new project called: %s' % project_item.name) return project_item except TSC.ServerResponseError: @@ -45,23 +45,28 @@ 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) + server.add_http_options({'verify': False}) + server.use_server_version() with server.auth.sign_in(tableau_auth): # Use highest Server REST API version available server.use_server_version() # Without parent_id specified, projects are created at the top level. - top_level_project = TSC.ProjectItem(name='Top Level Project') + top_level_project = TSC.ProjectItem(name='TPL2') top_level_project = create_project(server, top_level_project) # Specifying parent_id creates a nested projects. - child_project = TSC.ProjectItem(name='Child Project', parent_id=top_level_project.id) - child_project = create_project(server, child_project) + child_project = TSC.ProjectItem(name='CPL2', parent_id=top_level_project.id) + child_project = create_project(server, child_project, samples=True) # Projects can be nested at any level. - grand_child_project = TSC.ProjectItem(name='Grand Child Project', parent_id=child_project.id) + grand_child_project = TSC.ProjectItem(name='GCPL', parent_id=child_project.id) grand_child_project = create_project(server, grand_child_project) + # Projects can be updated + changed_project = server.projects.update(grand_child_project, samples=True) + if __name__ == '__main__': main() diff --git a/tableauserverclient/server/endpoint/endpoint.py b/tableauserverclient/server/endpoint/endpoint.py index 31291abc9..b74843d4c 100644 --- a/tableauserverclient/server/endpoint/endpoint.py +++ b/tableauserverclient/server/endpoint/endpoint.py @@ -18,6 +18,8 @@ Success_codes = [200, 201, 202, 204] +XML_CONTENT_TYPE = "text/xml" +JSON_CONTENT_TYPE = "application/json" class Endpoint(object): def __init__(self, parent_srv): diff --git a/tableauserverclient/server/endpoint/projects_endpoint.py b/tableauserverclient/server/endpoint/projects_endpoint.py index 72286e570..782a21654 100644 --- a/tableauserverclient/server/endpoint/projects_endpoint.py +++ b/tableauserverclient/server/endpoint/projects_endpoint.py @@ -1,9 +1,9 @@ -from .endpoint import api, Endpoint +from .endpoint import api, Endpoint, XML_CONTENT_TYPE from .exceptions import MissingRequiredFieldError from .permissions_endpoint import _PermissionsEndpoint from .default_permissions_endpoint import _DefaultPermissionsEndpoint -from .. import RequestFactory, ProjectItem, PaginationItem, Permission +from .. import RequestFactory, RequestOptions, ProjectItem, PaginationItem, Permission import logging @@ -40,23 +40,25 @@ def delete(self, project_id): logger.info("Deleted single project (ID: {0})".format(project_id)) @api(version="2.0") - def update(self, project_item): + def update(self, project_item, samples=False): if not project_item.id: error = "Project item missing ID." raise MissingRequiredFieldError(error) + params = {"params": {RequestOptions.Field.PublishSamples: samples }} url = "{0}/{1}".format(self.baseurl, project_item.id) update_req = RequestFactory.Project.update_req(project_item) - server_response = self.put_request(url, update_req) + server_response = self.put_request(url, update_req, XML_CONTENT_TYPE, params) logger.info("Updated project item (ID: {0})".format(project_item.id)) updated_project = ProjectItem.from_response(server_response.content, self.parent_srv.namespace)[0] return updated_project @api(version="2.0") - def create(self, project_item): + def create(self, project_item, samples=False): + params = {"params": {RequestOptions.Field.PublishSamples: samples }} url = self.baseurl create_req = RequestFactory.Project.create_req(project_item) - server_response = self.post_request(url, create_req) + server_response = self.post_request(url, create_req, XML_CONTENT_TYPE, params) new_project = ProjectItem.from_response(server_response.content, self.parent_srv.namespace)[0] logger.info("Created new project (ID: {0})".format(new_project.id)) return new_project diff --git a/tableauserverclient/server/request_options.py b/tableauserverclient/server/request_options.py index 3047691a9..36ffccd8e 100644 --- a/tableauserverclient/server/request_options.py +++ b/tableauserverclient/server/request_options.py @@ -48,6 +48,7 @@ class Field: OwnerName = "ownerName" Progress = "progress" ProjectName = "projectName" + PublishSamples = "publishSamples" SiteRole = "siteRole" Subtitle = "subtitle" Tags = "tags" From 4c542c5e28fce6151c11d62083090b46a5f55599 Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Tue, 19 Oct 2021 13:12:39 -0700 Subject: [PATCH 2/3] revert changes to sample --- issue_checking.py | 15 +++++++++++++++ samples/create_project.py | 7 +++---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 issue_checking.py diff --git a/issue_checking.py b/issue_checking.py new file mode 100644 index 000000000..d08e3a04d --- /dev/null +++ b/issue_checking.py @@ -0,0 +1,15 @@ +import tableauserverclient as TSC +from pprint import pprint + + +tableau_auth = TSC.TableauAuth('jfitzgerald', 'Rowan1S@sha2!VanShort') +server = TSC.Server('https://qa-near.tsi.lan') +server.add_http_options({'verify': False}) + +with server.auth.sign_in(tableau_auth): + all_users, pagination_item = server.users.get() + for user_item in all_users: + pprint(vars(user_item)) + #print("User name: '{}' fullname: '{}', User email: '{}'".format(user_item.name, + # user_item.fullname, + # user_item.email)) \ No newline at end of file diff --git a/samples/create_project.py b/samples/create_project.py index ffb66b84d..6ed659ee9 100644 --- a/samples/create_project.py +++ b/samples/create_project.py @@ -46,22 +46,21 @@ def main(): tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) server = TSC.Server(args.server) - server.add_http_options({'verify': False}) server.use_server_version() with server.auth.sign_in(tableau_auth): # Use highest Server REST API version available server.use_server_version() # Without parent_id specified, projects are created at the top level. - top_level_project = TSC.ProjectItem(name='TPL2') + top_level_project = TSC.ProjectItem(name='Top Level Project') top_level_project = create_project(server, top_level_project) # Specifying parent_id creates a nested projects. - child_project = TSC.ProjectItem(name='CPL2', parent_id=top_level_project.id) + child_project = TSC.ProjectItem(name='Child Project', parent_id=top_level_project.id) child_project = create_project(server, child_project, samples=True) # Projects can be nested at any level. - grand_child_project = TSC.ProjectItem(name='GCPL', parent_id=child_project.id) + grand_child_project = TSC.ProjectItem(name='Grand Child Project', parent_id=child_project.id) grand_child_project = create_project(server, grand_child_project) # Projects can be updated From 0a050668d9faf4d700e146240f95fe00441ee839 Mon Sep 17 00:00:00 2001 From: Jac Date: Tue, 19 Oct 2021 13:15:26 -0700 Subject: [PATCH 3/3] Delete issue_checking.py accidental checkin of scratch file --- issue_checking.py | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 issue_checking.py diff --git a/issue_checking.py b/issue_checking.py deleted file mode 100644 index d08e3a04d..000000000 --- a/issue_checking.py +++ /dev/null @@ -1,15 +0,0 @@ -import tableauserverclient as TSC -from pprint import pprint - - -tableau_auth = TSC.TableauAuth('jfitzgerald', 'Rowan1S@sha2!VanShort') -server = TSC.Server('https://qa-near.tsi.lan') -server.add_http_options({'verify': False}) - -with server.auth.sign_in(tableau_auth): - all_users, pagination_item = server.users.get() - for user_item in all_users: - pprint(vars(user_item)) - #print("User name: '{}' fullname: '{}', User email: '{}'".format(user_item.name, - # user_item.fullname, - # user_item.email)) \ No newline at end of file