From 66183f9288ea9dab0e06fddf7ed5960cfc300ea8 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Tue, 18 Feb 2020 14:01:48 +0000 Subject: [PATCH] Add plaintext representation for Query --- search/views.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/search/views.py b/search/views.py index 30ef9bb0..c2e9338f 100644 --- a/search/views.py +++ b/search/views.py @@ -69,6 +69,13 @@ class Query: self.subqueries.append(Query(self.text)) self.text = "" + @property + def plaintext(self): + if self.operator is not None: + return self.operator.join([q.plaintext for q in self.subqueries]) + + return self.text + def is_int(variable): """ Check if the variable can be casted to an integer """ @@ -236,9 +243,8 @@ def search_single_word(word, filters, user, start, end, user_state, aff): # Rooms if "5" in aff and Room.can_view_all(user): filter_rooms = ( - Q(details__icontains=word) | Q(name__icontains=word) | Q(port__details=word) | Q(building__name__icontains=building) + Q(details__icontains=word) | Q(name__icontains=word) | Q(port__details=word) | Q(building__name__icontains=word) ) - filter_rooms |= (Q(name__icontains=room) & Q(building__name__icontains=building)) filters["rooms"] |= filter_rooms