@@ -62,24 +62,50 @@ def apply_query_params(self, url):
62
62
return "{0}?{1}" .format (url , '&' .join (params ))
63
63
64
64
65
- class ImageRequestOptions (RequestOptionsBase ):
65
+ class _FilterOptionsBase (RequestOptionsBase ):
66
+ """ Provide a basic implementation of adding view filters to the url """
67
+ def __init__ (self ):
68
+ self .view_filters = []
69
+
70
+ def apply_query_params (self , url ):
71
+ raise NotImplementedError ()
72
+
73
+ def vf (self , name , value ):
74
+ self .view_filters .append ((name , value ))
75
+ return self
76
+
77
+ def _append_view_filters (self , params ):
78
+ for name , value in self .view_filters :
79
+ params .append ('vf_{}={}' .format (name , value ))
80
+
81
+
82
+ class CSVRequestOptions (_FilterOptionsBase ):
83
+ def apply_query_params (self , url ):
84
+ params = []
85
+ self ._append_view_filters (params )
86
+ return "{0}?{1}" .format (url , '&' .join (params ))
87
+
88
+
89
+ class ImageRequestOptions (_FilterOptionsBase ):
66
90
# if 'high' isn't specified, the REST API endpoint returns an image with standard resolution
67
91
class Resolution :
68
92
High = 'high'
69
93
70
94
def __init__ (self , imageresolution = None ):
95
+ super (ImageRequestOptions , self ).__init__ ()
71
96
self .image_resolution = imageresolution
72
97
73
98
def apply_query_params (self , url ):
74
99
params = []
75
100
if self .image_resolution :
76
101
params .append ('resolution={0}' .format (self .image_resolution ))
77
102
103
+ self ._append_view_filters (params )
104
+
78
105
return "{0}?{1}" .format (url , '&' .join (params ))
79
106
80
107
81
- class PDFRequestOptions (RequestOptionsBase ):
82
- # if 'high' isn't specified, the REST API endpoint returns an image with standard resolution
108
+ class PDFRequestOptions (_FilterOptionsBase ):
83
109
class PageType :
84
110
A3 = "a3"
85
111
A4 = "a4"
@@ -100,6 +126,7 @@ class Orientation:
100
126
Landscape = "landscape"
101
127
102
128
def __init__ (self , page_type = None , orientation = None ):
129
+ super (PDFRequestOptions , self ).__init__ ()
103
130
self .page_type = page_type
104
131
self .orientation = orientation
105
132
@@ -111,4 +138,6 @@ def apply_query_params(self, url):
111
138
if self .orientation :
112
139
params .append ('orientation={0}' .format (self .orientation ))
113
140
141
+ self ._append_view_filters (params )
142
+
114
143
return "{0}?{1}" .format (url , '&' .join (params ))
0 commit comments