Extending sample search to include search using form fields. Resolved #489

This commit is contained in:
Ramkrishna Chakrabarty
2011-03-09 15:33:04 -05:00
parent a5ea34e29a
commit d26b62573c
2 changed files with 22 additions and 1 deletions
+15 -1
View File
@@ -748,6 +748,20 @@ class RequestsCommon( BaseController, UsesFormDefinitions ):
trans.model.SampleDataset.table.c.sample_id==trans.model.Sample.table.c.id,
func.lower( trans.model.SampleDataset.table.c.name ).like( "%" + search_string.lower() + "%" ) ) ) \
.order_by( trans.model.Sample.table.c.create_time.desc() )
elif search_type == 'form value':
samples = []
if search_string.find('=') != -1:
field_label, field_value = search_string.split('=')
all_samples = trans.sa_session.query( trans.model.Sample ) \
.filter( trans.model.Sample.table.c.deleted==False ) \
.order_by( trans.model.Sample.table.c.create_time.desc() )
for sample in all_samples:
# find the field in the sample form with the given label
for field in sample.request.type.sample_form.fields:
if field_label == field['label']:
# check if the value is equal to the value in the search string
if sample.values.content[ field['name'] ] == field_value:
samples.append( sample )
if is_admin:
for s in samples:
if not s.request.deleted and s.request.state in request_states:
@@ -770,7 +784,7 @@ class RequestsCommon( BaseController, UsesFormDefinitions ):
display='checkboxes' )
# Build the search_type SelectField
selected_value = kwd.get( 'search_type', 'sample name' )
types = [ 'sample name', 'bar_code', 'dataset' ]
types = [ 'sample name', 'bar_code', 'dataset', 'form value' ]
search_type = build_select_field( trans, types, 'self', 'search_type', selected_value=selected_value, refresh_on_change=False )
# Build the search_box TextField
search_box = TextField( 'search_box', 50, kwd.get('search_box', '' ) )
@@ -47,8 +47,15 @@
${search_box.get_html()}
<input type="submit" name="find_samples_button" value="Find"/>
<div class="toolParamHelp" style="clear: both;">
<p>
Wildcard search (%) can be used as placeholder for any sequence of characters or words.<br/>
For example, to search for samples starting with 'mysample' use 'mysample%' as the search string.
</p>
<p>
When 'form value' search type is selected, then enter the search string in 'field label=value' format.
<br/>For example, when searching for all samples whose 'Volume' field is 1.3mL, then the search string
should be 'Volume=1.3mL' (without qoutes).
</p>
</div>
</div>
%if results: