commit/galaxy-central: Dave Bouvier: Fix tool shed API value mappers.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/1a5f25751066/ Changeset: 1a5f25751066 User: Dave Bouvier Date: 2013-09-06 23:06:18 Summary: Fix tool shed API value mappers. Affected #: 3 files diff -r f82d49deb6d05648d2ab114cff6d689b38806d65 -r 1a5f25751066598601aef4ad34da4b3bea8deaca lib/galaxy/webapps/tool_shed/api/repositories.py --- a/lib/galaxy/webapps/tool_shed/api/repositories.py +++ b/lib/galaxy/webapps/tool_shed/api/repositories.py @@ -14,18 +14,6 @@ log = logging.getLogger( __name__ ) -def default_repository_value_mapper( trans, repository ): - value_mapper={ 'id' : trans.security.encode_id( repository.id ), - 'user_id' : trans.security.encode_id( repository.user_id ) } - return value_mapper - -def default_repository_metadata_value_mapper( trans, repository_metadata ): - value_mapper = { 'id' : trans.security.encode_id( repository_metadata.id ), - 'repository_id' : trans.security.encode_id( repository_metadata.repository_id ) } - if repository_metadata.time_last_tested: - value_mapper[ 'time_last_tested' ] = time_ago( repository_metadata.time_last_tested ) - return value_mapper - class RepositoriesController( BaseAPIController ): """RESTful controller for interactions with repositories in the Tool Shed.""" @@ -108,12 +96,17 @@ ] } """ + metadata_value_mapper = { 'id' : trans.security.encode_id, + 'repository_id' : trans.security.encode_id, + 'time_last_tested' : time_ago } + repository_value_mapper = { 'id' : trans.security.encode_id, + 'user_id' : trans.security.encode_id } # Example URL: http://localhost:9009/api/repositories/get_repository_revision_install_info?name=add_column&owner=test&changeset_revision=3a08cc21466f try: # Get the repository information. repository = suc.get_repository_by_name_and_owner( trans.app, name, owner ) encoded_repository_id = trans.security.encode_id( repository.id ) - repository_dict = repository.to_dict( view='element', value_mapper=default_repository_value_mapper( trans, repository ) ) + repository_dict = repository.to_dict( view='element', value_mapper=repository_value_mapper ) repository_dict[ 'url' ] = web.url_for( controller='repositories', action='show', id=encoded_repository_id ) @@ -130,7 +123,7 @@ if repository_metadata: encoded_repository_metadata_id = trans.security.encode_id( repository_metadata.id ) repository_metadata_dict = repository_metadata.to_dict( view='collection', - value_mapper=default_repository_metadata_value_mapper( trans, repository_metadata ) ) + value_mapper=metadata_value_mapper ) repository_metadata_dict[ 'url' ] = web.url_for( controller='repository_revisions', action='show', id=encoded_repository_metadata_id ) @@ -155,6 +148,8 @@ GET /api/repositories Displays a collection (list) of repositories. """ + value_mapper = { 'id' : trans.security.encode_id, + 'user_id' : trans.security.encode_id } # Example URL: http://localhost:9009/api/repositories repository_dicts = [] deleted = util.string_as_bool( deleted ) @@ -164,7 +159,7 @@ .order_by( trans.app.model.Repository.table.c.name ) \ .all() for repository in query: - repository_dict = repository.to_dict( view='collection', value_mapper=default_repository_value_mapper( trans, repository ) ) + repository_dict = repository.to_dict( view='collection', value_mapper=value_mapper ) repository_dict[ 'url' ] = web.url_for( controller='repositories', action='show', id=trans.security.encode_id( repository.id ) ) @@ -184,10 +179,12 @@ :param id: the encoded id of the Repository object """ + value_mapper = { 'id' : trans.security.encode_id, + 'user_id' : trans.security.encode_id } # Example URL: http://localhost:9009/api/repositories/f9cad7b01a472135 try: repository = suc.get_repository_in_tool_shed( trans, id ) - repository_dict = repository.to_dict( view='element', value_mapper=default_repository_value_mapper( trans, repository ) ) + repository_dict = repository.to_dict( view='element', value_mapper=value_mapper ) repository_dict[ 'url' ] = web.url_for( controller='repositories', action='show', id=trans.security.encode_id( repository.id ) ) diff -r f82d49deb6d05648d2ab114cff6d689b38806d65 -r 1a5f25751066598601aef4ad34da4b3bea8deaca lib/galaxy/webapps/tool_shed/api/repository_revisions.py --- a/lib/galaxy/webapps/tool_shed/api/repository_revisions.py +++ b/lib/galaxy/webapps/tool_shed/api/repository_revisions.py @@ -11,13 +11,6 @@ log = logging.getLogger( __name__ ) -def default_value_mapper( trans, repository_metadata ): - value_mapper = { 'id' : trans.security.encode_id( repository_metadata.id ), - 'repository_id' : trans.security.encode_id( repository_metadata.repository_id ) } - if repository_metadata.time_last_tested: - value_mapper[ 'time_last_tested' ] = time_ago( repository_metadata.time_last_tested ) - return value_mapper - class RepositoryRevisionsController( BaseAPIController ): """RESTful controller for interactions with tool shed repository revisions.""" @@ -79,6 +72,9 @@ GET /api/repository_revisions Displays a collection (list) of repository revisions. """ + value_mapper = { 'id' : trans.security.encode_id, + 'repository_id' : trans.security.encode_id, + 'time_last_tested' : time_ago } # Example URL: http://localhost:9009/api/repository_revisions repository_metadata_dicts = [] # Build up an anded clause list of filters. @@ -128,7 +124,7 @@ .all() for repository_metadata in query: repository_metadata_dict = repository_metadata.to_dict( view='collection', - value_mapper=default_value_mapper( trans, repository_metadata ) ) + value_mapper=value_mapper ) repository_metadata_dict[ 'url' ] = web.url_for( controller='repository_revisions', action='show', id=trans.security.encode_id( repository_metadata.id ) ) @@ -148,10 +144,13 @@ :param id: the encoded id of the `RepositoryMetadata` object """ + value_mapper = { 'id' : trans.security.encode_id, + 'repository_id' : trans.security.encode_id, + 'time_last_tested' : time_ago } # Example URL: http://localhost:9009/api/repository_revisions/bb125606ff9ea620 try: repository_metadata = metadata_util.get_repository_metadata_by_id( trans, id ) - repository_metadata_dict = repository_metadata.as_dict( value_mapper=default_value_mapper( trans, repository_metadata ) ) + repository_metadata_dict = repository_metadata.to_dict( value_mapper=value_mapper ) repository_metadata_dict[ 'url' ] = web.url_for( controller='repository_revisions', action='show', id=trans.security.encode_id( repository_metadata.id ) ) @@ -168,6 +167,7 @@ PUT /api/repository_revisions/{encoded_repository_metadata_id}/{payload} Updates the value of specified columns of the repository_metadata table based on the key / value pairs in payload. """ + value_mapper = dict( id=trans.security.encode_id, repository_id=trans.security.encode_id, time_last_tested=time_ago ) repository_metadata_id = kwd.get( 'id', None ) try: repository_metadata = metadata_util.get_repository_metadata_by_id( trans, repository_metadata_id ) @@ -188,7 +188,7 @@ log.error( message, exc_info=True ) trans.response.status = 500 return message - repository_metadata_dict = repository_metadata.as_dict( value_mapper=default_value_mapper( trans, repository_metadata ) ) + repository_metadata_dict = repository_metadata.to_dict( value_mapper=value_mapper ) repository_metadata_dict[ 'url' ] = web.url_for( controller='repository_revisions', action='show', id=trans.security.encode_id( repository_metadata.id ) ) diff -r f82d49deb6d05648d2ab114cff6d689b38806d65 -r 1a5f25751066598601aef4ad34da4b3bea8deaca lib/galaxy/webapps/tool_shed/model/__init__.py --- a/lib/galaxy/webapps/tool_shed/model/__init__.py +++ b/lib/galaxy/webapps/tool_shed/model/__init__.py @@ -154,9 +154,6 @@ self.times_downloaded = times_downloaded self.deprecated = deprecated - def as_dict( self, value_mapper=None ): - return self.to_dict( view='element', value_mapper=value_mapper ) - def can_change_type( self, app ): # Allow changing the type only if the repository has no contents, has never been installed, or has never been changed from # the default type. @@ -233,7 +230,7 @@ class RepositoryMetadata( object, Dictifiable ): dict_collection_visible_keys = ( 'id', 'repository_id', 'changeset_revision', 'malicious', 'downloadable', 'has_repository_dependencies', 'includes_datatypes', - 'includes_tools', 'includes_tool_dependencies', 'includes_tools_for_display_in_tool_panel', 'includes_workflows' ) + 'includes_tools', 'includes_tool_dependencies', 'includes_tools_for_display_in_tool_panel', 'includes_workflows', 'time_last_tested' ) dict_element_visible_keys = ( 'id', 'repository_id', 'changeset_revision', 'malicious', 'downloadable', 'tools_functionally_correct', 'do_not_test', 'test_install_error', 'time_last_tested', 'tool_test_results', 'has_repository_dependencies', 'includes_datatypes', 'includes_tools', 'includes_tool_dependencies', 'includes_tools_for_display_in_tool_panel', 'includes_workflows' ) @@ -270,9 +267,6 @@ return True return False - def as_dict( self, value_mapper=None ): - return self.to_dict( view='element', value_mapper=value_mapper ) - class SkipToolTest( object, Dictifiable ): dict_collection_visible_keys = ( 'id', 'repository_metadata_id', 'initial_changeset_revision' ) 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