8000 Jac/publish samples by jacalata · Pull Request #918 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

Jac/publish samples #918

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

Merged
merged 3 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 8 additions & 4 deletions samples/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -45,7 +45,8 @@ 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.use_server_version()
Comment on lines -48 to +49
Co 8000 py link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imperfect undo. But it does make it easier to insert the ssl change for local testing :)

with server.auth.sign_in(tableau_auth):
# Use highest Server REST API version available
server.use_server_version()
Expand All @@ -56,12 +57,15 @@ def main():

# 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 = 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 = create_project(server, grand_child_project)

# Projects can be updated
changed_project = server.projects.update(grand_child_project, samples=True)


if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions tableauserverclient/server/endpoint/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 8 additions & 6 deletions tableauserverclient/server/endpoint/projects_endpoint.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tableauserverclient/server/request_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Field:
OwnerName = "ownerName"
Progress = "progress"
ProjectName = "projectName"
PublishSamples = "publishSamples"
SiteRole = "siteRole"
Subtitle = "subtitle"
Tags = "tags"
Expand Down
0