Merge pull request #2499 from dannon/user_tool_filter_fixes

Toolbox filter fixes
This commit is contained in:
Martin Cech
2016-06-14 15:42:03 -04:00
committed by GitHub
2 changed files with 13 additions and 27 deletions
+2 -2
View File
@@ -55,13 +55,13 @@ class FilterFactory( object ):
def __init_filters( self, key, filters, toolbox_filters, validate=None ):
for filter in filters:
if validate is None or filter in validate or filter in self.default_filters:
filter_function = self.__build_filter_function( filter )
filter_function = self._build_filter_function( filter )
toolbox_filters[ key ].append( filter_function )
else:
log.warning( "Refusing to load %s filter '%s' which is not defined in config", key, filter )
return toolbox_filters
def __build_filter_function( self, filter_name ):
def _build_filter_function( self, filter_name ):
"""Obtain python function (importing a submodule if needed)
corresponding to filter_name.
"""
+11 -25
View File
@@ -22,6 +22,7 @@ from galaxy.security.validate_user_input import (transform_publicname,
validate_email,
validate_password,
validate_publicname)
from galaxy.tools.toolbox.filters import FilterFactory
from galaxy.util import biostar, hash_util, docstring_trim, listify
from galaxy.web import url_for
from galaxy.web.base.controller import (BaseUIController,
@@ -1269,7 +1270,7 @@ class User( BaseUIController, UsesFormDefinitionsMixin, CreatesUsersMixin, Creat
The user can activate them and the choice is stored in user_preferences.
"""
def get_filter_mapping( db_filters, config_filters ):
def get_filter_mapping( db_filters, config_filters, factory ):
"""
Compare the allowed filters from the galaxy.ini config file with the previously saved or default filters from the database.
We need that to toogle the checkboxes for the formular in the right way.
@@ -1277,17 +1278,7 @@ class User( BaseUIController, UsesFormDefinitionsMixin, CreatesUsersMixin, Creat
"""
filters = list()
for filter_name in config_filters:
if ":" in filter_name:
# Should be a submodule of filters (e.g. examples:restrict_development_tools)
(module_name, function_name) = filter_name.rsplit(":", 1)
module_name = 'galaxy.tools.filters.%s' % module_name.strip()
module = __import__( module_name, globals(), fromlist=['temp_module'] )
function = getattr( module, function_name.strip() )
else:
# No module found it has to be explicitly imported.
module = __import__( 'galaxy.tools.filters', globals(), fromlist=['temp_module'] )
function = getattr( globals(), filter_name.strip() )
function = factory._build_filter_function(filter_name)
doc_string = docstring_trim( function.__doc__ )
split = doc_string.split('\n\n')
if split:
@@ -1328,9 +1319,10 @@ class User( BaseUIController, UsesFormDefinitionsMixin, CreatesUsersMixin, Creat
elif name == 'toolbox_label_filters':
saved_user_label_filters = listify( value, do_strip=True )
tool_filters = get_filter_mapping( saved_user_tool_filters, trans.app.config.user_tool_filters )
section_filters = get_filter_mapping( saved_user_section_filters, trans.app.config.user_section_filters )
label_filters = get_filter_mapping( saved_user_label_filters, trans.app.config.user_label_filters )
ff = FilterFactory(trans.app.toolbox)
tool_filters = get_filter_mapping( saved_user_tool_filters, trans.app.config.user_tool_filters, ff )
section_filters = get_filter_mapping( saved_user_section_filters, trans.app.config.user_section_filters, ff )
label_filters = get_filter_mapping( saved_user_label_filters, trans.app.config.user_label_filters, ff )
return trans.fill_template( 'user/toolbox_filters.mako',
cntrller=cntrller,
@@ -1349,12 +1341,6 @@ class User( BaseUIController, UsesFormDefinitionsMixin, CreatesUsersMixin, Creat
def edit_toolbox_filters( self, trans, cntrller, **kwd ):
params = util.Params( kwd )
message = util.restore_text( params.get( 'message', '' ) )
user_id = params.get( 'user_id', False )
if not user_id:
# User must be logged in to create a new address
return trans.show_error_message( "You must be logged in to change the ToolBox filters." )
user = trans.sa_session.query( trans.app.model.User ).get( trans.security.decode_id( user_id ) )
if params.get( 'edit_toolbox_filter_button', False ):
tool_filters = list()
@@ -1368,11 +1354,11 @@ class User( BaseUIController, UsesFormDefinitionsMixin, CreatesUsersMixin, Creat
label_filters.append( name[2:] )
elif name.startswith('s_'):
section_filters.append( name[2:] )
user.preferences['toolbox_tool_filters'] = ','.join( tool_filters )
user.preferences['toolbox_section_filters'] = ','.join( section_filters )
user.preferences['toolbox_label_filters'] = ','.join( label_filters )
trans.user.preferences['toolbox_tool_filters'] = ','.join( tool_filters )
trans.user.preferences['toolbox_section_filters'] = ','.join( section_filters )
trans.user.preferences['toolbox_label_filters'] = ','.join( label_filters )
trans.sa_session.add( user )
trans.sa_session.add( trans.user )
trans.sa_session.flush()
message = 'ToolBox filters has been updated.'
kwd = dict( message=message, status='done' )