From 7b50e2ed172093a2d156e80032f66312f2929711 Mon Sep 17 00:00:00 2001 From: preguraman Date: Mon, 12 Nov 2018 14:13:51 -0800 Subject: [PATCH 1/2] Add maxage param to the download view image request --- samples/download_view_image.py | 7 ++++++- tableauserverclient/server/request_options.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/samples/download_view_image.py b/samples/download_view_image.py index b95a8628b..730ca9572 100644 --- a/samples/download_view_image.py +++ b/samples/download_view_image.py @@ -25,6 +25,7 @@ def main(): parser.add_argument('--view-name', '-v', required=True, help='name of view to download an image of') parser.add_argument('--filepath', '-f', required=True, help='filepath to save the image returned') + parser.add_argument('--maxage', '-m', required=False, help='max age of the image in the cache in minutes.') parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', help='desired logging level (set to error by default)') @@ -55,8 +56,12 @@ def main(): raise LookupError("View with the specified name was not found.") view_item = all_views[0] + max_age = args.maxage + if not max_age: + max_age = 1 + # Step 3: Query the image endpoint and save the image to the specified location - image_req_option = TSC.ImageRequestOptions(imageresolution=TSC.ImageRequestOptions.Resolution.High) + image_req_option = TSC.ImageRequestOptions(imageresolution=TSC.ImageRequestOptions.Resolution.High, maxage = max_age) server.views.populate_image(view_item, image_req_option) with open(args.filepath, "wb") as image_file: diff --git a/tableauserverclient/server/request_options.py b/tableauserverclient/server/request_options.py index 0e3601a25..9f3247e7b 100644 --- a/tableauserverclient/server/request_options.py +++ b/tableauserverclient/server/request_options.py @@ -108,14 +108,17 @@ class ImageRequestOptions(_FilterOptionsBase): class Resolution: High = 'high' - def __init__(self, imageresolution=None): + def __init__(self, imageresolution=None, maxage=None): super(ImageRequestOptions, self).__init__() self.image_resolution = imageresolution + self.max_age = maxage def apply_query_params(self, url): params = [] if self.image_resolution: params.append('resolution={0}'.format(self.image_resolution)) + if self.max_age: + params.append('maxAge={0}'.format(self.max_age)) self._append_view_filters(params) From 4afd7ecae8b15459041a9ad06d42e06ae7c1e6f7 Mon Sep 17 00:00:00 2001 From: preguraman Date: Wed, 14 Nov 2018 12:16:38 -0800 Subject: [PATCH 2/2] Fix the code style error --- samples/download_view_image.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/download_view_image.py b/samples/download_view_image.py index 730ca9572..df2331596 100644 --- a/samples/download_view_image.py +++ b/samples/download_view_image.py @@ -58,10 +58,10 @@ def main(): max_age = args.maxage if not max_age: - max_age = 1 + max_age = 1 - # Step 3: Query the image endpoint and save the image to the specified location - image_req_option = TSC.ImageRequestOptions(imageresolution=TSC.ImageRequestOptions.Resolution.High, maxage = max_age) + image_req_option = TSC.ImageRequestOptions(imageresolution=TSC.ImageRequestOptions.Resolution.High, + maxage=max_age) server.views.populate_image(view_item, image_req_option) with open(args.filepath, "wb") as image_file: