2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/350d6d927398/ changeset: 350d6d927398 user: jgoecks date: 2013-02-01 23:56:55 summary: Move hda state counting out of grid and into a function in UsesHistory mixin. affected #: 2 files diff -r d166635a6f1528fdc233641e223dab2b78ba755d -r 350d6d92739872c661049e0418600d8c1f0d23fa lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -691,6 +691,8 @@ """Get a History from the database by id, verifying ownership.""" history = self.get_object( trans, id, 'History', check_ownership=check_ownership, check_accessible=check_accessible, deleted=deleted ) return self.security_check( trans, history, check_ownership, check_accessible ) + + def get_history_datasets( self, trans, history, show_deleted=False, show_hidden=False, show_purged=False ): """ Returns history's datasets. """ query = trans.sa_session.query( trans.model.HistoryDatasetAssociation ) \ @@ -705,6 +707,42 @@ query = query.filter( trans.model.Dataset.purged == False ) return query.all() + def get_hda_state_counts( self, trans, history, include_deleted=False, include_hidden=False ): + """ + Returns a dictionary with state counts for history's HDAs. Key is a + dataset state, value is the number of states in that count. + """ + + # Build query to get (state, count) pairs. + cols_to_select = [ trans.app.model.Dataset.table.c.state, func.count( '*' ) ] + from_obj = trans.app.model.HistoryDatasetAssociation.table.join( trans.app.model.Dataset.table ) + + conditions = [ trans.app.model.HistoryDatasetAssociation.table.c.history_id == history.id ] + if not include_deleted: + # Only count datasets that have not been deleted. + conditions.append( trans.app.model.HistoryDatasetAssociation.table.c.deleted == False ) + if not include_hidden: + # Only count datasets that are visible. + conditions.append( trans.app.model.HistoryDatasetAssociation.table.c.visible == True ) + + group_by = trans.app.model.Dataset.table.c.state + query = select( columns=cols_to_select, + from_obj=from_obj, + whereclause=and_( *conditions ), + group_by=group_by ) + + # Initialize count dict with all states. + state_count_dict = {} + for k, state in trans.app.model.Dataset.states.items(): + state_count_dict[ state ] = 0 + + # Process query results, adding to count dict. + for row in trans.sa_session.execute( query ): + state, count = row + state_count_dict[ state ] = count + + return state_count_dict + class UsesFormDefinitionsMixin: """Mixin for controllers that use Galaxy form objects.""" def get_all_forms( self, trans, all_versions=False, filter=None, form_type='All' ): diff -r d166635a6f1528fdc233641e223dab2b78ba755d -r 350d6d92739872c661049e0418600d8c1f0d23fa lib/galaxy/webapps/galaxy/controllers/history.py --- a/lib/galaxy/webapps/galaxy/controllers/history.py +++ b/lib/galaxy/webapps/galaxy/controllers/history.py @@ -25,26 +25,10 @@ class HistoryListGrid( grids.Grid ): # Custom column types - class DatasetsByStateColumn( grids.GridColumn ): + class DatasetsByStateColumn( grids.GridColumn, UsesHistoryMixin ): def get_value( self, trans, grid, history ): - # Build query to get (state, count) pairs. - cols_to_select = [ trans.app.model.Dataset.table.c.state, func.count( '*' ) ] - from_obj = trans.app.model.HistoryDatasetAssociation.table.join( trans.app.model.Dataset.table ) - where_clause = and_( trans.app.model.HistoryDatasetAssociation.table.c.history_id == history.id, - trans.app.model.HistoryDatasetAssociation.table.c.deleted == False, - trans.app.model.HistoryDatasetAssociation.table.c.visible == True, - ) - group_by = trans.app.model.Dataset.table.c.state - query = select( columns=cols_to_select, - from_obj=from_obj, - whereclause=where_clause, - group_by=group_by ) - - # Process results. - state_count_dict = {} - for row in trans.sa_session.execute( query ): - state, count = row - state_count_dict[ state ] = count + state_count_dict = self.get_hda_state_counts( trans, history ) + rval = [] for state in ( 'ok', 'running', 'queued', 'error' ): count = state_count_dict.get( state, 0 ) @@ -53,12 +37,16 @@ else: rval.append( '' ) return rval + + class HistoryListNameColumn( NameColumn ): def get_link( self, trans, grid, history ): link = None if not history.deleted: link = dict( operation="Switch", id=history.id, use_panels=grid.use_panels ) return link + + class DeletedColumn( grids.DeletedColumn ): def get_value( self, trans, grid, history ): if history == trans.history: @@ -75,6 +63,7 @@ query = query.order_by( self.model_class.table.c.purged.desc(), self.model_class.table.c.update_time.desc() ) return query + # Grid definition title = "Saved Histories" model_class = model.History https://bitbucket.org/galaxy/galaxy-central/commits/132aeb4a4b96/ changeset: 132aeb4a4b96 user: jgoecks date: 2013-02-02 00:06:09 summary: Resolve imports. affected #: 1 file diff -r 350d6d92739872c661049e0418600d8c1f0d23fa -r 132aeb4a4b96de744d20de6f368d197d59e7b9e3 lib/galaxy/webapps/galaxy/api/histories.py --- a/lib/galaxy/webapps/galaxy/api/histories.py +++ b/lib/galaxy/webapps/galaxy/api/histories.py @@ -4,7 +4,8 @@ import logging, os, string, shutil, urllib, re, socket from cgi import escape, FieldStorage from galaxy import util, datatypes, jobs, web, util -from galaxy.web.base.controller import * +from galaxy.web.base.controller import BaseAPIController, UsesHistoryMixin +from galaxy.web import url_for from galaxy.util.sanitize_html import sanitize_html from galaxy.model.orm import * import galaxy.datatypes 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.