Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit c4382266 authored by Ryan Herbert's avatar Ryan Herbert
Browse files

sample_set* models/tag.py search tags with search box

Tag searching is now managed in the search box entirely. The contents is
filtered and separated into tags and search strings in order to provide
an easier way for users to manipulate tags and filter results in a
seamless manner.
parent 2c8e95b0
......@@ -165,7 +165,13 @@ def all():
page = int(request.vars['page'])
step = 50
list = SampleSetList(type, page, step, tag=request.vars['tag'])
##filter
if "filter" not in request.vars :
request.vars["filter"] = ""
search, tags = parse_search(request.vars["filter"])
list = SampleSetList(type, page, step, tags=tags)
list.load_creator_names()
list.load_sample_information()
list.load_config_information()
......@@ -191,15 +197,8 @@ def all():
else:
result = sorted(result, key = lambda row : row.id, reverse=not reverse)
##filter
if "filter" not in request.vars :
request.vars["filter"] = ""
if "tag" not in request.vars:
request.vars["tag"] = ""
result = helper.filter(request.vars['filter'], result)
log.debug("%s list (%.3fs) %s" % (request.vars["type"], time.time()-start, request.vars["filter"]))
result = helper.filter(search, result)
log.debug("%s list (%.3fs) %s" % (request.vars["type"], time.time()-start, search))
return dict(query = result,
......@@ -373,12 +372,12 @@ def custom():
)
myGroupBy = db.sequence_file.id|db.patient.id|db.run.id|db.generic.id|db.results_file.config_id
if "tag" in request.vars:
q = (q
& (db.tag.name == request.vars["tag"])
& (db.tag_ref.tag_id == db.tag.id)
& (db.tag_ref.table_name == 'sequence_file')
& (db.tag_ref.record_id == db.sequence_file.id))
##filter
if "filter" not in request.vars :
request.vars["filter"] = ""
search, tags = parse_search(request.vars["filter"])
q = filter_by_tags(q, 'sequence_file', tags)
query = db(q).select(
db.patient.id, db.patient.info, db.patient.first_name, db.patient.last_name,
......@@ -397,10 +396,6 @@ def custom():
groupby = myGroupBy
)
##filter
if "filter" not in request.vars :
request.vars["filter"] = ""
for row in query :
row.checked = False
if (str(row.results_file.id) in request.vars["custom_list"]) :
......@@ -416,14 +411,14 @@ def custom():
row.names = row.generic.name
info = row.generic.info
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), info]
query = query.find(lambda row : ( vidjil_utils.advanced_filter(row.string,request.vars["filter"]) or row.checked) )
query = query.find(lambda row : ( vidjil_utils.advanced_filter(row.string,search) or row.checked) )
if config :
query = query.find(lambda row : ( row.results_file.config_id==config_id or (str(row.results_file.id) in request.vars["custom_list"])) )
tag_decorator = TagDecorator(get_tag_prefix())
log.debug("sample_set/custom (%.3fs) %s" % (time.time()-start, request.vars["filter"]))
log.debug("sample_set/custom (%.3fs) %s" % (time.time()-start, search))
return dict(query=query,
config_id=config_id,
......
class SampleSetList():
def __init__(self, type, page=None, step=None, tag=None):
def __init__(self, type, page=None, step=None, tags=None):
self.type = type
limitby = None
......@@ -7,12 +7,7 @@ class SampleSetList():
limitby = (page*step, (page+1)*step+1) # one more element to indicate if another page exists
query = (auth.vidjil_accessible_query(PermissionEnum.read.value, db[type]))
if tag is not None:
query = (query
& (db.tag.name == tag)
& (db.tag_ref.tag_id == db.tag.id)
& (db.tag_ref.table_name == self.type)
& (db.tag_ref.record_id == db[type].id))
query = filter_by_tags(query, self.type, tags)
query_gss = db(
query
......@@ -119,3 +114,12 @@ class SampleSetList():
def __len__(self):
return len(self.element_ids)
def filter_by_tags(query, table, tags):
if tags is not None and len(tags) > 0:
return (query
& (db.tag.name.belongs(tags))
& (db.tag_ref.tag_id == db.tag.id)
& (db.tag_ref.table_name == table)
& (db.tag_ref.record_id == db[table].id))
return query
......@@ -68,7 +68,7 @@ class TagDecorator(TagManager):
def decoration(self, ltype, stype, target):
this = "$(this)" # hack to solve some character escaping issues
return r'<a onclick="event.preventDefault();event.stopPropagation();db.callLinkable(%s)" href="%s" class="%s-link" data-sample-type="%s" data-linkable-type="%s" data-linkable-name="\1">%s\1</a>' % (this, target, ltype, stype, ltype, self.prefix)
return r'<a onclick="event.preventDefault();event.stopPropagation();db.callLinkable(%s)" href="%s" class="%s-link" data-sample-type="%s" data-linkable-type="%s" data-linkable-target-param="%s" data-linkable-name="%s\1">%s\1</a>' % (this, target, ltype, stype, ltype, "filter", self.prefix, self.prefix)
def decorate(self, text, ltype, stype, target):
if (text is None):
......@@ -79,7 +79,7 @@ class TagDecorator(TagManager):
return XML(text,
sanitize=True,
permitted_tags=['a'],
allowed_attributes={'a':['class', 'href', 'onclick', 'data-sample-type', 'data-linkable-type', 'data-linkable-name']})
allowed_attributes={'a':['class', 'href', 'onclick', 'data-sample-type', 'data-linkable-type', 'data-linkable-target-param', 'data-linkable-name']})
def get_tag_prefix():
try:
......
......@@ -8,7 +8,7 @@
<div class="db_block">
<div class="db_block_left">
search
<input id="db_filter_input" type="text" value="{{=request.vars["tag"] + " "}}{{=request.vars["filter"]}}" onchange="db.call('sample_set/all', {'type': '{{=helper.get_type()}}', 'filter' : this.value} )">
<input id="db_filter_input" type="text" value="{{=request.vars["filter"]}}" onchange="db.call('sample_set/all', {'type': '{{=helper.get_type()}}', 'filter' : this.value} )">
</div>
</div>
......
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