Skip to content

Commit

Permalink
Move tag copying into HasTags mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanheus committed Jul 5, 2017
1 parent 37cb522 commit bf8b156
Showing 1 changed file with 33 additions and 36 deletions.
69 changes: 33 additions & 36 deletions lib/galaxy/model/__init__.py
Expand Up @@ -83,6 +83,26 @@ def set_datatypes_registry( d_registry ):
_datatypes_registry = d_registry


class HasTags( object ):
dict_collection_visible_keys = ( 'tags' )
dict_element_visible_keys = ( 'tags' )

def to_dict(self, *args, **kwargs):
rval = super( HasTags, self).to_dict(*args, **kwargs)
rval['tags'] = self.make_tag_string_list()
return rval

def make_tag_string_list(self):
# add tags string list
tags_str_list = []
for tag in self.tags:
tag_str = tag.user_tname
if tag.value is not None:
tag_str += ":" + tag.user_value
tags_str_list.append( tag_str )
return tags_str_list


class HasName:

def get_display_name( self ):
Expand Down Expand Up @@ -1157,7 +1177,7 @@ def is_hda(d):
return isinstance( d, HistoryDatasetAssociation )


class History( object, Dictifiable, UsesAnnotations, HasName ):
class History( HasTags, Dictifiable, UsesAnnotations, HasName ):

dict_collection_visible_keys = ( 'id', 'name', 'published', 'deleted' )
dict_element_visible_keys = ( 'id', 'name', 'genome_build', 'deleted', 'purged', 'update_time',
Expand Down Expand Up @@ -1342,15 +1362,6 @@ def to_dict( self, view='collection', value_mapper=None ):
# Get basic value.
rval = super( History, self ).to_dict( view=view, value_mapper=value_mapper )

# Add tags.
tags_str_list = []
for tag in self.tags:
tag_str = tag.user_tname
if tag.value is not None:
tag_str += ":" + tag.user_value
tags_str_list.append( tag_str )
rval[ 'tags' ] = tags_str_list

if view == 'element':
rval[ 'size' ] = int( self.disk_size )

Expand Down Expand Up @@ -2327,7 +2338,8 @@ def convert_dataset( self, trans, target_type ):
return msg


class HistoryDatasetAssociation( DatasetInstance, Dictifiable, UsesAnnotations, HasName ):
class HistoryDatasetAssociation( DatasetInstance, HasTags, Dictifiable, UsesAnnotations,
HasName ):
"""
Resource class that creates a relation between a dataset and a user history.
"""
Expand Down Expand Up @@ -2501,6 +2513,7 @@ def to_dict( self, view='collection', expose_dataset_path=False ):
# Since this class is a proxy to rather complex attributes we want to
# display in other objects, we can't use the simpler method used by
# other model classes.
original_rval = super( HistoryDatasetAssociation, self ).to_dict(view=view)
hda = self
rval = dict( id=hda.id,
hda_ldda='hda',
Expand All @@ -2523,14 +2536,7 @@ def to_dict( self, view='collection', expose_dataset_path=False ):
misc_info=hda.info.strip() if isinstance( hda.info, string_types ) else hda.info,
misc_blurb=hda.blurb )

# add tags string list
tags_str_list = []
for tag in self.tags:
tag_str = tag.user_tname
if tag.value is not None:
tag_str += ":" + tag.user_value
tags_str_list.append( tag_str )
rval[ 'tags' ] = tags_str_list
rval.update(original_rval)

if hda.copied_from_library_dataset_dataset_association is not None:
rval['copied_from_ldda_id'] = hda.copied_from_library_dataset_dataset_association.id
Expand Down Expand Up @@ -3318,7 +3324,10 @@ def set_from_dict( self, new_data ):
return changed


class HistoryDatasetCollectionAssociation( DatasetCollectionInstance, UsesAnnotations, Dictifiable ):
class HistoryDatasetCollectionAssociation( DatasetCollectionInstance,
HasTags,
Dictifiable,
UsesAnnotations ):
""" Associates a DatasetCollection with a History. """
editable_keys = ( 'name', 'deleted', 'visible' )

Expand Down Expand Up @@ -3374,6 +3383,7 @@ def to_hda_representative( self, multiple=False ):
return rval if multiple else rval[ 0 ]

def to_dict( self, view='collection' ):
original_dict_value = super(HistoryDatasetCollectionAssociation, self).to_dict( view=view )
dict_value = dict(
hid=self.hid,
history_id=self.history.id,
Expand All @@ -3383,13 +3393,7 @@ def to_dict( self, view='collection' ):
**self._base_to_dict(view=view)
)

tags_str_list = []
for tag in self.tags:
tag_str = tag.user_tname
if tag.value is not None:
tag_str += ":" + tag.user_value
tags_str_list.append( tag_str )
dict_value[ 'tags' ] = tags_str_list
dict_value.update(original_dict_value)

return dict_value

Expand Down Expand Up @@ -3427,7 +3431,7 @@ def copy( self, element_destination=None ):
return hdca


class LibraryDatasetCollectionAssociation( DatasetCollectionInstance, Dictifiable ):
class LibraryDatasetCollectionAssociation( DatasetCollectionInstance ):
""" Associates a DatasetCollection with a library folder. """
editable_keys = ( 'name', 'deleted' )

Expand Down Expand Up @@ -3624,7 +3628,7 @@ def __init__( self ):
self.user = None


class StoredWorkflow( object, Dictifiable):
class StoredWorkflow( HasTags, Dictifiable ):

dict_collection_visible_keys = ( 'id', 'name', 'published', 'deleted' )
dict_element_visible_keys = ( 'id', 'name', 'published', 'deleted' )
Expand All @@ -3646,13 +3650,6 @@ def copy_tags_from(self, target_user, source_workflow):

def to_dict( self, view='collection', value_mapper=None ):
rval = super( StoredWorkflow, self ).to_dict( view=view, value_mapper=value_mapper )
tags_str_list = []
for tag in self.tags:
tag_str = tag.user_tname
if tag.value is not None:
tag_str += ":" + tag.user_value
tags_str_list.append( tag_str )
rval['tags'] = tags_str_list
rval['latest_workflow_uuid'] = ( lambda uuid: str( uuid ) if self.latest_workflow.uuid else None )( self.latest_workflow.uuid )
return rval

Expand Down

0 comments on commit bf8b156

Please sign in to comment.