diff --git a/aiohttp_admin/backends/mongo_utils.py b/aiohttp_admin/backends/mongo_utils.py index ca4de7f0..f5244537 100644 --- a/aiohttp_admin/backends/mongo_utils.py +++ b/aiohttp_admin/backends/mongo_utils.py @@ -35,8 +35,8 @@ def op(filter, field, operation, value): # TODO: fix comparators, keys should be something better comparator_map = { t.String: ('eq', 'ne', 'like', 'in'), - t.Int: ('eq', 'ne', 'lt', 'le', 'gt', 'ge', 'in'), - t.Float: ('eq', 'ne', 'lt', 'le', 'gt', 'ge'), + t.ToInt: ('eq', 'ne', 'lt', 'le', 'gt', 'ge', 'in'), + t.ToFloat: ('eq', 'ne', 'lt', 'le', 'gt', 'ge'), # t.Date: ('eq', 'ne', 'lt', 'le', 'gt', 'ge'), } diff --git a/aiohttp_admin/backends/sa_utils.py b/aiohttp_admin/backends/sa_utils.py index 30ff08a2..0a1c5b83 100644 --- a/aiohttp_admin/backends/sa_utils.py +++ b/aiohttp_admin/backends/sa_utils.py @@ -29,10 +29,10 @@ def build_trafaret(sa_type, **kwargs): trafaret = t.String(max_length=sa_type.length, **kwargs) elif isinstance(sa_type, sa.sql.sqltypes.Integer): - trafaret = t.Int(**kwargs) + trafaret = t.ToInt(**kwargs) elif isinstance(sa_type, sa.sql.sqltypes.Float): - trafaret = t.Float(**kwargs) + trafaret = t.ToFloat(**kwargs) elif isinstance(sa_type, sa.sql.sqltypes.DateTime): trafaret = DateTime(**kwargs) # RFC3339 @@ -41,7 +41,7 @@ def build_trafaret(sa_type, **kwargs): trafaret = DateTime(**kwargs) # RFC3339 elif isinstance(sa_type, sa.sql.sqltypes.Boolean): - trafaret = t.StrBool(**kwargs) + trafaret = t.ToBool(**kwargs) # Add PG related JSON and ARRAY elif isinstance(sa_type, postgresql.JSON): diff --git a/aiohttp_admin/layout_utils.py b/aiohttp_admin/layout_utils.py index 4a9c67ce..09aecae2 100644 --- a/aiohttp_admin/layout_utils.py +++ b/aiohttp_admin/layout_utils.py @@ -9,13 +9,13 @@ def build_field(key, value, relations=None): extra = None name = key - if isinstance(value, t.Int): + if isinstance(value, t.ToInt): v = "number" elif isinstance(value, (t.String, t.URL)): v = "string" elif isinstance(value, t.Email): v = "email" - elif isinstance(value, t.Float): + elif isinstance(value, t.ToFloat): v = "float" elif isinstance(value, t.Enum): v = "choice" diff --git a/aiohttp_admin/utils.py b/aiohttp_admin/utils.py index 47752795..cec9eb91 100644 --- a/aiohttp_admin/utils.py +++ b/aiohttp_admin/utils.py @@ -47,7 +47,7 @@ def json_datetime_serial(obj): OptKey = partial(t.Key, optional=True) -SimpleType = t.IntRaw | t.Bool | t.String | t.FloatRaw +SimpleType = t.Int | t.Bool | t.String | t.Float Filter = t.Dict({ OptKey('in'): t.List(SimpleType), OptKey('gt'): SimpleType, @@ -65,8 +65,8 @@ def json_datetime_serial(obj): ListQuery = t.Dict({ - OptKey('_page', default=1): t.Int[1:], - OptKey('_perPage', default=30): t.Int[1:], + OptKey('_page', default=1): t.ToInt[1:], + OptKey('_perPage', default=30): t.ToInt[1:], OptKey('_sortField'): t.String, OptKey('_sortDir', default=DESC): t.Enum(DESC, ASC), diff --git a/requirements-dev.txt b/requirements-dev.txt index 98cb4625..592b15df 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -14,6 +14,6 @@ pytest-sugar==0.9.2 pytest==5.2.2 python-dateutil==2.8.0 sqlalchemy==1.3.10 -trafaret==1.2.0 +trafaret==2.0.0 pymysql==0.9.3 -r requirements-doc.txt diff --git a/tests/db_fixtures.py b/tests/db_fixtures.py index a32e8554..1777cd8c 100644 --- a/tests/db_fixtures.py +++ b/tests/db_fixtures.py @@ -154,13 +154,13 @@ def document_schema(): t.Key('title'): t.String(max_length=200), t.Key('category'): t.String(max_length=200), t.Key('body'): t.String, - t.Key('views'): t.Int, - t.Key('average_note'): t.Float, + t.Key('views'): t.ToInt, + t.Key('average_note'): t.ToFloat, # t.Key('pictures'): t.Dict({}).allow_extra('*'), t.Key('published_at'): DateTime, # t.Key('tags'): t.List(t.Int), t.Key('status'): t.Enum(*choices), - t.Key('visible'): t.StrBool, + t.Key('visible'): t.ToBool, }) return schema diff --git a/tests/test_utils.py b/tests/test_utils.py index 1ccd608a..9f7c71c1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -131,11 +131,11 @@ def test_validate_payload_not_valid_schema(): def test_as_dict(): - exc = t.DataError() + exc = t.DataError('err') resp = as_dict(exc) assert isinstance(resp, dict) - exc = t.DataError() + exc = t.DataError('err') assert isinstance(exc.as_dict("boom"), str) resp = as_dict(exc, 'boom')