Skip to content

Commit

Permalink
API, histories: allow sorting by disk_size, move order parsing into m…
Browse files Browse the repository at this point in the history
…anager
  • Loading branch information
carlfeberhard committed Aug 10, 2015
1 parent 11f03d3 commit 1b64bea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
31 changes: 31 additions & 0 deletions lib/galaxy/managers/histories.py
Expand Up @@ -6,13 +6,19 @@
"""
import operator

import pkg_resources
pkg_resources.require( "SQLAlchemy >= 0.4" )
from sqlalchemy import desc, asc

from galaxy import model
from galaxy import exceptions as glx_exceptions
from galaxy.managers import sharable
from galaxy.managers import deletable
from galaxy.managers import containers
from galaxy.managers import hdas
from galaxy.managers import collections_util


import logging
log = logging.getLogger( __name__ )

Expand Down Expand Up @@ -122,6 +128,31 @@ def set_current_by_id( self, trans, history_id ):
"""
return self.set_current( trans, self.by_id( history_id ) )

# order_by parsing - similar to FilterParser but not enough yet to warrant a class?
def parse_order_by( self, order_by_string ):
"""Return an ORM compatible order_by using the given string"""
# TODO: generalize into class
# TODO: general (enough) columns
if order_by_string in ( 'create_time', 'create_time-dsc' ):
return desc( self.model_class.create_time )
if order_by_string == 'create_time-asc':
return asc( self.model_class.create_time )
if order_by_string in ( 'update_time', 'update_time-dsc' ):
return desc( self.model_class.update_time )
if order_by_string == 'update_time-asc':
return asc( self.model_class.update_time )
if order_by_string in ( 'name', 'name-asc' ):
return asc( self.model_class.name )
if order_by_string == 'name-dsc':
return desc( self.model_class.name )
# TODO: history columns
if order_by_string in ( 'size', 'name-dsc' ):
return desc( self.model_class.disk_size )
if order_by_string == 'size-asc':
return asc( self.model_class.disk_size )
raise glx_exceptions.RequestParameterInvalidException( 'Unkown order_by', order_by=order_by_string,
available=[ 'create_time', 'update_time', 'name', 'size' ])

# container interface
def _filter_to_contained( self, container, content_class ):
return content_class.history == container
Expand Down
23 changes: 3 additions & 20 deletions lib/galaxy/webapps/galaxy/api/histories.py
Expand Up @@ -421,24 +421,7 @@ def archive_download( self, trans, id, jeha_id, **kwds ):

def _parse_order_by( self, order_by_string ):
ORDER_BY_SEP_CHAR = ','
manager = self.history_manager
if ORDER_BY_SEP_CHAR in order_by_string:
return [ self._parse_single_order_by( o ) for o in order_by_string.split( ORDER_BY_SEP_CHAR ) ]
return self._parse_single_order_by( order_by_string )

def _parse_single_order_by( self, order_by_string ):
History = self.history_manager.model_class
# TODO: formalize and generalize into managers
if order_by_string in ( 'create_time', 'create_time-dsc' ):
return desc( History.create_time )
if order_by_string == 'create_time-asc':
return asc( History.create_time )
if order_by_string in ( 'update_time', 'update_time-dsc' ):
return desc( History.update_time )
if order_by_string == 'update_time-asc':
return asc( History.update_time )
if order_by_string in ( 'name', 'name-asc' ):
return asc( History.name )
if order_by_string == 'name-dsc':
return desc( History.name )
raise exceptions.RequestParameterInvalidException( 'Unkown order_by',
controller='history', order_by=order_by_string )
return [ manager.parse_order_by( o ) for o in order_by_string.split( ORDER_BY_SEP_CHAR ) ]
return manager.parse_order_by( order_by_string )

0 comments on commit 1b64bea

Please sign in to comment.