diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index df630a04..454dcdd5 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -6,7 +6,6 @@ from typing import List, Set import marshmallow as ma from flask import jsonify, request from marshmallow import Schema as MarshmallowSchema, fields as f -from teal import query from teal.marshmallow import EnumField from teal.resource import View @@ -15,10 +14,6 @@ from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.resources.lot.models import Lot, Path -class Filters(query.Query): - name = query.ILike(Lot.name) - - class LotFormat(Enum): UiTree = 'UiTree' @@ -30,7 +25,7 @@ class LotView(View): method (GET collection) endpoint """ format = EnumField(LotFormat, missing=None) - filter = f.Nested(Filters, missing=[]) + search = f.Str(missing=None) def post(self): l = request.get_json() @@ -73,8 +68,10 @@ class LotView(View): 'url': request.path }) else: - query = Lot.query.filter(*args['filter']) - lots = query.paginate(per_page=6) + query = Lot.query + if args['search']: + query = query.filter(Lot.name.ilike(args['search'] + '%')) + lots = query.paginate(per_page=6 if args['search'] else 30) ret = { 'items': self.schema.dump(lots.items, many=True, nested=0), 'pagination': { diff --git a/tests/test_lot.py b/tests/test_lot.py index 9b620362..ccd76f4a 100644 --- a/tests/test_lot.py +++ b/tests/test_lot.py @@ -243,7 +243,7 @@ def test_post_add_children_view_ui_tree_normal(user: UserClient): assert lots[1]['name'] == 'Child' # List format with a filter - lots = user.get(res=Lot, query=[('filter', {'name': 'pa'})])[0]['items'] + lots = user.get(res=Lot, query=[('search', 'pa')])[0]['items'] assert len(lots) == 1 assert lots[0]['name'] == 'Parent'