mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
When deleting histories, go to default history (unnamed, no datasets) if available and create new history only if necessary.
This commit is contained in:
@@ -666,10 +666,11 @@ class History( object, UsesAnnotations ):
|
||||
|
||||
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
|
||||
|
||||
@@ -832,6 +832,39 @@ class GalaxyWebTransaction( base.DefaultWebTransaction ):
|
||||
|
||||
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
|
||||
|
||||
@@ -309,7 +309,7 @@ class HistoryController( BaseUIController, SharableMixin, UsesAnnotations, UsesI
|
||||
# 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 @@ class HistoryController( BaseUIController, SharableMixin, UsesAnnotations, UsesI
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user