From 986737e667a71279a5d69de3237b8af73f586cb9 Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Mon, 31 Jul 2023 13:53:15 -0700 Subject: [PATCH] Add publish samples attribute --- samples/create_project.py | 9 ++++++++- tableauserverclient/models/project_item.py | 2 ++ tableauserverclient/server/endpoint/projects_endpoint.py | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/samples/create_project.py b/samples/create_project.py index 611dbe366..1fc649f8c 100644 --- a/samples/create_project.py +++ b/samples/create_project.py @@ -57,7 +57,14 @@ def main(): server.use_server_version() # Without parent_id specified, projects are created at the top level. - top_level_project = TSC.ProjectItem(name="Top Level Project") + # With the publish-samples attribute, the project will be created with sample items + top_level_project = TSC.ProjectItem( + name="Top Level Project", + description="A sample tsc project", + content_permissions=None, + parent_id=None, + samples=True, + ) top_level_project = create_project(server, top_level_project) # Specifying parent_id creates a nested projects. diff --git a/tableauserverclient/models/project_item.py b/tableauserverclient/models/project_item.py index 393a7990f..e7254ab5d 100644 --- a/tableauserverclient/models/project_item.py +++ b/tableauserverclient/models/project_item.py @@ -25,6 +25,7 @@ def __init__( description: Optional[str] = None, content_permissions: Optional[str] = None, parent_id: Optional[str] = None, + samples: Optional[bool] = None, ) -> None: self._content_permissions = None self._id: Optional[str] = None @@ -32,6 +33,7 @@ def __init__( self.name: str = name self.content_permissions: Optional[str] = content_permissions self.parent_id: Optional[str] = parent_id + self._samples: Optional[bool] = samples self._permissions = None self._default_workbook_permissions = None diff --git a/tableauserverclient/server/endpoint/projects_endpoint.py b/tableauserverclient/server/endpoint/projects_endpoint.py index 510f1ff3d..99bb2e39b 100644 --- a/tableauserverclient/server/endpoint/projects_endpoint.py +++ b/tableauserverclient/server/endpoint/projects_endpoint.py @@ -63,6 +63,8 @@ def update(self, project_item: ProjectItem, samples: bool = False) -> ProjectIte def create(self, project_item: ProjectItem, samples: bool = False) -> ProjectItem: params = {"params": {RequestOptions.Field.PublishSamples: samples}} url = self.baseurl + if project_item._samples: + url = "{0}?publishSamples={1}".format(self.baseurl, project_item._samples) create_req = RequestFactory.Project.create_req(project_item) 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]