[hg] galaxy 2524: Tweaks to grids to make it easier to override ...
details: http://www.bx.psu.edu/hg/galaxy/rev/5438f8d0a211 changeset: 2524:5438f8d0a211 user: James Taylor <james@jamestaylor.org> date: Mon Aug 03 17:14:12 2009 -0400 description: Tweaks to grids to make it easier to override query generation (backward compatible). 3 file(s) affected in this change: lib/galaxy/web/controllers/history.py lib/galaxy/web/framework/helpers/grids.py templates/history/grid.mako diffs (135 lines): diff -r 0431855a9ff4 -r 5438f8d0a211 lib/galaxy/web/controllers/history.py --- a/lib/galaxy/web/controllers/history.py Mon Aug 03 16:58:22 2009 -0400 +++ b/lib/galaxy/web/controllers/history.py Mon Aug 03 17:14:12 2009 -0400 @@ -13,7 +13,31 @@ # States for passing messages SUCCESS, INFO, WARNING, ERROR = "done", "info", "warning", "error" + class HistoryListGrid( grids.Grid ): + # Custom column types + class DatasetsByStateColumn( grids.GridColumn ): + def get_value( self, trans, grid, history ): + rval = [] + for state in ( 'ok', 'running', 'queued', 'error' ): + total = sum( 1 for d in history.active_datasets if d.state == state ) + if total: + rval.append( '<div class="count-box state-color-%s">%s</div>' % ( state, total ) ) + else: + rval.append( '' ) + return rval + class StatusColumn( grids.GridColumn ): + def get_value( self, trans, grid, history ): + if history.deleted: + return "deleted" + elif history.users_shared_with: + return "shared" + return "" + def get_link( self, trans, grid, item ): + if item.users_shared_with: + return dict( operation="sharing", id=item.id ) + return None + # Grid definition title = "Stored histories" model_class = model.History default_sort_key = "-create_time" @@ -21,12 +45,8 @@ grids.GridColumn( "Name", key="name", link=( lambda item: iff( item.deleted, None, dict( operation="switch", id=item.id ) ) ), attach_popup=True ), - grids.GridColumn( "Datasets (by state)", method='_build_datasets_by_state', ncells=4 ), - grids.GridColumn( "Status", method='_build_status', - link=( lambda item: iff( item.users_shared_with, - dict( operation="sharing", id=item.id ), - None ) ), - attach_popup=False ), + DatasetsByStateColumn( "Datasets (by state)", ncells=4 ), + StatusColumn( "Status", attach_popup=False ), grids.GridColumn( "Age", key="create_time", format=time_ago ), grids.GridColumn( "Last update", key="update_time", format=time_ago ), # Valid for filtering but invisible @@ -49,21 +69,6 @@ return trans.get_history() def apply_default_filter( self, trans, query ): return query.filter_by( user=trans.user, purged=False ) - def _build_datasets_by_state( self, trans, history ): - rval = [] - for state in ( 'ok', 'running', 'queued', 'error' ): - total = sum( 1 for d in history.active_datasets if d.state == state ) - if total: - rval.append( '<div class="count-box state-color-%s">%s</div>' % ( state, total ) ) - else: - rval.append( '' ) - return rval - def _build_status( self, trans, history ): - if history.deleted: - return "deleted" - elif history.users_shared_with: - return "shared" - return "" class HistoryController( BaseController ): diff -r 0431855a9ff4 -r 5438f8d0a211 lib/galaxy/web/framework/helpers/grids.py --- a/lib/galaxy/web/framework/helpers/grids.py Mon Aug 03 16:58:22 2009 -0400 +++ b/lib/galaxy/web/framework/helpers/grids.py Mon Aug 03 17:14:12 2009 -0400 @@ -40,16 +40,9 @@ if column.key: if "f-" + column.key in kwargs: column_filter = kwargs.get( "f-" + column.key ) - if column_filter == "True": - filter_args[column.key] = True - elif column_filter == "False": - filter_args[column.key] = False - elif column_filter == "All": - del filter_args[column.key] + query = column.filter( query, column_filter, filter_args ) # Carry filter along to newly generated urls extra_url_args[ "f-" + column.key ] = column_filter - if filter_args: - query = query.filter_by( **filter_args ) # Process sort arguments sort_key = sort_order = None if 'sort' in kwargs: @@ -143,6 +136,26 @@ if self.format: value = self.format( value ) return value + def get_link( self, trans, grid, item ): + if self.link and self.link( item ): + return self.link( item ) + return None + def filter( self, query, column_filter, filter_args ): + """ + Must modify filter_args for carrying forward, and return query + (possibly filtered). + """ + if column_filter == "True": + filter_args[self.key] = True + query = query.filter_by( **{ self.key: True } ) + elif column_filter == "False": + filter_args[self.key] = False + query = query.filter_by( **{ self.key: False } ) + elif column_filter == "All": + del filter_args[self.key] + return query + + class GridOperation( object ): def __init__( self, label, key=None, condition=None, allow_multiple=True ): diff -r 0431855a9ff4 -r 5438f8d0a211 templates/history/grid.mako --- a/templates/history/grid.mako Mon Aug 03 16:58:22 2009 -0400 +++ b/templates/history/grid.mako Mon Aug 03 17:14:12 2009 -0400 @@ -137,8 +137,9 @@ %if column.visible: <% # Link - if column.link and column.link( item ): - href = url( **column.link( item ) ) + link = column.get_link( trans, grid, item ) + if link: + href = url( **link ) else: href = None # Value (coerced to list so we can loop)
participants (1)
-
Greg Von Kuster