8000 Jac/publish samples (#918) · tableau/server-client-python@4007d3d · GitHub
[go: up one dir, main page]

Skip to content

Commit 4007d3d

Browse files
authored
Jac/publish samples (#918)
* add publish-samples option to create/update project
1 parent a899a95 commit 4007d3d

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

contributing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ python setup.py build
6262
python setup.py test
6363
```
6464

65+
### To use your locally built version
66+
```shell
67+
pip install .
68+
```
69+
6570
### Before Committing
6671

6772
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.

samples/create_project.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import tableauserverclient as TSC
1515

1616

17-
def create_project(server, project_item):
17+
def create_project(server, project_item, samples=False):
1818
try:
19-
project_item = server.projects.create(project_item)
19+
project_item = server.projects.create(project_item, samples)
2020
print('Created a new project called: %s' % project_item.name)
2121
return project_item
2222
except TSC.ServerResponseError:
@@ -45,7 +45,8 @@ def main():
4545
logging.basicConfig(level=logging_level)
4646

4747
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
48-
server = TSC.Server(args.server, use_server_version=True)
48+
server = TSC.Server(args.server)
49+
server.use_server_version()
4950
with server.auth.sign_in(tableau_auth):
5051
# Use highest Server REST API version available
5152
server.use_server_version()
@@ -56,12 +57,15 @@ def main():
5657

5758
# Specifying parent_id creates a nested projects.
5859
child_project = TSC.ProjectItem(name='Child Project', parent_id=top_level_project.id)
59-
child_project = create_project(server, child_project)
60+
child_project = create_project(server, child_project, samples=True)
6061

6162
# Projects can be nested at any level.
6263
grand_child_project = TSC.ProjectItem(name='Grand Child Project', parent_id=child_project.id)
6364
grand_child_project = create_project(server, grand_child_project)
6465

66+
# Projects can be updated
67+
changed_project = server.projects.update(grand_child_project, samples=True)
68+
6569

6670
if __name__ == '__main__':
6771
main()

tableauserverclient/server/endpoint/endpoint.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
Success_codes = [200, 201, 202, 204]
2020

21+
XML_CONTENT_TYPE = "text/xml"
22+
JSON_CONTENT_TYPE = "application/json"
2123

2224
class Endpoint(object):
2325
def __init__(self, parent_srv):

tableauserverclient/server/endpoint/projects_endpoint.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from .endpoint import api, Endpoint
1+
from .endpoint import api, Endpoint, XML_CONTENT_TYPE
22
from .exceptions import MissingRequiredFieldError
33
from .permissions_endpoint import _PermissionsEndpoint
44
from .default_permissions_endpoint import _DefaultPermissionsEndpoint
55

6-
from .. import RequestFactory, ProjectItem, PaginationItem, Permission
6+
from .. import RequestFactory, RequestOptions, ProjectItem, PaginationItem, Permission
77

88
import logging
99

@@ -40,23 +40,25 @@ def delete(self, project_id):
4040
logger.info("Deleted single project (ID: {0})".format(project_id))
4141

4242
@api(version="2.0")
43-
def update(self, project_item):
43+
def update(self, project_item, samples=False):
4444
if not project_item.id:
4545
error = "Project item missing ID."
4646
raise MissingRequiredFieldError(error)
4747

48+
params = {"params": {RequestOptions.Field.PublishSamples: samples }}
4849
url = "{0}/{1}".format(self.baseurl, project_item.id)
4950
update_req = RequestFactory.Project.update_req(project_item)
50-
server_response = self.put_request(url, update_req)
51+
server_response = self.put_request(url, update_req, XML_CONTENT_TYPE, params)
5152
logger.info("Updated project item (ID: {0})".format(project_item.id))
5253
updated_project = ProjectItem.from_response(server_response.content, self.parent_srv.namespace)[0]
5354
return updated_project
5455

5556
@api(version="2.0")
56-
def create(self, project_item):
57+
def create(self, project_item, samples=False):
58+
params = {"params": {RequestOptions.Field.PublishSamples: samples }}
5759
url = self.baseurl
5860
create_req = RequestFactory.Project.create_req(project_item)
59-
server_response = self.post_request(url, create_req)
61+
server_response = self.post_request(url, create_req, XML_CONTENT_TYPE, params)
6062
new_project = ProjectItem.from_response(server_response.content, self.parent_srv.namespace)[0]
6163
logger.info("Created new project (ID: {0})".format(new_project.id))
6264
return new_project

tableauserverclient/server/request_options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Field:
4848
OwnerName = "ownerName"
4949< 5420 code class="diff-text syntax-highlighted-line">
Progress = "progress"
5050
ProjectName = "projectName"
51+
PublishSamples = "publishSamples"
5152
SiteRole = "siteRole"
5253
Subtitle = "subtitle"
5354
Tags = "tags"

0 commit comments

Comments
 (0)
0