From 5e36c3f50ff8ab8d8dcb704bf5e569320ba499de Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 25 Feb 2013 23:09:22 -0600 Subject: [PATCH] Implement equivalent of dataset display through the API. --- lib/galaxy/web/__init__.py | 2 +- lib/galaxy/web/framework/__init__.py | 19 +++++++++---- .../webapps/galaxy/api/history_contents.py | 27 +++++++++++++++++++ lib/galaxy/webapps/galaxy/buildapp.py | 5 ++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/web/__init__.py b/lib/galaxy/web/__init__.py index 6f5d09ba273..838bafa490d 100644 --- a/lib/galaxy/web/__init__.py +++ b/lib/galaxy/web/__init__.py @@ -2,6 +2,6 @@ The Galaxy web application framework """ -from framework import expose, json, json_pretty, require_login, require_admin, url_for, error, form, FormBuilder, expose_api +from framework import expose, json, json_pretty, require_login, require_admin, url_for, error, form, FormBuilder, expose_api, expose_api_raw from framework.base import httpexceptions diff --git a/lib/galaxy/web/framework/__init__.py b/lib/galaxy/web/framework/__init__.py index 3c109305bc9..d8e7ab5f016 100644 --- a/lib/galaxy/web/framework/__init__.py +++ b/lib/galaxy/web/framework/__init__.py @@ -99,7 +99,14 @@ def require_login( verb="perform this action", use_panels=False, webapp='galaxy' return decorator return argcatcher -def expose_api( func ): +def expose_api_raw( func ): + """ + Expose this function via the API but don't dump the results + to JSON. + """ + return expose_api( func, to_json=False ) + +def expose_api( func, to_json=True ): @wraps(func) def decorator( self, trans, *args, **kwargs ): def error( environ, start_response ): @@ -183,10 +190,12 @@ def expose_api( func ): trans.response.status = 400 return "That user does not exist." try: - if trans.debug: - return simplejson.dumps( func( self, trans, *args, **kwargs ), indent=4, sort_keys=True ) - else: - return simplejson.dumps( func( self, trans, *args, **kwargs ) ) + rval = func( self, trans, *args, **kwargs) + if to_json and trans.debug: + rval = simplejson.dumps( rval, indent=4, sort_keys=True ) + elif to_json: + rval = simplejson.dumps( rval ) + return rval except paste.httpexceptions.HTTPException: raise # handled except: diff --git a/lib/galaxy/webapps/galaxy/api/history_contents.py b/lib/galaxy/webapps/galaxy/api/history_contents.py index 45771ece974..32a60436922 100644 --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -125,6 +125,33 @@ class HistoryContentsController( BaseAPIController, UsesHistoryDatasetAssociatio 'error' : str( exception ) } + @web.expose_api_raw + def display( self, trans, history_content_id, history_id, preview=False, filename=None, to_ext=None, chunk=None, **kwd ): + """ + GET /api/histories/{encoded_history_id}/contents/{encoded_content_id} + Displays history content (dataset). + """ + hda_dict = {} + try: + # for anon users: + #TODO: check login_required? + #TODO: this isn't actually most_recently_used (as defined in histories) + if( ( trans.user == None ) + and ( history_id == trans.security.encode_id( trans.history.id ) ) ): + history = trans.history + #TODO: dataset/hda by id (from history) OR check_ownership for anon user + hda = self.get_history_dataset_association( trans, history, history_content_id, + check_ownership=False, check_accessible=True ) + + else: + history = self.get_history( trans, history_id, + check_ownership=True, check_accessible=True, deleted=False ) + hda = self.get_history_dataset_association( trans, history, history_content_id, + check_ownership=True, check_accessible=True ) + except: + raise + return hda.datatype.display_data(trans, hda, preview, filename, to_ext, chunk, **kwd) + @web.expose_api def show( self, trans, id, history_id, **kwd ): """ diff --git a/lib/galaxy/webapps/galaxy/buildapp.py b/lib/galaxy/webapps/galaxy/buildapp.py index d60c326ff2d..4a3b056ca10 100644 --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -83,6 +83,11 @@ def app_factory( global_conf, **kwargs ): name_prefix='history_', path_prefix='/api/histories/:history_id', parent_resources=dict( member_name='history', collection_name='histories' ) ) + webapp.api_mapper.connect("history_contents_display", + "/api/histories/:history_id/contents/:history_content_id/display", + controller="history_contents", + action="display", + conditions=dict(method=["GET"])) webapp.api_mapper.resource( 'permission', 'permissions', path_prefix='/api/libraries/:library_id',