From e67ae76526f9d78f19d817e3efa4c54627183aa2 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 20 Jan 2014 12:39:50 -0600 Subject: [PATCH] Small refactor to ToolDataParameter. Break out logic for computing and asserting existence of history - simplifies get_html_field, get_initial_value_from_history_prevent_repeat, reduces code duplication, and eases some downstream merges changes I making. --- lib/galaxy/tools/parameters/basic.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index efe2935aec2..5e7cb6e7c49 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1611,9 +1611,7 @@ class DataToolParameter( ToolParameter ): filter_value = self.options.get_options( trans, other_values )[0][0] except IndexError: pass # no valid options - assert trans is not None, "DataToolParameter requires a trans" - history = trans.get_history() - assert history is not None, "DataToolParameter requires a history" + history = self._get_history( trans ) if value is not None: if type( value ) != list: value = [ value ] @@ -1683,10 +1681,7 @@ class DataToolParameter( ToolParameter ): # Can't look at history in workflow mode. Tool shed has no histories. if trans is None or trans.workflow_building_mode or trans.webapp.name == 'tool_shed': return DummyDataset() - assert trans is not None, "DataToolParameter requires a trans" - if history is None: - history = trans.get_history() - assert history is not None, "DataToolParameter requires a history" + history = self._get_history( trans, history ) if self.optional: return None most_recent_dataset = [] @@ -1860,6 +1855,14 @@ class DataToolParameter( ToolParameter ): ref = ref() return ref + def _get_history( self, trans, history=None ): + class_name = self.__class__.__name__ + assert trans is not None, "%s requires a trans" % class_name + if history is None: + history = trans.get_history() + assert history is not None, "%s requires a history" % class_name + return history + class HiddenDataToolParameter( HiddenToolParameter, DataToolParameter ): """