diff --git a/dj_rql/filter_cls.py b/dj_rql/filter_cls.py index d946d3a..5501833 100644 --- a/dj_rql/filter_cls.py +++ b/dj_rql/filter_cls.py @@ -3,6 +3,7 @@ # from collections import defaultdict +from datetime import datetime from uuid import uuid4 from django.db.models import Q @@ -354,6 +355,9 @@ def _build_q_for_search(self, operator, str_value): }) unquoted_value = self.remove_quotes(str_value) + if not unquoted_value: + return Q() + if not unquoted_value.startswith(RQL_ANY_SYMBOL): unquoted_value = '*' + unquoted_value @@ -802,10 +806,17 @@ def _convert_value(cls, django_field, str_value, use_repr=False): dt = parse_date(val) if dt is None: raise ValueError + return dt + elif filter_type == FilterTypes.DATETIME: dt = parse_datetime(val) if dt is None: - raise ValueError + dt = parse_date(val) + if dt is None: + raise ValueError + + return datetime(year=dt.year, month=dt.month, day=dt.day) + return dt elif filter_type == FilterTypes.BOOLEAN: if val not in (RQL_FALSE, RQL_TRUE): diff --git a/tests/test_filter_cls/test_apply_filters.py b/tests/test_filter_cls/test_apply_filters.py index 1761df9..38e54e8 100644 --- a/tests/test_filter_cls/test_apply_filters.py +++ b/tests/test_filter_cls/test_apply_filters.py @@ -253,6 +253,7 @@ def test_search(): assert apply_filters('(search="*aN*";search="*book")') == books assert apply_filters('(search="*aN";search="*b*")') == books assert apply_filters('search=bo') == [books[0]] + assert apply_filters('search=""') == books def test_search_bad_lookup(): diff --git a/tests/test_filter_cls/test_fields_filtering.py b/tests/test_filter_cls/test_fields_filtering.py index c7bc442..3ebe7d6 100644 --- a/tests/test_filter_cls/test_fields_filtering.py +++ b/tests/test_filter_cls/test_fields_filtering.py @@ -197,6 +197,7 @@ def test_published_at(): assert filter_field(filter_name, CO.NE, '2019-02-12T10:02') == [books[1]] assert filter_field(filter_name, CO.LE, '2020-01-01T00:00+08:00') == books assert filter_field(filter_name, CO.GT, '2000-12-12T00:21:00') == books + assert filter_field(filter_name, CO.GT, '2000-12-12') == books @pytest.mark.django_db @@ -396,7 +397,7 @@ def test_date_field_fail(filter_name, bad_value): @pytest.mark.parametrize('bad_value', [ - '2019-02-12', '0', 'date', '2019-02-12T27:00:00', '2019-02-12T21:00:00K', + '0', 'date', '2019-02-12T27:00:00', '2019-02-12T21:00:00K', ]) @pytest.mark.parametrize('filter_name', ['published.at']) def test_datetime_field_fail(filter_name, bad_value):