From 59d6d69bdad606f66b08f03bdf4d0cfaf041559a Mon Sep 17 00:00:00 2001 From: yiorgos marinellis Date: Tue, 28 Apr 2020 21:20:40 +0200 Subject: [PATCH] Add user filtering which is evaluate whether or not lot is specified --- ereuse_devicehub/resources/device/views.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 10a8fdff..f4bfc960 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -61,8 +61,7 @@ class Filters(query.Query): # todo This part of the query is really slow # And forces usage of distinct, as it returns many rows # due to having multiple paths to the same - lot = query.Join((Device.id == LotDeviceDescendants.device_id) - & (Deliverynote.lot_id == LotDeviceDescendants.ancestor_lot_id), + lot = query.Join((Device.id == LotDeviceDescendants.device_id), LotQ) @@ -142,10 +141,7 @@ class DeviceView(View): ) def query(self, args): - # query = Device.query.distinct() # todo we should not force to do this if the query is ok - query = Device.query.distinct() \ - .filter(Computer.owner_id == g.user.id) \ - .filter(Deliverynote.receiver_address == g.user.email) + query = Device.query.distinct() # todo we should not force to do this if the query is ok search_p = args.get('search', None) if search_p: @@ -156,9 +152,18 @@ class DeviceView(View): ).order_by( search.Search.rank(properties, search_p) + search.Search.rank(tags, search_p) ) + query = self.user_filter(query) return query.filter(*args['filter']).order_by(*args['sort']) + def user_filter(self, query): + filterqs = request.args.get('filter', None) + if (filterqs and + 'lot' not in filterqs): + query = query.filter((Computer.id == Device.id), (Computer.owner_id == g.user.id)) + pass + return query + class ManufacturerView(View): class FindArgs(marshmallow.Schema): search = marshmallow.fields.Str(required=True,