-
Notifications
You must be signed in to change notification settings - Fork 436
Implement view filters on the populate* request options #260
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
c0e9243
0bb7f9e
24313e8
0e0622b
098a857
a01dd4b
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 |
---|---|---|
|
@@ -62,24 +62,50 @@ def apply_query_params(self, url): | |
return "{0}?{1}".format(url, '&'.join(params)) | ||
|
||
|
||
class ImageRequestOptions(RequestOptionsBase): | ||
class _FilterOptionsBase(RequestOptionsBase): | ||
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. Seems like a reasonable refactor. Can you give this class a docstring just so at a glance we can tell what it's used for vs other optionsbases? |
||
""" Provide a basic implementation of adding view filters to the url """ | ||
def __init__(self): | ||
self.view_filters = [] | ||
|
||
def apply_query_params(self, url): | ||
raise NotImplementedError() | ||
|
||
def vf(self, name, value): | ||
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. There's no code testing this or sampling this yet, but I'm guessing this makes it:
Baby-builder pattern! 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. Yes, eventually, we will refactor to a builder pattern! |
||
self.view_filters.append((name, value)) | ||
return self | ||
|
||
def _append_view_filters(self, params): | ||
for name, value in self.view_filters: | ||
params.append('vf_{}={}'.format(name, value)) | ||
|
||
|
||
class CSVRequestOptions(_FilterOptionsBase): | ||
def apply_query_params(self, url): | ||
params = [] | ||
self._append_view_filters(params) | ||
return "{0}?{1}".format(url, '&'.join(params)) | ||
|
||
|
||
class ImageRequestOptions(_FilterOptionsBase): | ||
# if 'high' isn't specified, the REST API endpoint returns an image with standard resolution | ||
class Resolution: | ||
High = 'high' | ||
|
||
def __init__(self, imageresolution=None): | ||
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. Side note: I thought I made this so it was I might make a PR after this merges |
||
super(ImageRequestOptions, self).__init__() | ||
self.image_resolution = imageresolution | ||
|
||
def apply_query_params(self, url): | ||
params = [] | ||
if self.image_resolution: | ||
params.append('resolution={0}'.format(self.image_resolution)) | ||
|
||
self._append_view_filters(params) | ||
|
||
return "{0}?{1}".format(url, '&'.join(params)) | ||
|
||
|
||
class PDFRequestOptions(RequestOptionsBase): | ||
# if 'high' isn't specified, the REST API endpoint returns an image with standard resolution | ||
class PDFRequestOptions(_FilterOptionsBase): | ||
class PageType: | ||
A3 = "a3" | ||
A4 = "a4" | ||
|
@@ -100,6 +126,7 @@ class Orientation: | |
Landscape = "landscape" | ||
|
||
def __init__(self, page_type=None, orientation=None): | ||
super(PDFRequestOptions, self).__init__() | ||
self.page_type = page_type | ||
self.orientation = orientation | ||
|
||
|
@@ -111,4 +138,6 @@ def apply_query_params(self, url): | |
if self.orientation: | ||
params.append('orientation={0}'.format(self.orientation)) | ||
|
||
self._append_view_filters(params) | ||
|
||
return "{0}?{1}".format(url, '&'.join(params)) |
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.
I don't think this is right, the 'stream=true' is an option for the
requests
library, not something that gets included in the url string, which is whatapply_query_parameters
does.