Skip to content
Closed
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
31 changes: 25 additions & 6 deletions tableauserverclient/server/request_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ class Direction:
Asc = 'asc'

def __init__(self, pagenumber=1, pagesize=100):
self.pagenumber = pagenumber
self.pagesize = pagesize
self.pagenumber = to_int("pagenumber", pagenumber)
self.pagesize = to_int("pagesize", pagesize)
self.sort = set()
self.filter = set()

def page_size(self, page_size):
self.pagesize = page_size
self.pagesize = to_int("pagesize", page_size)
return self

def page_number(self, page_number):
self.pagenumber = page_number
self.pagenumber = to_int("pagenumber", page_number)
return self

def apply_query_params(self, url):
Expand Down Expand Up @@ -98,8 +98,15 @@ def _append_view_filters(self, params):


class CSVRequestOptions(_FilterOptionsBase):
def __init__(self, maxage=None):
super(CSVRequestOptions, self).__init__()
self.max_age = to_int("maxage", maxage)

def apply_query_params(self, url):
params = []
if self.max_age:
params.append('maxAge={0}'.format(self.max_age))

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

Expand All @@ -112,7 +119,7 @@ class Resolution:
def __init__(self, imageresolution=None, maxage=None):
super(ImageRequestOptions, self).__init__()
self.image_resolution = imageresolution
self.max_age = maxage
self.max_age = to_int("maxage", maxage)

def apply_query_params(self, url):
params = []
Expand Down Expand Up @@ -146,10 +153,11 @@ class Orientation:
Portrait = "portrait"
Landscape = "landscape"

def __init__(self, page_type=None, orientation=None):
def __init__(self, page_type=None, orientation=None, maxage=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we call it max_age here as well since it’s what you call it on the object anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ImageRequestOptions already had maxage, so I wanted to keep it consistent across the 3 request objects without introducing any breaking changes. I guess we could deprecate it if we really wanted to change it?

super(PDFRequestOptions, self).__init__()
self.page_type = page_type
self.orientation = orientation
self.max_age = to_int("maxage", maxage)

def apply_query_params(self, url):
params = []
Expand All @@ -159,6 +167,17 @@ def apply_query_params(self, url):
if self.orientation:
params.append('orientation={0}'.format(self.orientation))

if self.max_age:
params.append('maxAge={0}'.format(self.max_age))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do some verification that this is an integer at least?


self._append_view_filters(params)

return "{0}?{1}".format(url, '&'.join(params))


def to_int(name, value):
try:
return int(value)
except ValueError:
print("Integer value expected for the '{}' parameter, but got {}".format(name, value))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to just print something in this case. We should throw an exception that tells what the error is. I believe we have something for Integer parameter errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have property decorators in models for Integer parameter errors, but didn't want to bring that into here.
Above snippet prints a message and re-throws the same ValueError. It would be ideal to throw an exception with our custom message, but that results in 2 exceptions being thrown.

raise