Skip to content

Commit

Permalink
fix: remove vizHeight and vizWidth from ImageRequestOptions
Browse files Browse the repository at this point in the history
Closes #1564

Retrieving a view image does not support vizHeight and
vizWidth serverside. Supporting it for images as well was
a mistake.
  • Loading branch information
jorwoods committed Feb 7, 2025
1 parent 364f431 commit 0fa709d
Showing 1 changed file with 40 additions and 52 deletions.
92 changes: 40 additions & 52 deletions tableauserverclient/server/request_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,46 +268,6 @@ def _append_view_filters(self, params) -> None:
params[name] = value


class _ImagePDFCommonExportOptions(_DataExportOptions):
def __init__(self, maxage=-1, viz_height=None, viz_width=None):
super().__init__(maxage=maxage)
self.viz_height = viz_height
self.viz_width = viz_width

@property
def viz_height(self):
return self._viz_height

@viz_height.setter
@property_is_int(range=(0, sys.maxsize), allowed=(None,))
def viz_height(self, value):
self._viz_height = value

@property
def viz_width(self):
return self._viz_width

@viz_width.setter
@property_is_int(range=(0, sys.maxsize), allowed=(None,))
def viz_width(self, value):
self._viz_width = value

def get_query_params(self) -> dict:
params = super().get_query_params()

# XOR. Either both are None or both are not None.
if (self.viz_height is None) ^ (self.viz_width is None):
raise ValueError("viz_height and viz_width must be specified together")

if self.viz_height is not None:
params["vizHeight"] = self.viz_height

if self.viz_width is not None:
params["vizWidth"] = self.viz_width

return params


class CSVRequestOptions(_DataExportOptions):
"""
Options that can be used when exporting a view to CSV. Set the maxage to control the age of the data exported.
Expand Down Expand Up @@ -338,7 +298,7 @@ class ExcelRequestOptions(_DataExportOptions):
extension = "xlsx"


class ImageRequestOptions(_ImagePDFCommonExportOptions):
class ImageRequestOptions(_DataExportOptions):
"""
Options that can be used when exporting a view to an image. Set the maxage to control the age of the data exported.
Filters to the underlying data can be applied using the `vf` and `parameter` methods.
Expand All @@ -354,13 +314,6 @@ class ImageRequestOptions(_ImagePDFCommonExportOptions):
maxage: int, optional
The maximum age of the data to export. Shortest possible duration is 1
minute. No upper limit. Default is -1, which means no limit.
viz_height: int, optional
The height of the viz in pixels. If specified, viz_width must also be specified.
viz_width: int, optional
The width of the viz in pixels. If specified, viz_height must also be specified.
"""

extension = "png"
Expand All @@ -369,8 +322,10 @@ class ImageRequestOptions(_ImagePDFCommonExportOptions):
class Resolution:
High = "high"

def __init__(self, imageresolution=None, maxage=-1, viz_height=None, viz_width=None):
super().__init__(maxage=maxage, viz_height=viz_height, viz_width=viz_width)
def __init__(self, imageresolution=None, maxage=-1):
super().__init__(
maxage=maxage,
)
self.image_resolution = imageresolution

def get_query_params(self):
Expand All @@ -380,7 +335,7 @@ def get_query_params(self):
return params


class PDFRequestOptions(_ImagePDFCommonExportOptions):
class PDFRequestOptions(_DataExportOptions):
"""
Options that can be used when exporting a view to PDF. Set the maxage to control the age of the data exported.
Filters to the underlying data can be applied using the `vf` and `parameter` methods.
Expand Down Expand Up @@ -425,12 +380,45 @@ class Orientation:
Landscape = "landscape"

def __init__(self, page_type=None, orientation=None, maxage=-1, viz_height=None, viz_width=None):
super().__init__(maxage=maxage, viz_height=viz_height, viz_width=viz_width)
super().__init__(
maxage=maxage,
)
self.page_type = page_type
self.orientation = orientation
self.viz_height = viz_height
self.viz_width = viz_width

@property
def viz_height(self):
return self._viz_height

@viz_height.setter
@property_is_int(range=(0, sys.maxsize), allowed=(None,))
def viz_height(self, value):
self._viz_height = value

@property
def viz_width(self):
return self._viz_width

@viz_width.setter
@property_is_int(range=(0, sys.maxsize), allowed=(None,))
def viz_width(self, value):
self._viz_width = value

def get_query_params(self) -> dict:
params = super().get_query_params()

# XOR. Either both are None or both are not None.
if (self.viz_height is None) ^ (self.viz_width is None):
raise ValueError("viz_height and viz_width must be specified together")

if self.viz_height is not None:
params["vizHeight"] = self.viz_height

if self.viz_width is not None:
params["vizWidth"] = self.viz_width

if self.page_type:
params["type"] = self.page_type

Expand Down

0 comments on commit 0fa709d

Please sign in to comment.