commit/galaxy-central: carlfeberhard: Visualizations registry: decompose get_visualzations into both single vis check and all registered check
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/80dcf7e41b4a/ Changeset: 80dcf7e41b4a User: carlfeberhard Date: 2013-06-24 23:47:29 Summary: Visualizations registry: decompose get_visualzations into both single vis check and all registered check Affected #: 1 file diff -r 208bb69cae38e31f60ae9650c3cc261bfda7b079 -r 80dcf7e41b4aec1d5608c05c870a634651af2924 lib/galaxy/visualization/registry.py --- a/lib/galaxy/visualization/registry.py +++ b/lib/galaxy/visualization/registry.py @@ -98,11 +98,44 @@ """ self.listings = VisualizationsConfigParser.parse( self.configuration_filepath ) - #TODO: def get_visualization( self, trans, visualization_name, target_object ): - # """ - # Is the visualization with the given `visualization_name` applicable - # to the `target_object`? - # """ + def get_visualization( self, trans, visualization_name, target_object ): + """ + Return data to build a url to the visualization with the given + `visualization_name` if it's applicable to `target_object` or + `None` if it's not. + """ + # a little weird to pass trans because this registry is part of the trans.app + listing_data = self.listings.get( visualization_name, None ) + if not listing_data: + return None + + data_sources = listing_data[ 'data_sources' ] + for data_source in data_sources: + # currently a model class is required + model_class = data_source[ 'model_class' ] + if not isinstance( target_object, model_class ): + continue + + # tests are optional - default is the above class test + tests = data_source[ 'tests' ] + if tests and not self.is_object_applicable( trans, target_object, tests ): + continue + + param_data = data_source[ 'to_params' ] + url = self.get_visualization_url( trans, target_object, visualization_name, param_data ) + link_text = listing_data.get( 'link_text', None ) + if not link_text: + # default to visualization name, titlecase, and replace underscores + link_text = visualization_name.title().replace( '_', ' ' ) + render_location = listing_data.get( 'render_location' ) + # remap some of these vars for direct use in ui.js, PopupMenu (e.g. text->html) + return { + 'href' : url, + 'html' : link_text, + 'target': render_location + } + + return None # -- building links to visualizations from objects -- def get_visualizations( self, trans, target_object ): @@ -111,36 +144,11 @@ the urls to call in order to render the visualizations. """ #TODO:?? a list of objects? YAGNI? - # a little weird to pass trans because this registry is part of the trans.app applicable_visualizations = [] - for vis_name, listing_data in self.listings.items(): - - data_sources = listing_data[ 'data_sources' ] - for data_source in data_sources: - # currently a model class is required - model_class = data_source[ 'model_class' ] - if not isinstance( target_object, model_class ): - continue - - # tests are optional - default is the above class test - tests = data_source[ 'tests' ] - if tests and not self.is_object_applicable( trans, target_object, tests ): - continue - - param_data = data_source[ 'to_params' ] - url = self.get_visualization_url( trans, target_object, vis_name, param_data ) - link_text = listing_data.get( 'link_text', None ) - if not link_text: - # default to visualization name, titlecase, and replace underscores - link_text = vis_name.title().replace( '_', ' ' ) - render_location = listing_data.get( 'render_location' ) - # remap some of these vars for direct use in ui.js, PopupMenu (e.g. text->html) - applicable_visualizations.append({ - 'href' : url, - 'html' : link_text, - 'target': render_location - }) - + for vis_name in self.listings: + url_data = self.get_visualization( trans, vis_name, target_object ) + if url_data: + applicable_visualizations.append( url_data ) return applicable_visualizations def is_object_applicable( self, trans, target_object, data_source_tests ): Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org