8000 Implement view filters on the populate* request options (#260) · tableau/server-client-python@7816d2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 7816d2e

Browse files
author
Russell Hay
authored
Implement view filters on the populate* request options (#260)
* Implement view filters on the populate* request options
1 parent b817537 commit 7816d2e

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

tableauserverclient/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
SiteItem, TableauAuth, UserItem, ViewItem, WorkbookItem, UnpopulatedPropertyError, \
55
HourlyInterval, DailyInterval, WeeklyInterval, MonthlyInterval, IntervalItem, TaskItem, \
66
SubscriptionItem
7-
from .server import RequestOptions, ImageRequestOptions, PDFRequestOptions, Filter, Sort, \
7+
from .server import RequestOptions, CSVRequestOptions, ImageRequestOptions, PDFRequestOptions, Filter, Sort, \
88
Server, ServerResponseError, MissingRequiredFieldError, NotSignedInError, Pager
99
from ._version import get_versions
1010
__version__ = get_versions()['version']

tableauserverclient/server/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .request_factory import RequestFactory
2-
from .request_options import ImageRequestOptions, PDFRequestOptions, RequestOptions
2+
from .request_options import CSVRequestOptions, ImageRequestOptions, PDFRequestOptions, RequestOptions
33
from .filter import Filter
44
from .sort import Sort
55
from .. import ConnectionItem, DatasourceItem, JobItem, \

tableauserverclient/server/endpoint/views_endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def csv_fetcher():
105105
def _get_view_csv(self, view_item, req_options):
106106
url = "{0}/{1}/data".format(self.baseurl, view_item.id)
107107

108-
with closing(self.get_request(url, parameters={"stream": True})) as server_response:
108+
with closing(self.get_request(url, request_object=req_options, parameters={"stream": True})) as server_response:
109109
csv = server_response.iter_content(1024)
110110
return csv
111111

tableauserverclient/server/request_options.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,50 @@ def apply_query_params(self, url):
6262
return "{0}?{1}".format(url, '&'.join(params))
6363

6464

65-
class ImageRequestOptions(RequestOptionsBase):
65+
class _FilterOptionsBase(RequestOptionsBase):
66+
""" Provide a basic implementation of adding view filters to the url """
67+
def __init__(self):
68+
self.view_filters = []
69+
70+
def apply_query_params(self, url):
71+
raise NotImplementedError()
72+
73+
def vf(self, name, value):
74+
self.view_filters.append((name, value))
75+
return self
76+
77+
def _append_view_filters(self, params):
78+
for name, value in self.view_filters:
79+
params.append('vf_{}={}'.format(name, value))
80+
81+
82+
class CSVRequestOptions(_FilterOptionsBase):
83+
def apply_query_params(self, url):
84+
params = []
85+
self._append_view_filters(params)
86+
return "{0}?{1}".format(url, '&'.join(params))
87+
88+
89+
class ImageRequestOptions(_FilterOptionsBase):
6690
# if 'high' isn't specified, the REST API endpoint returns an image with standard resolution
6791
class Resolution:
6892
High = 'high'
6993

7094
def __init__(self, imageresolution=None):
95+
super(ImageRequestOptions, self).__init__()
7196
self.image_resolution = imageresolution
7297

7398
def apply_query_params(self, url):
7499
params = []
75100
if self.image_resolution:
76101
params.append('resolution={0}'.format(self.image_resolution))
77102

103+
self._append_view_filters(params)
104+
78105
return "{0}?{1}".format(url, '&'.join(params))
79106

80107

81-
class PDFRequestOptions(RequestOptionsBase):
82-
# if 'high' isn't specified, the REST API endpoint returns an image with standard resolution
108+
class PDFRequestOptions(_FilterOptionsBase):
83109
class PageType:
84110
A3 = "a3"
85111
A4 = "a4"
@@ -100,6 +126,7 @@ class Orientation:
100126
Landscape = "landscape"
101127

102128
def __init__(self, page_type=None, orientation=None):
129+
super(PDFRequestOptions, self).__init__()
103130
self.page_type = page_type
104131
self.orientation = orientation
105132

@@ -111,4 +138,6 @@ def apply_query_params(self, url):
111138
if self.orientation:
112139
params.append('orientation={0}'.format(self.orientation))
113140

141+
self._append_view_filters(params)
142+
114143
return "{0}?{1}".format(url, '&'.join(params))

0 commit comments

Comments
 (0)
0