3 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/579c0b64e463/ changeset: 579c0b64e463 user: jgoecks date: 2013-03-18 22:17:14 summary: When possible, move HDA attribute addition from controller method down to model. affected #: 2 files diff -r a7bd59964f5053133897e6e7b89065a608e11d03 -r 579c0b64e463918691bb38e718af8d70dd6f9fa7 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -1516,6 +1516,11 @@ # other model classes. hda = self rval = dict( id = hda.id, + uuid = ( lambda uuid: str( uuid ) if uuid else None )( hda.dataset.uuid ), + history_id = hda.history.id, + hid = hda.hid, + file_ext = hda.ext, + peek = ( lambda hda: hda.display_peek() if hda.peek and hda.peek != 'no peek' else None )( hda ), model_class = self.__class__.__name__, name = hda.name, deleted = hda.deleted, diff -r a7bd59964f5053133897e6e7b89065a608e11d03 -r 579c0b64e463918691bb38e718af8d70dd6f9fa7 lib/galaxy/webapps/galaxy/api/history_contents.py --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -195,20 +195,16 @@ return "Not implemented." -#TODO: move these into model def get_hda_dict( trans, history, hda, for_editing ): hda_dict = hda.get_api_value( view='element' ) - hda_dict[ 'id' ] = trans.security.encode_id( hda.id ) - hda_dict[ 'history_id' ] = trans.security.encode_id( history.id ) - hda_dict[ 'hid' ] = hda.hid - - hda_dict[ 'file_ext' ] = hda.ext + # Add additional attributes that depend on trans can hence must be added here rather than at the model level. if trans.user_is_admin() or trans.app.config.expose_dataset_path: hda_dict[ 'file_name' ] = hda.file_name if not hda_dict[ 'deleted' ]: - hda_dict[ 'download_url' ] = url_for( 'history_contents_display', history_id = trans.security.encode_id( history.id ), history_content_id = trans.security.encode_id( hda.id ) ) + hda_dict[ 'download_url' ] = url_for( 'history_contents_display', history_id = trans.security.encode_id( history.id ), + history_content_id = trans.security.encode_id( hda.id ) ) can_access_hda = trans.app.security_agent.can_access_dataset( trans.get_current_user_roles(), hda.dataset ) hda_dict[ 'accessible' ] = ( trans.user_is_admin() or can_access_hda ) @@ -224,22 +220,14 @@ hda_dict[ 'display_apps' ] = get_display_apps( trans, hda ) hda_dict[ 'display_types' ] = get_old_display_applications( trans, hda ) - - if hda.dataset.uuid is None: - hda_dict['uuid'] = None - else: - hda_dict['uuid'] = str(hda.dataset.uuid) - hda_dict[ 'visualizations' ] = hda.get_visualizations() - if hda.peek and hda.peek != 'no peek': - hda_dict[ 'peek' ] = to_unicode( hda.display_peek() ) if hda.creating_job and hda.creating_job.tool_id: tool_used = trans.app.toolbox.get_tool( hda.creating_job.tool_id ) if tool_used and tool_used.force_history_refresh: hda_dict[ 'force_history_refresh' ] = True - return hda_dict + return trans.security.encode_dict_ids( hda_dict ) def get_display_apps( trans, hda ): #TODO: make more straightforward (somehow) https://bitbucket.org/galaxy/galaxy-central/commits/c39687f63b9a/ changeset: c39687f63b9a user: jgoecks date: 2013-03-18 22:18:31 summary: Remove unused parameter. affected #: 1 file diff -r 579c0b64e463918691bb38e718af8d70dd6f9fa7 -r c39687f63b9afb75c56102ec89431997a586a656 lib/galaxy/webapps/galaxy/api/history_contents.py --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -67,7 +67,7 @@ if encoded_hda_id in ids: #TODO: share code with show try: - rval.append( get_hda_dict( trans, history, hda, for_editing=True ) ) + rval.append( get_hda_dict( trans, history, hda ) ) except Exception, exc: # don't fail entire list if hda err's, record and move on @@ -149,7 +149,7 @@ hda = self.get_history_dataset_association( trans, history, id, check_ownership=True, check_accessible=True ) - hda_dict = get_hda_dict( trans, history, hda, for_editing=True ) + hda_dict = get_hda_dict( trans, history, hda ) except Exception, e: msg = "Error in history API at listing dataset: %s" % ( str(e) ) @@ -195,7 +195,7 @@ return "Not implemented." -def get_hda_dict( trans, history, hda, for_editing ): +def get_hda_dict( trans, history, hda ): hda_dict = hda.get_api_value( view='element' ) # Add additional attributes that depend on trans can hence must be added here rather than at the model level. https://bitbucket.org/galaxy/galaxy-central/commits/ef7f32032b55/ changeset: ef7f32032b55 user: jgoecks date: 2013-03-18 22:38:31 summary: Move get_hda_dict and associated methods from history_contents controller to HDA mixin. Use get_hda_dict in datasets controller; this unifies the dataset dictionary returns by API controllers. affected #: 3 files diff -r c39687f63b9afb75c56102ec89431997a586a656 -r ef7f32032b55995657d15af8b173613461dd49af lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -6,12 +6,16 @@ import os import re import pkg_resources +import urllib pkg_resources.require("SQLAlchemy >= 0.4") +pkg_resources.require( "Routes" ) +import routes from sqlalchemy import func, and_, select from paste.httpexceptions import HTTPBadRequest, HTTPInternalServerError, HTTPNotImplemented, HTTPRequestRangeNotSatisfiable from galaxy import util, web +from gettext import gettext from galaxy.datatypes.interval import ChromatinInteractions from galaxy.exceptions import ItemAccessibilityException, ItemDeletionException, ItemOwnershipException, MessageException from galaxy.security.validate_user_input import validate_publicname @@ -25,6 +29,11 @@ from galaxy.datatypes.data import Text +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 @@ -322,6 +331,85 @@ return dataset.conversion_messages.PENDING return None + def get_hda_dict( self, trans, hda ): + hda_dict = hda.get_api_value( view='element' ) + history = hda.history + + # Add additional attributes that depend on trans can hence must be added here rather than at the model level. + if trans.user_is_admin() or trans.app.config.expose_dataset_path: + hda_dict[ 'file_name' ] = hda.file_name + + if not hda_dict[ 'deleted' ]: + hda_dict[ 'download_url' ] = url_for( 'history_contents_display', history_id = trans.security.encode_id( history.id ), + history_content_id = trans.security.encode_id( hda.id ) ) + + can_access_hda = trans.app.security_agent.can_access_dataset( trans.get_current_user_roles(), hda.dataset ) + hda_dict[ 'accessible' ] = ( trans.user_is_admin() or can_access_hda ) + hda_dict[ 'api_type' ] = "file" + + if not( hda.purged or hda.deleted or hda.dataset.purged ): + meta_files = [] + for meta_type in hda.metadata.spec.keys(): + if isinstance( hda.metadata.spec[ meta_type ].param, FileParameter ): + meta_files.append( dict( file_type=meta_type ) ) + if meta_files: + hda_dict[ 'meta_files' ] = meta_files + + hda_dict[ 'display_apps' ] = self.get_display_apps( trans, hda ) + hda_dict[ 'display_types' ] = self.get_old_display_applications( trans, hda ) + hda_dict[ 'visualizations' ] = hda.get_visualizations() + + if hda.creating_job and hda.creating_job.tool_id: + tool_used = trans.app.toolbox.get_tool( hda.creating_job.tool_id ) + if tool_used and tool_used.force_history_refresh: + hda_dict[ 'force_history_refresh' ] = True + + return trans.security.encode_dict_ids( hda_dict ) + + def get_display_apps( self, trans, hda ): + #TODO: make more straightforward (somehow) + display_apps = [] + + 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(): + 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 ) + }) + display_apps.append( dict( label=display_app.name, links=app_links ) ) + + return display_apps + + def get_old_display_applications( self, trans, hda ): + 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 ) + + 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 ) ) + + return display_apps + class UsesLibraryMixin: diff -r c39687f63b9afb75c56102ec89431997a586a656 -r ef7f32032b55995657d15af8b173613461dd49af lib/galaxy/webapps/galaxy/api/datasets.py --- a/lib/galaxy/webapps/galaxy/api/datasets.py +++ b/lib/galaxy/webapps/galaxy/api/datasets.py @@ -50,8 +50,11 @@ elif data_type == 'genome_data': rval = self._get_genome_data( trans, dataset, kwd.get('dbkey', None) ) else: - # Default: return dataset as API value. - rval = dataset.get_api_value() + # Default: return dataset as dict. + if hda_ldda == 'hda': + rval = self.get_hda_dict( trans, dataset ) + else: + rval = dataset.get_api_value() except Exception, e: rval = "Error in dataset API at listing contents: " + str( e ) diff -r c39687f63b9afb75c56102ec89431997a586a656 -r ef7f32032b55995657d15af8b173613461dd49af lib/galaxy/webapps/galaxy/api/history_contents.py --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -2,24 +2,12 @@ API operations on the contents of a history. """ import logging -import urllib -from gettext import gettext from galaxy import web from galaxy.web.base.controller import BaseAPIController, url_for from galaxy.web.base.controller import UsesHistoryDatasetAssociationMixin, UsesHistoryMixin from galaxy.web.base.controller import UsesLibraryMixin, UsesLibraryMixinItems -from galaxy.web.framework.helpers import to_unicode -from galaxy.datatypes.display_applications import util -from galaxy.datatypes.metadata import FileParameter - -from galaxy.datatypes.display_applications.link_generator import get_display_app_link_generator - -import pkg_resources -pkg_resources.require( "Routes" ) -import routes - log = logging.getLogger( __name__ ) class HistoryContentsController( BaseAPIController, UsesHistoryDatasetAssociationMixin, UsesHistoryMixin, @@ -67,7 +55,7 @@ if encoded_hda_id in ids: #TODO: share code with show try: - rval.append( get_hda_dict( trans, history, hda ) ) + rval.append( self.get_hda_dict( trans, hda ) ) except Exception, exc: # don't fail entire list if hda err's, record and move on @@ -149,7 +137,7 @@ hda = self.get_history_dataset_association( trans, history, id, check_ownership=True, check_accessible=True ) - hda_dict = get_hda_dict( trans, history, hda ) + hda_dict = self.get_hda_dict( trans, hda ) except Exception, e: msg = "Error in history API at listing dataset: %s" % ( str(e) ) @@ -194,81 +182,3 @@ trans.response.status = 403 return "Not implemented." - -def get_hda_dict( trans, history, hda ): - hda_dict = hda.get_api_value( view='element' ) - - # Add additional attributes that depend on trans can hence must be added here rather than at the model level. - if trans.user_is_admin() or trans.app.config.expose_dataset_path: - hda_dict[ 'file_name' ] = hda.file_name - - if not hda_dict[ 'deleted' ]: - hda_dict[ 'download_url' ] = url_for( 'history_contents_display', history_id = trans.security.encode_id( history.id ), - history_content_id = trans.security.encode_id( hda.id ) ) - - can_access_hda = trans.app.security_agent.can_access_dataset( trans.get_current_user_roles(), hda.dataset ) - hda_dict[ 'accessible' ] = ( trans.user_is_admin() or can_access_hda ) - hda_dict[ 'api_type' ] = "file" - - if not( hda.purged or hda.deleted or hda.dataset.purged ): - meta_files = [] - for meta_type in hda.metadata.spec.keys(): - if isinstance( hda.metadata.spec[ meta_type ].param, FileParameter ): - meta_files.append( dict( file_type=meta_type ) ) - if meta_files: - hda_dict[ 'meta_files' ] = meta_files - - hda_dict[ 'display_apps' ] = get_display_apps( trans, hda ) - hda_dict[ 'display_types' ] = get_old_display_applications( trans, hda ) - hda_dict[ 'visualizations' ] = hda.get_visualizations() - - if hda.creating_job and hda.creating_job.tool_id: - tool_used = trans.app.toolbox.get_tool( hda.creating_job.tool_id ) - if tool_used and tool_used.force_history_refresh: - hda_dict[ 'force_history_refresh' ] = True - - return trans.security.encode_dict_ids( hda_dict ) - -def get_display_apps( trans, hda ): - #TODO: make more straightforward (somehow) - display_apps = [] - - def get_display_app_url( display_app_link, hda, trans ): - web_url_for = routes.URLGenerator( trans.webapp.mapper, trans.environ ) - dataset_hash, user_hash = 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(): - 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 ) - }) - display_apps.append( dict( label=display_app.name, links=app_links ) ) - - return display_apps - -def get_old_display_applications( trans, hda ): - 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 ) - - 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 ) ) - - 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.