mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Make activatable_datasets a property of the History object, eliminating the problematic mapper.
This commit is contained in:
@@ -162,7 +162,6 @@ class History( object ):
|
||||
self.user = user
|
||||
self.datasets = []
|
||||
self.galaxy_sessions = []
|
||||
|
||||
def _next_hid( self ):
|
||||
# TODO: override this with something in the database that ensures
|
||||
# better integrity
|
||||
@@ -174,16 +173,14 @@ class History( object ):
|
||||
if dataset.hid > last_hid:
|
||||
last_hid = dataset.hid
|
||||
return last_hid + 1
|
||||
|
||||
def add_galaxy_session( self, galaxy_session, association=None ):
|
||||
if association is None:
|
||||
self.galaxy_sessions.append( GalaxySessionToHistoryAssociation( galaxy_session, self ) )
|
||||
else:
|
||||
self.galaxy_sessions.append( association )
|
||||
|
||||
def add_dataset( self, dataset, parent_id=None, genome_build=None, set_hid = True ):
|
||||
if isinstance( dataset, Dataset ):
|
||||
dataset = HistoryDatasetAssociation( dataset = dataset )
|
||||
dataset = HistoryDatasetAssociation( dataset = dataset, copied_from = dataset )
|
||||
dataset.flush()
|
||||
elif not isinstance( dataset, HistoryDatasetAssociation ):
|
||||
raise TypeError, "You can only add Dataset and HistoryDatasetAssociation instances to a history ( you tried to add %s )." % str( dataset )
|
||||
@@ -198,22 +195,28 @@ class History( object ):
|
||||
else:
|
||||
if set_hid:
|
||||
dataset.hid = self._next_hid()
|
||||
dataset.history = self
|
||||
if genome_build not in [None, '?']:
|
||||
self.genome_build = genome_build
|
||||
self.datasets.append( dataset )
|
||||
|
||||
def copy(self):
|
||||
des = History()
|
||||
def copy( self, target_user = None ):
|
||||
if not target_user:
|
||||
target_user = self.user
|
||||
des = History( user = target_user )
|
||||
des.flush()
|
||||
des.name = self.name
|
||||
des.user_id = self.user_id
|
||||
for data in self.datasets:
|
||||
new_data = data.copy( copy_children = True )
|
||||
des.add_dataset( new_data )
|
||||
new_data = data.copy( copy_children = True, target_history = des )
|
||||
des.add_dataset( new_data, set_hid = False )
|
||||
new_data.flush()
|
||||
des.hid_counter = self.hid_counter
|
||||
des.flush()
|
||||
return des
|
||||
@property
|
||||
def activatable_datasets( self ):
|
||||
for hda in self.datasets:
|
||||
if not hda.dataset.purged:
|
||||
yield hda
|
||||
|
||||
# class Query( object ):
|
||||
# def __init__( self, name=None, state=None, tool_parameters=None, history=None ):
|
||||
@@ -656,66 +659,6 @@ class HistoryDatasetAssociation( DatasetInstance ):
|
||||
if not metadata_safe or not assoc.metadata_safe:
|
||||
assoc.clear( purge = purge )
|
||||
|
||||
class History( object ):
|
||||
def __init__( self, id=None, name=None, user=None ):
|
||||
self.id = id
|
||||
self.name = name or "Unnamed history"
|
||||
self.deleted = False
|
||||
self.purged = False
|
||||
self.genome_build = None
|
||||
# Relationships
|
||||
self.user = user
|
||||
self.datasets = []
|
||||
self.galaxy_sessions = []
|
||||
def _next_hid( self ):
|
||||
# TODO: override this with something in the database that ensures
|
||||
# better integrity
|
||||
if len( self.datasets ) == 0:
|
||||
return 1
|
||||
else:
|
||||
last_hid = 0
|
||||
for dataset in self.datasets:
|
||||
if dataset.hid > last_hid:
|
||||
last_hid = dataset.hid
|
||||
return last_hid + 1
|
||||
def add_galaxy_session( self, galaxy_session, association=None ):
|
||||
if association is None:
|
||||
self.galaxy_sessions.append( GalaxySessionToHistoryAssociation( galaxy_session, self ) )
|
||||
else:
|
||||
self.galaxy_sessions.append( association )
|
||||
def add_dataset( self, dataset, parent_id=None, genome_build=None, set_hid = True ):
|
||||
if isinstance( dataset, Dataset ):
|
||||
dataset = HistoryDatasetAssociation( dataset = dataset, copied_from = dataset )
|
||||
dataset.flush()
|
||||
elif not isinstance( dataset, HistoryDatasetAssociation ):
|
||||
raise TypeError, "You can only add Dataset and HistoryDatasetAssociation instances to a history."
|
||||
if parent_id:
|
||||
for data in self.datasets:
|
||||
if data.id == parent_id:
|
||||
dataset.hid = data.hid
|
||||
break
|
||||
else:
|
||||
if set_hid: dataset.hid = self._next_hid()
|
||||
else:
|
||||
if set_hid: dataset.hid = self._next_hid()
|
||||
dataset.history = self
|
||||
if genome_build not in [None, '?']:
|
||||
self.genome_build = genome_build
|
||||
self.datasets.append( dataset )
|
||||
def copy( self, target_user = None ):
|
||||
if not target_user:
|
||||
target_user = self.user
|
||||
des = History( user = target_user )
|
||||
des.flush()
|
||||
des.name = self.name
|
||||
for data in self.datasets:
|
||||
new_data = data.copy( copy_children = True, target_history = des )
|
||||
des.add_dataset( new_data, set_hid = False )
|
||||
new_data.flush()
|
||||
des.hid_counter = self.hid_counter
|
||||
des.flush()
|
||||
return des
|
||||
|
||||
class Library( object ):
|
||||
permitted_actions = get_permitted_actions( filter='LIBRARY' )
|
||||
def __init__( self, name = None, description = None, root_folder = None ):
|
||||
|
||||
@@ -567,8 +567,7 @@ assign_mapper( context, ImplicitlyConvertedDatasetAssociation, ImplicitlyConvert
|
||||
assign_mapper( context, History, History.table,
|
||||
properties=dict( galaxy_sessions=relation( GalaxySessionToHistoryAssociation ),
|
||||
datasets=relation( HistoryDatasetAssociation, backref="history", order_by=asc(HistoryDatasetAssociation.table.c.hid) ),
|
||||
active_datasets=relation( HistoryDatasetAssociation, primaryjoin=( ( HistoryDatasetAssociation.table.c.history_id == History.table.c.id ) & ( not_( HistoryDatasetAssociation.table.c.deleted ) ) ), order_by=asc( HistoryDatasetAssociation.table.c.hid ), lazy=False, viewonly=True ),
|
||||
activatable_datasets=relation( HistoryDatasetAssociation, primaryjoin=( ( HistoryDatasetAssociation.table.c.history_id == History.table.c.id ) & ( not_( Dataset.table.c.purged ) ) ), order_by=asc( HistoryDatasetAssociation.table.c.hid ), lazy=True, viewonly=True )
|
||||
active_datasets=relation( HistoryDatasetAssociation, primaryjoin=( ( HistoryDatasetAssociation.table.c.history_id == History.table.c.id ) & ( not_( HistoryDatasetAssociation.table.c.deleted ) ) ), order_by=asc( HistoryDatasetAssociation.table.c.hid ), lazy=False, viewonly=True )
|
||||
) )
|
||||
|
||||
assign_mapper( context, User, User.table,
|
||||
|
||||
@@ -219,13 +219,6 @@ class GalaxyRBACAgent( RBACAgent ):
|
||||
dup.flush()
|
||||
if history:
|
||||
for history in user.active_histories:
|
||||
"""
|
||||
TODO: instead of user.active_histories, a faster approach would be the following, but we need the
|
||||
history.activatable_datasets mapper corrected so that eagerload can be used.
|
||||
histories = app.model.History.filter( and_( app.model.History.table.c.user_id==user.id,
|
||||
app.model.History.table.c.purged==False ) ) \
|
||||
.options( eagerload( 'activatable_datasets' ) ).all()
|
||||
"""
|
||||
self.history_set_default_permissions( history, permissions=permissions, dataset=dataset, bypass_manage_permission=bypass_manage_permission )
|
||||
def user_get_default_permissions( self, user ):
|
||||
permissions = {}
|
||||
|
||||
@@ -187,15 +187,8 @@ def main():
|
||||
# Add the new default permissions for the user
|
||||
dup = app.model.DefaultUserPermissions( user, default_user_action, private_role )
|
||||
dup.flush()
|
||||
# Set DefaultHistoryPermissions on all of the user's active histories and associated datasets
|
||||
# TODO: fix mapping for history.activatable_datasets so it doesn't throw an exception on the
|
||||
# following query when eagerloading activatable_datasets. Fix all of the queries below that
|
||||
# call history.active_datasets to be history.activatable_datasets when this works.
|
||||
histories = app.model.History.filter( and_( app.model.History.table.c.user_id==user.id,
|
||||
app.model.History.table.c.purged==False ) ) \
|
||||
.options( eagerload( 'active_datasets' ) ).all()
|
||||
print "Setting DefaultHistoryPermissions for %d un-purged histories associated with %s" % ( len( histories ), user.email )
|
||||
for history in histories:
|
||||
for history in user.active_histories:
|
||||
# Delete all of the current default permissions for the history
|
||||
for dhp in history.default_permissions:
|
||||
dhp.delete()
|
||||
@@ -203,9 +196,9 @@ def main():
|
||||
# Add the new default permissions for the history
|
||||
dhp = app.model.DefaultHistoryPermissions( history, default_user_action, private_role )
|
||||
dhp.flush()
|
||||
print "Setting DatasetPermissionss for %d un-purged datasets in history %d" % ( len( history.active_datasets ), history.id )
|
||||
print "Setting DatasetPermissionss for %d un-purged datasets in history %d" % ( len( history.activatable_datasets ), history.id )
|
||||
# Set the permissions on the current history's datasets that are not purged
|
||||
for hda in history.active_datasets:
|
||||
for hda in history.activatable_datasets:
|
||||
dataset = hda.dataset
|
||||
if dataset.library_associations:
|
||||
# Don't change permissions on a dataset associated with a library
|
||||
|
||||
@@ -248,12 +248,7 @@ div#footer {
|
||||
|
||||
<%namespace file="history_common.mako" import="render_dataset" />
|
||||
|
||||
<%
|
||||
activatable_datasets = []
|
||||
for hda in history.datasets:
|
||||
if not hda.dataset.purged:
|
||||
activatable_datasets.append( hda )
|
||||
%>
|
||||
<% activatable_datasets = history.activatable_datasets %>
|
||||
|
||||
%if ( show_deleted and not activatable_datasets ) or ( not show_deleted and not history.active_datasets ):
|
||||
<div class="infomessagesmall" id="emptyHistoryMessage">
|
||||
|
||||
Reference in New Issue
Block a user