galaxy-dist commit fb2a31820ccf: A bit of code cleanup / optimization in sample tracking.
# HG changeset patch -- Bitbucket.org # Project galaxy-dist # URL http://bitbucket.org/galaxy/galaxy-dist/overview # User Greg Von Kuster <greg@bx.psu.edu> # Date 1287069813 14400 # Node ID fb2a31820ccff6f02bb24a0632f214bfef0a8b0a # Parent c8173a50bc9bdb0c8e07807c1b73be746557647f A bit of code cleanup / optimization in sample tracking. --- a/templates/requests/common/manage_request.mako +++ b/templates/requests/common/manage_request.mako @@ -163,7 +163,7 @@ </div></div> -%if request.has_samples_without_library_destinations: +%if request.samples_without_library_destinations: ${render_msg( "Select a target data library and folder for all the samples before starting the sequence run", "warning" )} %endif --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -1647,12 +1647,12 @@ class Request( object ): def is_complete( self ): return self.state == self.states.COMPLETE @property - def has_samples_without_library_destinations( self ): + def samples_without_library_destinations( self ): # Return all samples that are not associated with a library samples = [] - for s in self.samples: - if not s.library: - samples.append( s.name ) + for sample in self.samples: + if not sample.library: + samples.append( sample ) return samples def send_email_notification( self, trans, common_state, final_state=False ): # Check if an email notification is configured to be sent when the samples @@ -1774,25 +1774,25 @@ class Sample( object ): return None @property def untransferred_dataset_files( self ): - count = 0 - for df in self.datasets: - if df.status == self.transfer_status.NOT_STARTED: - count = count + 1 - return count + untransferred_datasets = [] + for dataset in self.datasets: + if dataset.status == self.transfer_status.NOT_STARTED: + untransferred_datasets.append( dataset ) + return untransferred_datasets @property def inprogress_dataset_files( self ): - count = 0 - for df in self.datasets: - if df.status not in [self.transfer_status.NOT_STARTED, self.transfer_status.COMPLETE]: - count = count + 1 - return count + inprogress_datasets = [] + for dataset in self.datasets: + if dataset.status not in [ self.transfer_status.NOT_STARTED, self.transfer_status.COMPLETE ]: + inprogress_datasets.append( dataset ) + return inprogress_datasets @property def transferred_dataset_files( self ): - count = 0 - for df in self.datasets: - if df.status == self.transfer_status.COMPLETE: - count = count + 1 - return count + transferred_datasets = [] + for dataset in self.datasets: + if dataset.status == self.transfer_status.COMPLETE: + transferred_datasets.append( dataset ) + return transferred_datasets def dataset_size( self, filepath ): def print_ticks(d): pass --- a/templates/requests/common/sample_datasets.mako +++ b/templates/requests/common/sample_datasets.mako @@ -1,5 +1,5 @@ <%def name="render_sample_datasets( sample )"> - ${sample.transferred_dataset_files} / ${len( sample.datasets )} + ${len( sample.transferred_dataset_files )}/${len( sample.datasets )} </%def> ${render_sample_datasets( sample )} --- a/lib/galaxy/web/controllers/requests_admin.py +++ b/lib/galaxy/web/controllers/requests_admin.py @@ -244,6 +244,11 @@ class RequestsAdmin( BaseController, Use params = util.Params( kwd ) message = util.restore_text( params.get( 'message', '' ) ) status = params.get( 'status', 'done' ) + sample_id = params.get( 'sample_id', None ) + try: + sample = trans.sa_session.query( trans.model.Sample ).get( trans.security.decode_id ( sample_id ) ) + except: + return invalid_id_redirect( trans, 'requests_admin', sample_id ) if 'operation' in kwd: operation = kwd[ 'operation' ].lower() sample_dataset_id = params.get( 'id', None ) @@ -262,48 +267,44 @@ class RequestsAdmin( BaseController, Use elif operation == "delete": not_deleted = [] for sample_dataset in selected_sample_datasets: - sample_id = sample_dataset.sample.id - if sample_dataset.status == trans.app.model.Sample.transfer_status.NOT_STARTED: + # Make sure the dataset has been transferred before deleting it. + if sample_dataset in sample.untransferred_dataset_files: trans.sa_session.delete( sample_dataset ) trans.sa_session.flush() else: not_deleted.append( sample_dataset.name ) - message = '%i datasets have been deleted. ' % ( len( id_list ) - len( not_deleted ) ) + message = '%i datasets have been deleted.' % ( len( id_list ) - len( not_deleted ) ) if not_deleted: status = 'warning' - message = message + '%s could not be deleted because their transfer status is not "Not Started". ' % str( not_deleted ) + message = message + ' %s could not be deleted because their transfer status is not "Not Started". ' % str( not_deleted ) return trans.response.send_redirect( web.url_for( controller='requests_admin', action='manage_datasets', - sample_id=trans.security.encode_id( sample_id ), + sample_id=sample_id, status=status, message=message ) ) elif operation == "rename": - # if none of the selected sample datasets are in the NOT_STARTED state, - # then display error message - flag = True - for sd in selected_sample_datasets: - if sd.status == trans.app.model.Sample.transfer_status.NOT_STARTED: - flag = False + # If one of the selected sample datasets is in the NOT_STARTED state, + # then display an error message. A NOT_STARTED state implies the dataset + # has not yet been transferred. + no_datasets_transferred = True + for selected_sample_dataset in selected_sample_datasets: + if selected_sample_dataset in sample.untransferred_dataset_files: + no_datasets_transferred = False break - if flag: + if no_datasets_transferred: status = 'error' - message = 'A dataset can be renamed only if it is in the <b>Not Started</b> state.' + message = 'A dataset can be renamed only if it is in the "Not Started" state.' return trans.response.send_redirect( web.url_for( controller='requests_admin', action='manage_datasets', - sample_id=trans.security.encode_id( selected_sample_datasets[0].sample.id ), + sample_id=sample_id, status=status, message=message ) ) return trans.fill_template( '/admin/requests/rename_datasets.mako', - sample=selected_sample_datasets[0].sample, + sample=sample, id_list=id_list ) elif operation == "start transfer": - self.__start_datatx( trans, selected_sample_datasets[0].sample, selected_sample_datasets ) + self.__start_datatx( trans, sample, selected_sample_datasets ) # Render the grid view - sample_id = params.get( 'sample_id', None ) - try: - sample = trans.sa_session.query( trans.model.Sample ).get( trans.security.decode_id ( sample_id ) ) - except: - return invalid_id_redirect( trans, 'requests_admin', sample_id ) request_id = trans.security.encode_id( sample.request.id ) library_id = trans.security.encode_id( sample.library.id ) self.datatx_grid.title = 'Datasets of sample "%s"' % sample.name @@ -392,25 +393,26 @@ class RequestsAdmin( BaseController, Use folder_path = self.__check_path( folder_path ) if params.get( 'folder_up', False ): if folder_path[-1] == os.sep: - folder_path = os.path.dirname(folder_path[:-1]) + folder_path = os.path.dirname( folder_path[:-1] ) folder_path = self.__check_path( folder_path ) elif params.get( 'select_show_datasets_button', False ) or params.get( 'select_more_button', False ): # get the sample these datasets are associated with try: sample = trans.sa_session.query( trans.model.Sample ).get( trans.security.decode_id( selected_sample_id ) ) - if sample.name in sample.request.has_samples_without_library_destinations: - raise Exception() except: - # if no sample (with associated library & folder) has been selected + return invalid_id_redirect( trans, 'requests_admin', selected_sample_id ) + if sample in sample.request.samples_without_library_destinations: + # Display an error if a sample has been selected that + # has not yet been associated with a destination library. status = 'error' - message = 'Select a sample with associated data library and folder before selecting the dataset(s).' + message = 'Select a sample with associated data library and folder before selecting the datasets.' return trans.response.send_redirect( web.url_for( controller='requests_admin', action='get_data', - request_id=trans.security.encode_id( request.id ), + request_id=request_id, folder_path=folder_path, status=status, message=message ) ) - # save the sample datasets + # Save the sample datasets sample_dataset_file_names = self.__save_sample_datasets( trans, sample, selected_files, folder_path ) if sample_dataset_file_names: message = 'Datasets (%s) have been selected for sample (%s)' % \ @@ -419,7 +421,7 @@ class RequestsAdmin( BaseController, Use return trans.response.send_redirect( web.url_for( controller='requests_admin', action='manage_datasets', request_id=request_id, - sample_id=trans.security.encode_id( sample.id ), + sample_id=selected_sample_id, message=message, status=status ) ) else: # 'select_more_button' was clicked --- a/templates/requests/common/find_samples.mako +++ b/templates/requests/common/find_samples.mako @@ -71,7 +71,7 @@ %else: State: ${sample.state.name}<br/> %endif - Datasets: <a href="${h.url_for( controller='requests_common', action='view_dataset_transfer', cntrller=cntrller, sample_id=trans.security.encode_id( sample.id ) )}">${sample.transferred_dataset_files}/${len( sample.datasets )}</a><br/> + Datasets: <a href="${h.url_for( controller='requests_common', action='view_dataset_transfer', cntrller=cntrller, sample_id=trans.security.encode_id( sample.id ) )}">${len( sample.transferred_dataset_files )}/${len( sample.datasets )}</a><br/> %if is_admin: <i>User: ${sample.request.user.email}</i> %endif
participants (1)
-
commits-noreply@bitbucket.org