Merge pull request #2870 from dannon/histories.most_recent_v_default

Create a new trans method for getting the most recently touched history.
This commit is contained in:
John Chilton
2016-08-30 08:39:38 -04:00
committed by GitHub
4 changed files with 28 additions and 8 deletions
+24 -4
View File
@@ -660,7 +660,7 @@ class GalaxyWebTransaction( base.DefaultWebTransaction,
users_last_session.current_history.deleted):
history = users_last_session.current_history
elif not history:
history = self.get_history( create=True )
history = self.get_history( create=True, most_recent=True )
if history not in self.galaxy_session.histories:
self.galaxy_session.add_history( history )
if history.user is None:
@@ -708,10 +708,11 @@ class GalaxyWebTransaction( base.DefaultWebTransaction,
"""
return self.galaxy_session
def get_history( self, create=False ):
def get_history( self, create=False, most_recent=False ):
"""
Load the current history, creating a new one only if there is not
current history and we're told to create.
Load the current history.
- If that isn't available, we find the most recently updated history.
- If *that* isn't available, we get or create the default history.
Transactions will not always have an active history (API requests), so
None is a valid response.
"""
@@ -719,6 +720,8 @@ class GalaxyWebTransaction( base.DefaultWebTransaction,
if self.galaxy_session:
if hasattr( self.galaxy_session, 'current_history' ):
history = self.galaxy_session.current_history
if not history and most_recent:
history = self.get_most_recent_history()
if not history and util.string_as_bool( create ):
history = self.get_or_create_default_history()
return history
@@ -764,6 +767,23 @@ class GalaxyWebTransaction( base.DefaultWebTransaction,
return history
def get_most_recent_history( self ):
"""
Gets the most recently updated history.
"""
# There must be a user to fetch histories, and without a user we have
# no recent history.
if not self.galaxy_session.user:
return None
try:
recent_history = self.sa_session.query( self.app.model.History ).filter_by(
user=self.galaxy_session.user,
deleted=False ).order_by(self.app.model.History.update_time.desc()).first()
except NoResultFound:
return None
self.set_history(recent_history)
return recent_history
def new_history( self, name=None ):
"""
Create a new history and associate it with the current session and
@@ -487,7 +487,7 @@ class HistoryController( BaseUIController, SharableMixin, UsesAnnotations, UsesI
history = self.history_manager.get_accessible( self.decode_id( id ), trans.user,
current_history=trans.history )
else:
history = trans.get_history( create=True )
history = trans.get_history( most_recent=True, create=True )
trans.response.set_content_type( 'text/xml' )
return trans.fill_template_mako(
@@ -1351,7 +1351,7 @@ class HistoryController( BaseUIController, SharableMixin, UsesAnnotations, UsesI
"""Return the current user's current history in a serialized, dictionary form."""
# Prevent IE11 from caching this
trans.response.headers[ 'Cache-Control' ] = ["max-age=0", "no-cache", "no-store"]
history = trans.get_history( create=True )
history = trans.get_history( most_recent=True, create=True )
return self.history_data( trans, history )
@web.json
@@ -955,7 +955,7 @@ class VisualizationController( BaseUIController, SharableMixin, UsesVisualizatio
"""
regions = regions or '{}'
# Need to create history if necessary in order to create tool form.
trans.get_history( create=True )
trans.get_history( most_recent=True, create=True )
if id:
# Loading a shared visualization.
@@ -90,7 +90,7 @@
<%
# HACK: Rendering workflow steps requires that trans have a history; however, if its user's first visit to Galaxy is here, he won't have a history
# and an error will occur. To prevent this error, make sure user has a history.
trans.get_history( create=True )
trans.get_history( most_recent=True, create=True )
%>
<table class="annotated-item">
<tr><th>Step</th><th class="annotation">Annotation</th></tr>