Implement equivalent of dataset display through the API.

This commit is contained in:
John Chilton
2013-02-25 23:09:22 -06:00
parent ae11991ffb
commit 5e36c3f50f
4 changed files with 47 additions and 6 deletions
+1 -1
View File
@@ -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
+14 -5
View File
@@ -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:
@@ -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 ):
"""
+5
View File
@@ -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',