commit/galaxy-central: carlfeberhard: Display applications: revert to original methods for generating urls

1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/6d84efb087eb/ Changeset: 6d84efb087eb User: carlfeberhard Date: 2013-04-18 00:58:52 Summary: Display applications: revert to original methods for generating urls Affected #: 2 files diff -r f8e235f593cd24958e52fcb436d5ab47fb9d1cee -r 6d84efb087eb040bef8d388d1ca9c29da3f48725 lib/galaxy/datatypes/display_applications/link_generator.py --- a/lib/galaxy/datatypes/display_applications/link_generator.py +++ /dev/null @@ -1,161 +0,0 @@ -"""Classes to generate links for old-style display applications. - -Separating Transaction based elements of display applications from datatypes. -""" - -#FIXME: The code contained within this file is for old-style display applications, but -#this module namespace is intended to only handle the new-style display applications. - -import urllib - -# for the url_for hack -import pkg_resources -pkg_resources.require( "Routes" ) -import routes - -from galaxy import util -from galaxy.web import url_for -from galaxy.datatypes.interval import Interval, Gff, Wiggle, CustomTrack - -#TODO: Ideally, these classes would be instantiated in the trans (or some other semi-persistant fixture) -# Currently, these are instantiated per HDA which is not the best solution - -#TODO: these could be extended to handle file_function and parse/contain the builds.txt files - -#HACK: these duplicate functionality from the individual datatype classes themselves - -def get_display_app_link_generator( display_app_name ): - """Returns an instance of the proper link generator class - based on the display_app_name or DisplayAppLinkGenerator - if the display_app_name is unrecognized. - """ - if display_app_name == 'ucsc': - return UCSCDisplayAppLinkGenerator() - - elif display_app_name == 'gbrowse': - return GBrowseDisplayAppLinkGenerator() - - return DisplayAppLinkGenerator() - - -class DisplayAppLinkGenerator( object ): - """Base class for display application link generators. - - This class returns an empty list of links for all datatypes. - """ - def __init__( self ): - self.display_app_name = '' - - def no_links_available( self, dataset, app, base_url, url_for=url_for ): - """Called when no display application links are available - for this display app name and datatype combination. - """ - return [] - - def _link_function_from_datatype( self, datatype ): - """Dispatch to proper link generating function on datatype. - """ - return self.no_links_available - - def generate_links( self, trans, dataset ): - # here's the hack - which is expensive (time) - web_url_for = routes.URLGenerator( trans.webapp.mapper, trans.environ ) - - link_function = self._link_function_from_datatype( dataset.datatype ) - display_links = link_function( dataset, trans.app, trans.request.base, url_for=web_url_for ) - - return display_links - - -class UCSCDisplayAppLinkGenerator( DisplayAppLinkGenerator ): - """Class for generating links to display data in the - UCSC genome browser. - - This class returns links for the following datatypes and their subclasses: - Interval, Wiggle, Gff, CustomTrack - """ - def __init__( self ): - self.display_app_name = 'ucsc' - - def _link_function_from_datatype( self, datatype ): - """Dispatch to proper link generating function based on datatype. - """ - if( ( isinstance( datatype, Interval ) ) - or ( isinstance( datatype, Wiggle ) ) - or ( isinstance( datatype, Gff ) ) - or ( isinstance( datatype, CustomTrack ) ) ): - return self.ucsc_links - else: - return super( UCSCDisplayAppLinkGenerator, self )._link_function_from_datatype( datatype ) - - def ucsc_links( self, dataset, app, base_url, url_for=url_for ): - """Generate links to UCSC genome browser sites based on the dbkey - and content of dataset. - """ - # this is a refactor of Interval.ucsc_links, GFF.ucsc_links, Wiggle.ucsc_links, and CustomTrack.ucsc_links - #TODO: app vars can be moved into init (and base_url as well) - chrom, start, stop = dataset.datatype.get_estimated_display_viewport( dataset ) - if chrom is None: - return [] - ret_val = [] - for site_name, site_url in util.get_ucsc_by_build(dataset.dbkey): - if site_name in app.config.ucsc_display_sites: - internal_url = url_for( controller='dataset', dataset_id=dataset.id, - action='display_at', filename='%s_%s' % ( self.display_app_name, site_name ) ) - base_url = app.config.get( "display_at_callback", base_url ) - display_url = urllib.quote_plus( "%s%s/display_as?id=%i&display_app=%s&authz_method=display_at" - % (base_url, url_for( controller='root' ), dataset.id, self.display_app_name) ) - redirect_url = urllib.quote_plus( "%sdb=%s&position=%s:%s-%s&hgt.customText=%%s" - % (site_url, dataset.dbkey, chrom, start, stop ) ) - - link = '%s?redirect_url=%s&display_url=%s' % ( internal_url, redirect_url, display_url ) - ret_val.append( ( site_name, link ) ) - - return ret_val - - -class GBrowseDisplayAppLinkGenerator( DisplayAppLinkGenerator ): - """Class for generating links to display data in the - GBrowse genome browser. - - This class returns links for the following datatypes and their subclasses: - Gff, Wiggle - """ - def __init__( self ): - self.display_app_name = 'gbrowse' - - def _link_function_from_datatype( self, datatype ): - """Dispatch to proper link generating function based on datatype. - """ - if( ( isinstance( datatype, Gff ) ) - or ( isinstance( datatype, Wiggle ) ) ): - return self.gbrowse_links - else: - return super( GBrowseDisplayAppLinkGenerator, self )._link_function_from_datatype( datatype ) - - def gbrowse_links( self, dataset, app, base_url, url_for=url_for ): - """Generate links to GBrowse genome browser sites based on the dbkey - and content of dataset. - """ - # when normalized for var names, Gff.gbrowse_links and Wiggle.gbrowse_links are the same - # also: almost identical to ucsc_links except for the 'chr' stripping, sites_by_build, config key - # could be refactored even more - chrom, start, stop = dataset.datatype.get_estimated_display_viewport( dataset ) - if chrom is None: - return [] - ret_val = [] - for site_name, site_url in util.get_gbrowse_sites_by_build( dataset.dbkey ): - if site_name in app.config.gbrowse_display_sites: - # strip chr from seqid - if chrom.startswith( 'chr' ) and len ( chrom ) > 3: - chrom = chrom[3:] - internal_url = url_for( controller='dataset', dataset_id=dataset.id, - action='display_at', filename='%s_%s' % ( self.display_app_name, site_name ) ) - redirect_url = urllib.quote_plus( "%s/?q=%s:%s..%s&eurl=%%s" % ( site_url, chrom, start, stop ) ) - base_url = app.config.get( "display_at_callback", base_url ) - display_url = urllib.quote_plus( "%s%s/display_as?id=%i&display_app=%s&authz_method=display_at" - % ( base_url, url_for( controller='root' ), dataset.id, self.display_app_name ) ) - link = '%s?redirect_url=%s&display_url=%s' % ( internal_url, redirect_url, display_url ) - ret_val.append( ( site_name, link ) ) - - return ret_val diff -r f8e235f593cd24958e52fcb436d5ab47fb9d1cee -r 6d84efb087eb040bef8d388d1ca9c29da3f48725 lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -32,8 +32,6 @@ from galaxy.datatypes.display_applications import util as da_util from galaxy.datatypes.metadata import FileParameter -from galaxy.datatypes.display_applications.link_generator import get_display_app_link_generator - log = logging.getLogger( __name__ ) # States for passing messages @@ -392,28 +390,18 @@ }) def get_display_apps( self, trans, hda ): - #TODO: make more straightforward (somehow) display_apps = [] + for display_app in hda.get_display_applications( trans ).itervalues(): - def get_display_app_url( display_app_link, hda, trans ): - web_url_for = routes.URLGenerator( trans.webapp.mapper, trans.environ ) - dataset_hash, user_hash = da_util.encode_dataset_user( trans, hda, None ) - return web_url_for( controller='dataset', - action="display_application", - dataset_id=dataset_hash, - user_id=user_hash, - app_name=urllib.quote_plus( display_app_link.display_application.id ), - link_name=urllib.quote_plus( display_app_link.id ) ) - - for display_app in hda.get_display_applications( trans ).itervalues(): app_links = [] - for display_app_link in display_app.links.itervalues(): + for link_app in display_app.links.itervalues(): app_links.append({ - 'target' : display_app_link.url.get( 'target_frame', '_blank' ), - 'href' : get_display_app_url( display_app_link, hda, trans ), - 'text' : gettext( display_app_link.name ) + 'target': link_app.url.get( 'target_frame', '_blank' ), + 'href' : link_app.get_display_url( hda, trans ), + 'text' : gettext( link_app.name ) }) - display_apps.append( dict( label=display_app.name, links=app_links ) ) + if app_links: + display_apps.append( dict( label=display_app.name, links=app_links ) ) return display_apps @@ -421,19 +409,23 @@ display_apps = [] if not trans.app.config.enable_old_display_applications: return display_apps - for display_app_name in hda.datatype.get_display_types(): - link_generator = get_display_app_link_generator( display_app_name ) - display_links = link_generator.generate_links( trans, hda ) + + for display_app in hda.datatype.get_display_types(): + target_frame, display_links = hda.datatype.get_display_links( hda, + display_app, trans.app, trans.request.base ) - app_links = [] - for display_name, display_link in display_links: - app_links.append({ - 'target' : '_blank', - 'href' : display_link, - 'text' : display_name - }) - if app_links: - display_apps.append( dict( label=hda.datatype.get_display_label( display_app_name ), links=app_links ) ) + if len( display_links ) > 0: + display_label = hda.datatype.get_display_label( display_app ) + + app_links = [] + for display_name, display_link in display_links: + app_links.append({ + 'target': target_frame, + 'href' : display_link, + 'text' : gettext( display_name ) + }) + if app_links: + display_apps.append( dict( label=display_label, links=app_links ) ) return display_apps 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