details: http://www.bx.psu.edu/hg/galaxy/rev/960820cccaaa changeset: 1549:960820cccaaa user: Dan Blankenberg <dan@bx.psu.edu> date: Tue Oct 07 11:58:32 2008 -0400 description: Users can copy datasets between their histories. 3 file(s) affected in this change: lib/galaxy/web/controllers/dataset.py templates/dataset/copy_view.mako templates/dataset/edit_attributes.mako diffs (164 lines): diff -r ae341e281c89 -r 960820cccaaa lib/galaxy/web/controllers/dataset.py --- a/lib/galaxy/web/controllers/dataset.py Mon Oct 06 13:34:51 2008 -0400 +++ b/lib/galaxy/web/controllers/dataset.py Tue Oct 07 11:58:32 2008 -0400 @@ -155,3 +155,67 @@ if self._undelete( trans, id ): return "OK" raise "Error undeleting" + + + @web.expose + def copy_datasets( self, trans, source_dataset_ids = "", target_history_ids = "", new_history_name="", do_copy = False ): + user = trans.get_user() + history = trans.get_history() + create_new_history = False + if source_dataset_ids: + if not isinstance( source_dataset_ids, list ): + source_dataset_ids = source_dataset_ids.split( "," ) + source_dataset_ids = map( int, source_dataset_ids ) + else: + source_dataset_ids = [] + if target_history_ids: + if not isinstance( target_history_ids, list ): + target_history_ids = target_history_ids.split( "," ) + if "create_new_history" in target_history_ids: + create_new_history = True + target_history_ids.remove( "create_new_history" ) + target_history_ids = map( int, target_history_ids ) + else: + target_history_ids = [] + done_msg = error_msg = "" + if do_copy: + invalid_datasets = 0 + if not source_dataset_ids or not ( target_history_ids or create_new_history ): + error_msg = "You must provide both source datasets and target histories." + if create_new_history: + target_history_ids.append( "create_new_history" ) + else: + if create_new_history: + new_history = trans.app.model.History() + if new_history_name: + new_history.name = new_history_name + new_history.user = user + new_history.flush() + target_history_ids.append( new_history.id ) + if user: + target_histories = [ hist for hist in map( trans.app.model.History.get, target_history_ids ) if ( hist is not None and hist.user == user )] + else: + target_histories = [ history ] + if len( target_histories ) != len( target_history_ids ): + error_msg = error_msg + "You do not have permission to add datasets to %i requested histories. " % ( len( target_history_ids ) - len( target_histories ) ) + for data in map( trans.app.model.HistoryDatasetAssociation.get, source_dataset_ids ): + if data is None: + error_msg = error_msg + "You tried to copy a non-existant dataset. " + invalid_datasets += 1 + elif data.history != history: + error_msg = error_msg + "You tried to copy a dataset which is not in your current history. " + invalid_datasets += 1 + else: + for hist in target_histories: + hist.add_dataset( data.copy( copy_children = True ) ) + trans.app.model.flush() + done_msg = "%i datasets copied to %i histories." % ( len( source_dataset_ids ) - invalid_datasets, len( target_histories ) ) + history.refresh() + elif create_new_history: + target_history_ids.append( "create_new_history" ) + source_datasets = history.active_datasets + target_histories = [history] + if user: + target_histories = user.histories + + return trans.fill_template( "/dataset/copy_view.mako", source_dataset_ids = source_dataset_ids, target_history_ids = target_history_ids, source_datasets = source_datasets, target_histories = target_histories, new_history_name = new_history_name, done_msg = done_msg, error_msg = error_msg ) diff -r ae341e281c89 -r 960820cccaaa templates/dataset/copy_view.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/dataset/copy_view.mako Tue Oct 07 11:58:32 2008 -0400 @@ -0,0 +1,66 @@ +<%inherit file="/base.mako"/> +<%def name="title()">Copy History Items</%def> + +%if error_msg: +<p> +<div class="errormessage">${error_msg}</div> +<div style="clear: both"></div> +</p> +%endif +%if done_msg: +<p> +<div class="donemessage">${done_msg}</div> +<div style="clear: both"></div> +</p> +%endif +<p> +<div class="toolForm"> + <form> + <div style="float: left; width: 50%; padding: 0px 0px 0px 0px;"> + <div class="toolFormTitle">Source History Items</div> + <div class="toolFormBody"> + %for data in source_datasets: + <% + checked = "" + if data.id in source_dataset_ids: + checked = " checked" + %> + <div class="form-row"><input type="checkbox" name="source_dataset_ids" value="${data.id}"${checked}> ${data.hid}: ${data.name}</div> + %endfor + </div> + </div> + <div style="float: right; width: 50%; padding: 0px 0px 0px 0px;"> + <div class="toolFormTitle">Target Histories</div> + <div class="toolFormBody"> + %for i, hist in enumerate( target_histories ): + <% + checked = "" + if hist.id in target_history_ids: + checked = " checked" + cur_history_text = "" + if hist == trans.get_history(): + cur_history_text = " <strong>(current history)</strong>" + %> + <div class="form-row"><input type="checkbox" name="target_history_ids" value="${hist.id}"${checked}> ${i + 1}${cur_history_text}: ${hist.name}</div> + %endfor + %if trans.get_user(): + <% + checked = "" + if "create_new_history" in target_history_ids: + checked = " checked" + %> + <br> + <div class="form-row"><input type="checkbox" name="target_history_ids" value="create_new_history"${checked}>New history named: <input type="textbox" name="new_history_name" value="${new_history_name}"></div> + %endif + </div> + </div> + <div style="clear: both"></div> + <div class="form-row" align="center"><input type="submit" class="primary-button" name="do_copy" value="Copy History Items"></div> + </form> +</div> +</p> +<div style="clear: both"></div> +<p> +<div class="infomessage">Select any number of source history items and any number of target histories and click on "Copy History Items" to add a copy of each selected dataset to each selected history.</div> +<div style="clear: both"></div> +</p> diff -r ae341e281c89 -r 960820cccaaa templates/dataset/edit_attributes.mako --- a/templates/dataset/edit_attributes.mako Mon Oct 06 13:34:51 2008 -0400 +++ b/templates/dataset/edit_attributes.mako Tue Oct 07 11:58:32 2008 -0400 @@ -1,5 +1,5 @@ <%inherit file="/base.mako"/> -<%def name="title()">Your saved histories</%def> +<%def name="title()">History Item Attributes</%def> <%def name="datatype( dataset, datatypes )"> @@ -132,3 +132,12 @@ </form> </div> </div> + + <p> + <div class="toolForm"> + <div class="toolFormTitle">Copy History Item</div> + <div class="toolFormBody"> + Click <a href="${h.url_for( controller='dataset', action='copy_datasets', source_dataset_ids=data.id, target_history_ids=data.history_id )}" target="galaxy_main">here</a> to make a copy of this history item. + </div> + </div> + </p>