forked from tableau/server-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.py
More file actions
27 lines (22 loc) · 865 Bytes
/
filter.py
File metadata and controls
27 lines (22 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from .request_options import RequestOptions
class Filter(object):
def __init__(self, field, operator, value):
self.field = field
self.operator = operator
self._value = None
self.value = value
def __str__(self):
value_string = str(self._value)
if isinstance(self._value, list):
value_string = value_string.replace(' ', '').replace('\'', '')
return '{0}:{1}:{2}'.format(self.field, self.operator, value_string)
@property
def value(self):
return self._value
@value.setter
def value(self, filter_value):
if isinstance(filter_value, list) and self.operator != RequestOptions.Operator.In:
error = "Filter values can only be a list if the operator is 'in'."
raise ValueError(error)
else:
self._value = filter_value