diff --git a/core/inventory/api_v2.py b/core/inventory/api_v2.py index ef3ae90..d69b6f7 100644 --- a/core/inventory/api_v2.py +++ b/core/inventory/api_v2.py @@ -20,18 +20,24 @@ class ContainerViewSet(viewsets.ModelViewSet): queryset = Container.objects.all() +def filter_items(items, query): + query_tokens = query.split(' ') + for item in items: + item_tokens = item.name.split(' ') + if all(token in item_tokens for token in query_tokens): + yield item + elif all(token in item.description for token in query_tokens): + yield item + @api_view(['GET']) -@permission_classes([IsAuthenticated]) +@permission_classes([]) +#@permission_classes([IsAuthenticated]) #@permission_required('view_item', raise_exception=True) def search_items(request, event_slug, query): try: event = Event.objects.get(slug=event_slug) - query_tokens = query.split(' ') - q = Item.objects.filter(event=event) - for token in query_tokens: - if token: - q = q.filter(description__icontains=token) - return Response(ItemSerializer(q, many=True).data) + items = filter_items(Item.objects.filter(event=event), query) + return Response(ItemSerializer(items, many=True).data) except Event.DoesNotExist: return Response(status=404)