mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Cleanup to_json caller, slightly improve exception handlers
This commit is contained in:
@@ -2418,33 +2418,35 @@ class Tool( object, Dictifiable ):
|
||||
current_state = group_state
|
||||
iterate(tool_dict['cases'][i]['inputs'], input.cases[i].inputs, current_state, other_values)
|
||||
else:
|
||||
# create input dictionary, try to pass other_values if to_dict function supports it e.g. dynamic options
|
||||
# identify name
|
||||
input_name = tool_dict.get('name')
|
||||
|
||||
# create expanded input dictionary incl. repeats and dynamic_parameters
|
||||
try:
|
||||
tool_dict = input.to_dict(trans, other_values=other_values)
|
||||
except Exception:
|
||||
log.exception('tools::to_json() - Skipping parameter expansion for %s.' % input_name)
|
||||
pass
|
||||
|
||||
# identify name
|
||||
input_name = tool_dict.get('name')
|
||||
if input_name:
|
||||
# backup default value
|
||||
try:
|
||||
tool_dict['default_value'] = input.get_initial_value(trans, other_values)
|
||||
except Exception:
|
||||
# get initial value failed due to improper late validation
|
||||
tool_dict['default_value'] = None
|
||||
pass
|
||||
# backup default value
|
||||
try:
|
||||
tool_dict['default_value'] = input.get_initial_value(trans, other_values)
|
||||
except Exception:
|
||||
log.exception('tools::to_json() - Getting initial value failed %s.' % input_name)
|
||||
# get initial value failed due to improper late validation
|
||||
tool_dict['default_value'] = None
|
||||
pass
|
||||
|
||||
# update input value from tool state
|
||||
tool_dict['value'] = state_inputs.get(input_name, None)
|
||||
# update input value from tool state
|
||||
tool_dict['value'] = state_inputs.get(input_name, None)
|
||||
|
||||
# sanitize values
|
||||
sanitize(tool_dict, 'value')
|
||||
sanitize(tool_dict, 'default_value')
|
||||
# sanitize values
|
||||
sanitize(tool_dict, 'value')
|
||||
sanitize(tool_dict, 'default_value')
|
||||
|
||||
# use default value
|
||||
if tool_dict['value'] is None:
|
||||
tool_dict['value'] = tool_dict['default_value']
|
||||
# use default value
|
||||
if tool_dict['value'] is None:
|
||||
tool_dict['value'] = tool_dict['default_value']
|
||||
|
||||
# backup final input dictionary
|
||||
group_inputs[input_index] = tool_dict
|
||||
|
||||
@@ -202,7 +202,7 @@ class ToolParameter( object, Dictifiable ):
|
||||
for validator in self.validators:
|
||||
validator.validate( value, history )
|
||||
|
||||
def to_dict( self, trans, view='collection', value_mapper=None ):
|
||||
def to_dict( self, trans, view='collection', value_mapper=None, other_values={} ):
|
||||
""" to_dict tool parameter. This can be overridden by subclasses. """
|
||||
tool_dict = super( ToolParameter, self ).to_dict()
|
||||
#TODO: wrapping html as it causes a lot of errors on subclasses - needs histories, etc.
|
||||
@@ -277,7 +277,7 @@ class TextToolParameter( ToolParameter ):
|
||||
def get_initial_value( self, trans, context, history=None ):
|
||||
return self.value
|
||||
|
||||
def to_dict( self, trans, view='collection', value_mapper=None ):
|
||||
def to_dict( self, trans, view='collection', value_mapper=None, other_values={} ):
|
||||
d = super(TextToolParameter, self).to_dict(trans)
|
||||
d['area'] = self.area
|
||||
d['size'] = self.size
|
||||
@@ -482,7 +482,7 @@ class BooleanToolParameter( ToolParameter ):
|
||||
else:
|
||||
return self.falsevalue
|
||||
|
||||
def to_dict( self, trans, view='collection', value_mapper=None ):
|
||||
def to_dict( self, trans, view='collection', value_mapper=None, other_values={} ):
|
||||
d = super(BooleanToolParameter, self).to_dict(trans)
|
||||
d['value'] = self.checked
|
||||
d['truevalue'] = self.truevalue
|
||||
@@ -692,7 +692,7 @@ class BaseURLToolParameter( ToolParameter ):
|
||||
# BaseURLToolParameters are ultimately "hidden" parameters
|
||||
return None
|
||||
|
||||
def to_dict( self, trans, view='collection', value_mapper=None ):
|
||||
def to_dict( self, trans, view='collection', value_mapper=None, other_values={} ):
|
||||
d = super( BaseURLToolParameter, self ).to_dict( trans )
|
||||
d['value'] = self.get_value( trans )
|
||||
return d
|
||||
@@ -1079,7 +1079,7 @@ class GenomeBuildParameter( SelectToolParameter ):
|
||||
def get_legal_values( self, trans, other_values ):
|
||||
return set( dbkey for dbkey, _ in self._get_dbkey_names( trans=trans ) )
|
||||
|
||||
def to_dict( self, trans, view='collection', value_mapper=None ):
|
||||
def to_dict( self, trans, view='collection', value_mapper=None, other_values={} ):
|
||||
# skip SelectToolParameter (the immediate parent) bc we need to get options in a different way here
|
||||
d = ToolParameter.to_dict( self, trans )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user