8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-30 08:32:26 +00:00

Add ability to search by building+room

This commit is contained in:
Jean-Romain Garnier 2020-02-16 18:35:46 +00:00 committed by Gabriel Detraz
parent c863107293
commit fe11867ba9

View file

@ -121,6 +121,12 @@ def search_single_word(word, filters, user, start, end, user_state, aff):
) )
filter_users = (filter_clubs | Q(name__icontains=word)) filter_users = (filter_clubs | Q(name__icontains=word))
if len(word.split(" ")) >= 2:
# Assume the room is in 1 word, and the building may be in multiple words
building = " ".join(word.split(" ")[:-1])
room = word.split(" ")[-1]
filter_users |= (Q(room__name__icontains=room) & Q(room__building__name__icontains=building))
if not User.can_view_all(user)[0]: if not User.can_view_all(user)[0]:
filter_clubs &= Q(id=user.id) filter_clubs &= Q(id=user.id)
filter_users &= Q(id=user.id) filter_users &= Q(id=user.id)
@ -204,6 +210,13 @@ def search_single_word(word, filters, user, start, end, user_state, aff):
filter_rooms = ( filter_rooms = (
Q(details__icontains=word) | Q(name__icontains=word) | Q(port__details=word) Q(details__icontains=word) | Q(name__icontains=word) | Q(port__details=word)
) )
if len(word.split(" ")) >= 2:
# Assume the room is in 1 word, and the building may be in multiple words
building = " ".join(word.split(" ")[:-1])
room = word.split(" ")[-1]
filter_rooms |= (Q(name__icontains=room) & Q(building__name__icontains=building))
filters["rooms"] |= filter_rooms filters["rooms"] |= filter_rooms
# Switch ports # Switch ports
@ -326,6 +339,10 @@ def get_words(query):
# If we are between two ", ignore separators # If we are between two ", ignore separators
words[i] += char words[i] += char
continue continue
if char == "+":
# If we encouter a + outside of ", we replace it with a space
words[i] += " "
continue
if char == " " or char == ",": if char == " " or char == ",":
# If we encouter a separator outside of ", we create a new word # If we encouter a separator outside of ", we create a new word
if words[i] is not "": if words[i] is not "":