commit/galaxy-central: jgoecks: (1) Create generic methods for copying visualizations and visualization configurations; (2) use generic visualization copying to support importing and cloning visualizations.
1 new changeset in galaxy-central: http://bitbucket.org/galaxy/galaxy-central/changeset/8a3730093edc/ changeset: 8a3730093edc user: jgoecks date: 2011-06-17 20:27:47 summary: (1) Create generic methods for copying visualizations and visualization configurations; (2) use generic visualization copying to support importing and cloning visualizations. affected #: 3 files (3.4 KB) --- a/lib/galaxy/model/__init__.py Fri Jun 17 13:16:53 2011 -0400 +++ b/lib/galaxy/model/__init__.py Fri Jun 17 14:27:47 2011 -0400 @@ -2244,20 +2244,59 @@ self.user = None class Visualization( object ): - def __init__( self ): + def __init__( self, user=None, type=None, title=None, dbkey=None, latest_revision=None ): self.id = None - self.user = None - self.type = None - self.title = None - self.latest_revision = None + self.user = user + self.type = type + self.title = title + self.dbkey = dbkey + self.latest_revision = latest_revision self.revisions = [] + if self.latest_revision: + self.revisions.append( latest_revision ) + + def copy( self, user=None, title=None ): + """ + Provide copy of visualization with only its latest revision. + """ + # NOTE: a shallow copy is done: the config is copied as is but datasets + # are not copied nor are the dataset ids changed. This means that the + # user does not have a copy of the data in his/her history and the + # user who owns the datasets may delete them, making them inaccessible + # for the current user. + # TODO: a deep copy option is needed. + + if not user: + user = self.user + if not title: + title = self.title + + copy_viz = Visualization( user=user, type=self.type, title=title, dbkey=self.dbkey ) + copy_revision = self.latest_revision.copy( visualization=copy_viz ) + copy_viz.latest_revision = copy_revision + return copy_viz class VisualizationRevision( object ): - def __init__( self ): + def __init__( self, visualization=None, title=None, dbkey=None, config=None ): self.id = None - self.visualization = None - self.title = None - self.config = None + self.visualization = visualization + self.title = title + self.dbkey = dbkey + self.config = config + + def copy( self, visualization=None ): + """ + Returns a copy of this object. + """ + if not visualization: + visualization = self.visualization + + return VisualizationRevision( + visualization=visualization, + title=self.title, + dbkey=self.dbkey, + config=self.config + ) class VisualizationUserShareAssociation( object ): def __init__( self ): --- a/lib/galaxy/web/controllers/visualization.py Fri Jun 17 13:16:53 2011 -0400 +++ b/lib/galaxy/web/controllers/visualization.py Fri Jun 17 14:27:47 2011 -0400 @@ -92,29 +92,21 @@ @web.expose @web.require_login() def clone(self, trans, id, *args, **kwargs): - viz = self.get_visualization( trans, id, check_ownership=False ) + visualization = self.get_visualization( trans, id, check_ownership=False ) user = trans.get_user() - if viz.user == user: - owner = True - else: - if trans.sa_session.query( model.VisualizationUserShareAssociation ) \ - .filter_by( user=user, visualization=viz ).count() == 0: - error( "Visualization is not owned by or shared with current user" ) - owner = False - new_viz = model.Visualization() - new_viz.title = "Clone of '%s'" % viz.title - new_viz.dbkey = viz.dbkey - new_viz.type = viz.type - new_viz.latest_revision = viz.latest_revision - if not owner: - new_viz.title += " shared by '%s'" % viz.user.email - new_viz.user = user + if trans.sa_session.query( model.VisualizationUserShareAssociation ) \ + .filter_by( user=user, visualization=visualization ).count() == 0: + error( "Visualization is not owned by or shared with current user" ) + + cloned_visualization = visualization.copy( user=trans.user, title="Copy of '%s'" % visualization.title ) + # Persist session = trans.sa_session - session.add( new_viz ) + session.add( cloned_visualization ) session.flush() + # Display the management page - trans.set_message( 'Clone created with name "%s"' % new_viz.title ) + trans.set_message( 'Copy created with name "%s"' % cloned_visualization.title ) return self.list( trans ) @web.expose @@ -205,36 +197,14 @@ elif visualization.deleted: return trans.show_error_message( "You can't import this visualization because it has been deleted.<br>You can %s" % referer_message, use_panels=True ) else: - # # Create imported visualization via copy. - # NOTE: a shallow copy is done: the config is copied as is but datasets - # are not copied nor are the dataset ids changed. This means that the - # user does not have a copy of the data in his/her history and the - # user who owns the datasets may delete them, making them inaccessible - # for the current user. - # TODO: - # -a deep copy is needed; - # -need to handle custom db keys. - # + # TODO: need to handle custom db keys. - imported_visualization = model.Visualization() - imported_visualization.title = visualization.title - imported_visualization.dbkey = visualization.dbkey - imported_visualization.type = visualization.type - imported_visualization.user = trans.user + imported_visualization = visualization.copy( user=trans.user, title="imported: " + visualization.title ) - # And the first visualization revision - imported_visualization_revision = model.VisualizationRevision() - imported_visualization_revision.title = visualization.title - imported_visualization_revision.config = visualization.latest_revision.config - imported_visualization_revision.dbkey = visualization.dbkey - imported_visualization_revision.visualization = imported_visualization - imported_visualization.latest_revision = imported_visualization_revision - # Persist session = trans.sa_session session.add( imported_visualization ) - session.add( imported_visualization_revision ) session.flush() # Redirect to load galaxy frames. --- a/templates/visualization/list.mako Fri Jun 17 13:16:53 2011 -0400 +++ b/templates/visualization/list.mako Fri Jun 17 14:27:47 2011 -0400 @@ -13,6 +13,19 @@ <div style="overflow: auto; height: 100%;"><div class="page-container" style="padding: 10px;"> + %if message: + <% + try: + status + except: + status = "done" + %> + <p /> + <div class="${status}message"> + ${h.to_unicode( message )} + </div> + %endif + ${h.to_unicode( grid )} <br><br> @@ -35,6 +48,7 @@ <td><div popupmenu="shared-${i}-popup"><a class="action-button" href="${h.url_for( action='display_by_username_and_slug', username=visualization.user.username, slug=visualization.slug)}" target="_top">View</a> + <a class="action-button" href="${h.url_for( action='clone', id=trans.security.encode_id(visualization.id) )}">Copy</a></div></td></tr> 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.
participants (1)
-
Bitbucket