rest_utils: simplify filter extracting
Change-Id: I7271f6f7d381753607c2c791985100ecd421a981
This commit is contained in:
parent
6f2e510fea
commit
284fe744d6
|
@ -26,6 +26,9 @@ from qinling import exceptions as exc
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
FILTER_TYPES = ('in', 'nin', 'eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'has')
|
||||||
|
LIST_VALUE_FILTER_TYPES = {'in', 'nin'}
|
||||||
|
|
||||||
|
|
||||||
def wrap_wsme_controller_exception(func):
|
def wrap_wsme_controller_exception(func):
|
||||||
"""Decorator for controllers method.
|
"""Decorator for controllers method.
|
||||||
|
@ -122,38 +125,17 @@ def _extract_filter_type_and_value(data):
|
||||||
'filter_type:value'.
|
'filter_type:value'.
|
||||||
:return: filter type and value.
|
:return: filter type and value.
|
||||||
"""
|
"""
|
||||||
if data.startswith("in:"):
|
for filter_type in FILTER_TYPES:
|
||||||
value = list(six.text_type(data[3:]).split(","))
|
prefix = filter_type + ':'
|
||||||
filter_type = 'in'
|
prefix_len = len(prefix)
|
||||||
elif data.startswith("nin:"):
|
if data.startswith(prefix):
|
||||||
value = list(six.text_type(data[4:]).split(","))
|
value = six.text_type(data[prefix_len:])
|
||||||
filter_type = 'nin'
|
if filter_type in LIST_VALUE_FILTER_TYPES:
|
||||||
elif data.startswith("neq:"):
|
value = list(value.split(','))
|
||||||
value = six.text_type(data[4:])
|
return filter_type, value
|
||||||
filter_type = 'neq'
|
|
||||||
elif data.startswith("gt:"):
|
|
||||||
value = six.text_type(data[3:])
|
|
||||||
filter_type = 'gt'
|
|
||||||
elif data.startswith("gte:"):
|
|
||||||
value = six.text_type(data[4:])
|
|
||||||
filter_type = 'gte'
|
|
||||||
elif data.startswith("lt:"):
|
|
||||||
value = six.text_type(data[3:])
|
|
||||||
filter_type = 'lt'
|
|
||||||
elif data.startswith("lte:"):
|
|
||||||
value = six.text_type(data[4:])
|
|
||||||
filter_type = 'lte'
|
|
||||||
elif data.startswith("eq:"):
|
|
||||||
value = six.text_type(data[3:])
|
|
||||||
filter_type = 'eq'
|
|
||||||
elif data.startswith("has:"):
|
|
||||||
value = six.text_type(data[4:])
|
|
||||||
filter_type = 'has'
|
|
||||||
else:
|
|
||||||
value = data
|
|
||||||
filter_type = 'eq'
|
|
||||||
|
|
||||||
return filter_type, value
|
# Not matching any filter types, defaults to 'eq'.
|
||||||
|
return 'eq', data
|
||||||
|
|
||||||
|
|
||||||
def get_project_params(project_id, all_projects):
|
def get_project_params(project_id, all_projects):
|
||||||
|
|
Loading…
Reference in New Issue