Commit 27475873 authored by Mikaël Salson's avatar Mikaël Salson Committed by Vidjil Team
Browse files

vidjil_utils: filter method takes a list of string rather than a concatenation of strings

This prevents encoding issues between the different strings when they are concatenated
parent aa4457df
......@@ -172,8 +172,7 @@ def custom():
row.checked = True
row.names = vidjil_utils.anon_names(row.patient.id, row.patient.first_name, row.patient.last_name)
row.string = (row.names + row.sequence_file.filename +
str(row.sequence_file.sampling_date) + str(row.sequence_file.pcr) + str(row.config.name) + str(row.results_file.run_date) + str(row.patient.info)).lower()
row.string = [row.names, row.sequence_file.filename, str(row.sequence_file.sampling_date), str(row.sequence_file.pcr), str(row.config.name), str(row.results_file.run_date), row.patient.info]
query = query.find(lambda row : ( vidjil_utils.filter(row.string,request.vars["filter"]) or row.checked) )
if config :
......@@ -426,7 +425,7 @@ def index():
request.vars["filter"] = ""
for row in result :
row['string'] = (row['last_name']+row['first_name']+row['confs']+row['groups']+str(row['birth'])).lower()+str(row['info'])
row['string'] = [row['last_name'], row['first_name'], row['confs'], row['groups'], str(row['birth']), str(row['info'])]
result = filter(lambda row : vidjil_utils.filter(row['string'],request.vars["filter"]), result )
log.debug("patient list (%.3fs) %s" % (time.time()-start, request.vars["filter"]))
return dict(query = result,
......
......@@ -50,7 +50,7 @@ def index():
request.vars["filter"] = ""
for row in query :
row.string = (row.sequence_file.filename+row.config.name+row.patient.last_name+row.patient.first_name+row.sequence_file.producer+str(row.results_file.run_date)+row.status ).lower()
row.string = [row.sequence_file.filename, row.config.name, row.patient.last_name, row.patient.first_name, row.sequence_file.producer, str(row.results_file.run_date), row.status]
query = query.find(lambda row : vidjil_utils.filter(row.string,request.vars["filter"]) )
return dict(query = query,
......
......@@ -125,14 +125,16 @@ def anon_names(patient_id, first_name, last_name, can_view=None):
# return true if the string respect the filter list
def filter(str, filter_str):
filter_list = filter_str.split(" ")
str = map(lambda s: s.lower(), str)
for f in filter_list :
if len(f) > 0 and f[0] == "-" :
if f[1:].lower() in str.lower():
return False
else :
if f.lower() not in str.lower():
return False
pattern = f[1:]
else:
pattern = f
result = filter(lambda item: pattern.lower() in item, str)
if len(result) == 0:
return False
return True
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment