1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/4a514b0de915/ Changeset: 4a514b0de915 User: jgoecks Date: 2013-08-06 01:06:40 Summary: When deleting histories, go to default history (unnamed, no datasets) if available and create new history only if necessary. Affected #: 3 files diff -r 2a5554c53aead0373e26eacdffc75e5c713bd721 -r 4a514b0de915b8d8ea3b9ff333d04b0907a5fb66 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -666,10 +666,11 @@ api_collection_visible_keys = ( 'id', 'name', 'published', 'deleted' ) api_element_visible_keys = ( 'id', 'name', 'published', 'deleted', 'genome_build', 'purged' ) + default_name = 'Unnamed history' def __init__( self, id=None, name=None, user=None ): self.id = id - self.name = name or "Unnamed history" + self.name = name or History.default_name self.deleted = False self.purged = False self.importing = False diff -r 2a5554c53aead0373e26eacdffc75e5c713bd721 -r 4a514b0de915b8d8ea3b9ff333d04b0907a5fb66 lib/galaxy/web/framework/__init__.py --- a/lib/galaxy/web/framework/__init__.py +++ b/lib/galaxy/web/framework/__init__.py @@ -832,6 +832,39 @@ history = property( get_history, set_history ) + def get_or_create_default_history( self ): + """ + Gets or creates a default history and associates it with the current + session. + """ + + # There must be a user to fetch a default history. + if not self.galaxy_session.user: + return self.new_history() + + # Look for default history that (a) has default name + is not deleted and + # (b) has no datasets. If suitable history found, use it; otherwise, create + # new history. + unnamed_histories = self.sa_session.query( self.app.model.History ).filter_by( + user=self.galaxy_session.user, + name=self.app.model.History.default_name, + deleted=False ) + default_history = None + for history in unnamed_histories: + if len( history.datasets ) == 0: + # Found suitable default history. + default_history = history + break + + # Set or create hsitory. + if default_history: + history = default_history + self.set_history( history ) + else: + history = self.new_history() + + return history + def new_history( self, name=None ): """ Create a new history and associate it with the current session and diff -r 2a5554c53aead0373e26eacdffc75e5c713bd721 -r 4a514b0de915b8d8ea3b9ff333d04b0907a5fb66 lib/galaxy/webapps/galaxy/controllers/history.py --- a/lib/galaxy/webapps/galaxy/controllers/history.py +++ b/lib/galaxy/webapps/galaxy/controllers/history.py @@ -309,7 +309,7 @@ # If deleting the current history, make a new current. if history == trans.get_history(): deleted_current = True - trans.new_history() + trans.get_or_create_default_history() trans.log_event( "History (%s) marked as deleted" % history.name ) n_deleted += 1 if purge and trans.app.config.allow_user_dataset_purge: @@ -571,8 +571,8 @@ # No need to check other outputs since the job's parent history is this history job.mark_deleted( trans.app.config.track_jobs_in_database ) trans.app.job_manager.job_stop_queue.put( job.id ) - # Regardless of whether it was previously deleted, we make a new history active - trans.new_history() + # Regardless of whether it was previously deleted, get or create default history. + trans.get_or_create_default_history() return trans.show_ok_message( "History deleted, a new history is active", refresh_frames=['history'] ) @web.expose 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.