mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 08:23:46 +00:00
Pep, Pylint & Fix oubli
This commit is contained in:
parent
8b20e10e20
commit
3da02fd7a4
1 changed files with 9 additions and 10 deletions
|
@ -56,8 +56,9 @@ def is_int(variable):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def finish_results(results, col, order):
|
def finish_results(results, col, order):
|
||||||
"""Sort the results by applying filters and then limit them to the
|
"""Sort the results by applying filters and then limit them to the
|
||||||
number of max results. Finally add the info of the nmax number of results
|
number of max results. Finally add the info of the nmax number of results
|
||||||
to the dict"""
|
to the dict"""
|
||||||
|
|
||||||
|
@ -119,7 +120,8 @@ def finish_results(results, col, order):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def search_single_word(word, filters, is_cableur, start, end, user_state, aff):
|
def search_single_word(word, filters, is_cableur, user_id,
|
||||||
|
start, end, user_state, aff):
|
||||||
""" Construct the correct filters to match differents fields of some models
|
""" Construct the correct filters to match differents fields of some models
|
||||||
with the given query according to the given filters.
|
with the given query according to the given filters.
|
||||||
The match field are either CharField or IntegerField that will be displayed
|
The match field are either CharField or IntegerField that will be displayed
|
||||||
|
@ -143,7 +145,7 @@ def search_single_word(word, filters, is_cableur, start, end, user_state, aff):
|
||||||
)
|
)
|
||||||
) & Q(state__in=user_state)
|
) & Q(state__in=user_state)
|
||||||
if not is_cableur:
|
if not is_cableur:
|
||||||
filter_users &= Q(id=request.user.id)
|
filter_users &= Q(id=user_id)
|
||||||
filters['users'] |= filter_users
|
filters['users'] |= filter_users
|
||||||
|
|
||||||
# Machines
|
# Machines
|
||||||
|
@ -166,7 +168,7 @@ def search_single_word(word, filters, is_cableur, start, end, user_state, aff):
|
||||||
interface__ipv4__ipv4__icontains=word
|
interface__ipv4__ipv4__icontains=word
|
||||||
)
|
)
|
||||||
if not is_cableur:
|
if not is_cableur:
|
||||||
filter_machines &= Q(user__id=request.user.id)
|
filter_machines &= Q(user__id=user_id)
|
||||||
filters['machines'] |= filter_machines
|
filters['machines'] |= filter_machines
|
||||||
|
|
||||||
# Factures
|
# Factures
|
||||||
|
@ -321,11 +323,9 @@ def get_words(query):
|
||||||
# The last char war a \ so we escape this char
|
# The last char war a \ so we escape this char
|
||||||
escaping_char = False
|
escaping_char = False
|
||||||
words[i] += char
|
words[i] += char
|
||||||
print( 'escaped '+char+' -> '+words[i] )
|
|
||||||
continue
|
continue
|
||||||
if char == '\\':
|
if char == '\\':
|
||||||
# We need to escape the next char
|
# We need to escape the next char
|
||||||
print( 'escaping '+char+' -> '+words[i] )
|
|
||||||
escaping_char = True
|
escaping_char = True
|
||||||
continue
|
continue
|
||||||
if char == '"':
|
if char == '"':
|
||||||
|
@ -336,15 +336,14 @@ 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 == ' ' 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 '':
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
# If we haven't encountered any special case, add the char to the word
|
# If we haven't encountered any special case, add the char to the word
|
||||||
print(words)
|
|
||||||
words[i] += char
|
words[i] += char
|
||||||
|
|
||||||
return words
|
return words
|
||||||
|
|
||||||
|
|
||||||
|
@ -371,12 +370,12 @@ def get_results(query, request, params):
|
||||||
}
|
}
|
||||||
|
|
||||||
words = get_words(query)
|
words = get_words(query)
|
||||||
print( words )
|
|
||||||
for word in words:
|
for word in words:
|
||||||
filters = search_single_word(
|
filters = search_single_word(
|
||||||
word,
|
word,
|
||||||
filters,
|
filters,
|
||||||
request.user.has_perms(('cableur',)),
|
request.user.has_perms(('cableur',)),
|
||||||
|
request.user.id,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
user_state,
|
user_state,
|
||||||
|
|
Loading…
Reference in a new issue