Skip to content

Commit

Permalink
Add publish samples attribute (#1264)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacalata authored Aug 1, 2023
1 parent 4caf0a5 commit 2821592
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion samples/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions tableauserverclient/models/project_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ 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
self.description: Optional[str] = description
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
Expand Down
2 changes: 2 additions & 0 deletions tableauserverclient/server/endpoint/projects_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 2821592

Please sign in to comment.