Commit 98edc826 authored by Marc Duez's avatar Marc Duez
Browse files

server : filter > factorize function for admin/results/patient controllers

parent 9ac254c2
# coding: utf8
import gluon.contrib.simplejson, re
import os.path
import vidjil_utils
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
......@@ -21,21 +22,16 @@ def worker():
def log():
if auth.has_membership("admin"):
lines = []
file = open('/var/vidjil/'+request.vars["file"])
for row in reversed(file.readlines()) :
flag = True
if "filter" not in request.vars :
request.vars["filter"] = ""
if "filter" in request.vars :
filter_list = request.vars["filter"].split(' ')
for f in filter_list :
if row.lower().find(f.lower()) == -1 :
flag = False
else :
request.vars["filter"] = ""
if flag :
for row in reversed(file.readlines()) :
if vidjil_utils.filter(row, request.vars["filter"]) :
line = {}
tmp = re.split('\t+| +', row)
......
......@@ -204,13 +204,15 @@ def index():
query = query.sort(lambda row : row.patient[request.vars["sort"]], reverse=reverse)
##filter
if "filter" in request.vars and request.vars["filter"] != "":
for row in query :
row.string = (row.confs+row.groups+row.patient.last_name+row.patient.first_name+str(row.patient.birth)).lower()+row.patient.info
query = query.find(lambda row : row.string.find(request.vars["filter"].lower()) != -1)
else :
if "filter" not in request.vars :
request.vars["filter"] = ""
for row in query :
row.string = (row.confs+row.groups+row.patient.last_name+row.patient.first_name+str(row.patient.birth)).lower()+row.patient.info
query = query.find(lambda row : vidjil_utils.filter(row.string,request.vars["filter"]) )
return dict(query = query,
count = count,
isAdmin = isAdmin,
......
# coding: utf8
import gluon.contrib.simplejson
import vidjil_utils
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
......@@ -43,12 +45,13 @@ def index():
query = query.sort(lambda row : row.sequence_file[request.vars["sort"]], reverse=reverse)
##filter
if "filter" in request.vars and 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()
query = query.find(lambda row : row.string.find(request.vars["filter"].lower()) != -1)
else :
##filter
if "filter" not in request.vars :
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()
query = query.find(lambda row : vidjil_utils.filter(row.string,request.vars["filter"]) )
return dict(query = query,
reverse=reverse)
......
......@@ -59,3 +59,18 @@ def anon(patient_id, user_id):
name += ' (%s)' % patient_id
return name
# take a string to check and a filter_str (list of word to find (or not))
# return true if the string respect the filter list
def filter(str, filter_str):
filter_list = filter_str.split(" ")
for f in filter_list :
if len(f) > 0 and f[0] == "-" :
if str.lower().find(f[1:].lower()) != -1 :
return False
else :
if str.lower().find(f.lower()) == -1 :
return False
return True
Markdown is supported
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