-
Notifications
You must be signed in to change notification settings - Fork 448
Adds max_age param to csv and pdf request options #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
|
@@ -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)) | ||
|
|
||
|
|
@@ -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 = [] | ||
|
|
@@ -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): | ||
| 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 = [] | ||
|
|
@@ -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)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| raise | ||
There was a problem hiding this comment.
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_agehere as well since it’s what you call it on the object anywayThere was a problem hiding this comment.
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?