8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-04 17:06:27 +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 Supelec Rezo Rennes
parent fb97849609
commit ab311e82bc

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))
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]:
filter_clubs &= 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 = (
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
# Switch ports
@ -326,6 +339,10 @@ def get_words(query):
# If we are between two ", ignore separators
words[i] += char
continue
if char == "+":
# If we encouter a + outside of ", we replace it with a space
words[i] += " "
continue
if char == " " or char == ",":
# If we encouter a separator outside of ", we create a new word
if words[i] is not "":