def to_filter_args(object_name, context, search): parse_results = None try: parse_results = parser().parseString(search, True) except ParseException as e: _logger.warning('Parsing of \'%s\' failed: %s', search, e) raise QueryException('\'search\' malformed', 400) object_search_fns = _search_fns[object_name] return [_handle_parse_result(context, parse_results, object_search_fns)]
def get_count( json_, default=_DEFAULT_COUNT, max_=_MAX_COUNT, param_name='count'): if param_name not in json_: return default count = json_[param_name] if type(count) is not int: raise QueryException(f'\'{param_name}\' must be int', 400) if count < 0: raise QueryException( f'\'{param_name}\' must be greater than or equal to 0', 400) elif count > max_: raise QueryException( f'\'{param_name}\' must be less than or equal to {max_}', 400) return count
def get_search(context, json_, object_name, param_name='search'): if param_name not in json_: return [] search = json_[param_name] if type(search) is not str: raise QueryException( f'\'{param_name}\' must be string', 400) # pragma: no cover filter_args = searchutils.to_filter_args(object_name, context, search) return filter_args
def get_return_total_count( json_, default=_DEFAULT_RETURN_TOTAL_COUNT, param_name='totalCount'): if param_name not in json_: return default return_total_count = json_[param_name] if type(return_total_count) is not bool: raise QueryException( f'\'{param_name}\' must be boolean', 400) # pragma: no cover return return_total_count
def get_return_objects( json_, default=_DEFAULT_RETURN_OBJECTS, param_name='objects'): if param_name not in json_: return default return_objects = json_[param_name] if type(return_objects) is not bool: raise QueryException( f'\'{param_name}\' must be boolean', 400) # pragma: no cover return return_objects
def get_sort(json_, object_name, param_name='sort', disable_default_sort_param_name='disableDefaultSort'): sort = None if param_name in json_: sort = json_[param_name] if sort is not None: if type(sort) is not str: raise QueryException( '\'{0}\' must be null or string', 400) # pragma: no cover default_sort_enabled = True if disable_default_sort_param_name in json_: if type(json_[disable_default_sort_param_name]) is not bool: raise QueryException( f'\'{disable_default_sort_param_name}\' must be boolean', 400) # pragma: no cover default_sort_enabled = not json_[disable_default_sort_param_name] sort_list = sortutils.to_sort_list(object_name, sort, default_sort_enabled) order_by_args = sortutils.sort_list_to_order_by_args( object_name, sort_list) return order_by_args
def sort_list_to_order_by_args(object_name, sort_list): db_sort_list = [] for sort_desc in sort_list: field_name = sort_desc['field_name'] direction = sort_desc['direction'] db_sort_field_accessor_fns = _to_db_sort_field_accessor_fns( object_name, field_name) if db_sort_field_accessor_fns: for db_sort_field_accessor_fn in db_sort_field_accessor_fns: db_sort_list.append(db_sort_field_accessor_fn(direction)) else: raise QueryException( f'\'{field_name}\' field not recognized for \'sort\'', 400) return db_sort_list