8000 Adds hidden_views parameter to publish() (#614) · shiv-io/server-client-python@896a92b · GitHub
[go: up one dir, main page]

Skip to content

Commit 896a92b

Browse files
scumlChris ShinjacalataReba Magier
authored
Adds hidden_views parameter to publish() (tableau#614)
* delete docs folder from master (tableau#520) * delete folder * add back readme for docs * Fix logger statement in User.add (tableau#608) The logger statement is using the parameter to output the id of the user, but that isnt set until line 67 and saved to a new variable. We want the logger statement to use that new user * Adds hidden views parameter to workbook publish * Pycodestyle Co-authored-by: Chris Shin <cshin@tableau.com> Co-authored-by: Jac <jacalata@users.noreply.github.com> Co-authored-by: Reba Magier <rebeccam@syapse.com>
1 parent 3a9e0e5 commit 896a92b

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

tableauserverclient/server/endpoint/workbooks_endpoint.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ def delete_permission(self, item, capability_item):
234234
@api(version="2.0")
235235
@parameter_added_in(as_job='3.0')
236236
@parameter_added_in(connections='2.8')
237-
def publish(self, workbook_item, file_path, mode, connection_credentials=None, connections=None, as_job=False):
237+
def publish(
238+
self, workbook_item, file_path, mode,
239+
connection_credentials=None, connections=None, as_job=False,
240+
hidden_views=None
241+
):
238242

239243
if connection_credentials is not None:
240244
import warnings
@@ -277,7 +281,8 @@ def publish(self, workbook_item, file_path, mode, connection_credentials=None, c
277281
conn_creds = connection_credentials
278282
xml_request, content_type = RequestFactory.Workbook.publish_req_chunked(workbook_item,
279283
connection_credentials=conn_creds,
280-
connections=connections)
284+
connections=connections,
285+
hidden_views=hidden_views)
281286
else:
282287
logger.info('Publishing {0} to server'.format(filename))
283288
with open(file_path, 'rb') as f:
@@ -287,7 +292,8 @@ def publish(self, workbook_item, file_path, mode, connection_credentials=None, c
287292
filename,
288293
file_contents,
289294
10000 connection_credentials=conn_creds,
290-
connections=connections)
295+
connections=connections,
296+
hidden_views=hidden_views)
291297
logger.debug('Request xml: {0} '.format(xml_request[:1000]))
292298

293299
# Send the publishing request to server

tableauserverclient/server/request_factory.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ def _add_connections_element(connections_element, connection):
3838
_add_credentials_element(connection_element, connection_credentials)
3939

4040

41+
def _add_hiddenview_element(views_element, view_name):
42+
view_element = ET.SubElement(views_element, 'view')
43+
view_element.attrib['name'] = view_name
44+
view_element.attrib['hidden'] = "true"
45+
46+
4147
def _add_credentials_element(parent_element, connection_credentials):
4248
credentials_element = ET.SubElement(parent_element, 'connectionCredentials')
4349
credentials_element.attrib['name'] = connection_credentials.name
@@ -448,7 +454,11 @@ def add_req(self, user_item):
448454

449455

450456
class WorkbookRequest(object):
451-
def _generate_xml(self, workbook_item, connection_credentials=None, connections=None):
457+
def _generate_xml(
458+
self, workbook_item,
459+
connection_credentials=None, connections=None,
460+
hidden_views=None
461+
):
452462
xml_request = ET.Element('tsRequest')
453463
workbook_element = ET.SubElement(xml_request, 'workbook')
454464
workbook_element.attrib['name'] = workbook_item.name
@@ -467,6 +477,12 @@ def _generate_xml(self, workbook_item, connection_credentials=None, connections=
467477
connections_element = ET.SubElement(workbook_element, 'connections')
468478
for connection in connections:
469479
_add_connections_element(connections_element, connection)
480+
481+
if hidden_views is not None:
482+
views_element = ET.Sub EDBE Element(workbook_element, 'views')
483+
for view_name in hidden_views:
484+
_add_hiddenview_element(views_element, view_name)
485+
470486
return ET.tostring(xml_request)
471487

472488
def update_req(self, workbook_item):
@@ -494,19 +510,27 @@ def update_req(self, workbook_item):
494510

495511
return ET.tostring(xml_request)
496512

497-
def publish_req(self, workbook_item, filename, file_contents, connection_credentials=None, connections=None):
513+
def publish_req(
514+
self, workbook_item, filename, file_contents,
515+
connection_credentials=None, connections=None, hidden_views=None
516+
):
498517
xml_request = self._generate_xml(workbook_item,
499518
connection_credentials=connection_credentials,
500-
connections=connections)
519+
connections=connections,
520+
hidden_views=hidden_views)
501521

502522
parts = {'request_payload': ('', xml_request, 'text/xml'),
503523
'tableau_workbook': (filename, file_contents, 'application/octet-stream')}
504524
return _add_multipart(parts)
505525

506-
def publish_req_chunked(self, workbook_item, connection_credentials=None, connections=None):
526+
def publish_req_chunked(
527+
self, workbook_item, connection_credentials=None, connections=None,
528+
hidden_views=None
529+
):
507530
xml_request = self._generate_xml(workbook_item,
508531
connection_credentials=connection_credentials,
509-
connections=connections)
532+
connections=connections,
533+
hidden_views=hidden_views)
510534

511535
parts = {'request_payload': ('', xml_request, 'text/xml')}
512536
return _add_multipart(parts)

test/test_workbook.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import tableauserverclient as TSC
55
import xml.etree.ElementTree as ET
66

7+
78
from tableauserverclient.datetime_helpers import format_datetime
89
from tableauserverclient.server.endpoint.exceptions import InternalServerError
910
from tableauserverclient.server.request_factory import RequestFactory
@@ -436,6 +437,28 @@ def test_publish(self):
436437
self.assertEqual('GDP per capita', new_workbook.views[0].name)
437438
self.assertEqual('RESTAPISample_0/sheets/GDPpercapita', new_workbook.views[0].content_url)
438439

440+
def test_publish_with_hidden_view(self):
441+
with open(PUBLISH_XML, 'rb') as f:
442+
response_xml = f.read().decode('utf-8')
443+
with requests_mock.mock() as m:
444+
m.post(self.baseurl, text=response_xml)
445+
446+
new_workbook = TSC.WorkbookItem(name='Sample',
447+
show_tabs=False,
448+
project_id='ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
449+
450+
sample_workbook = os.path.join(TEST_ASSET_DIR, 'SampleWB.twbx')
451+
publish_mode = self.server.PublishMode.CreateNew
452+
453+
new_workbook = self.server.workbooks.publish(new_workbook,
454+
sample_workbook,
455+
publish_mode,
456+
hidden_views=['GDP per capita'])
457+
458+
request_body = m._adapter.request_history[0]._request.body
459+
self.assertIn(
460+
b'<views><view hidden="true" name="GDP per capita" /></views>', request_body)
461+
439462
def test_publish_async(self):
440463
self.server.version = '3.0'
441464
baseurl = self.server.workbooks.baseurl

0 commit comments

Comments
 (0)
0