A bit of code cleanup / optimization in sample tracking.

This commit is contained in:
Greg Von Kuster
2010-10-14 11:23:33 -04:00
parent 4631710431
commit bed3d3987c
5 changed files with 53 additions and 51 deletions
+19 -19
View File
@@ -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
+31 -29
View File
@@ -244,6 +244,11 @@ class RequestsAdmin( BaseController, UsesFormDefinitionWidgets ):
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, UsesFormDefinitionWidgets ):
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, UsesFormDefinitionWidgets ):
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, UsesFormDefinitionWidgets ):
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
+1 -1
View File
@@ -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
@@ -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
@@ -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 )}