commit/galaxy-central: 2 new changesets
2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/ed4a98b6ca9f/ Changeset: ed4a98b6ca9f User: jgoecks Date: 2013-08-20 20:08:27 Summary: Documentation and cleanup for APIItem mixin. Affected #: 1 file diff -r ee0a47c22e2fea2ce9d605a9cfef7071557ca6de -r ed4a98b6ca9f0f4dc6bd6e07cff7ee8ef470d0de lib/galaxy/model/item_attrs.py --- a/lib/galaxy/model/item_attrs.py +++ b/lib/galaxy/model/item_attrs.py @@ -160,19 +160,34 @@ class APIItem: """ Mixin for api representation. """ - #api_collection_visible_keys = ( 'id' ) - #api_element_visible_keys = ( 'id' ) - def get_api_value( self, view='collection', value_mapper = None ): + + def get_api_value( self, view='collection', value_mapper=None ): + """ + Return item dictionary. + """ + + if not value_mapper: + value_mapper = {} + def get_value( key, item ): + """ + Recursive helper function to get item values. + """ + # FIXME: why use exception here? Why not look for key in value_mapper + # first and then default to get_api_value? try: return item.get_api_value( view=view, value_mapper=value_mapper ) except: if key in value_mapper: return value_mapper.get( key )( item ) return item - if value_mapper is None: - value_mapper = {} - rval = {} + + # Create dict to represent item. + rval = dict( + model_class=self.__class__.__name__ + ) + + # Fill item dict with visible keys. try: visible_keys = self.__getattribute__( 'api_' + view + '_visible_keys' ) except AttributeError: @@ -181,13 +196,12 @@ try: item = self.__getattribute__( key ) if type( item ) == InstrumentedList: - rval[key] = [] + rval[ key ] = [] for i in item: - rval[key].append( get_value( key, i ) ) + rval[ key ].append( get_value( key, i ) ) else: - rval[key] = get_value( key, item ) + rval[ key ] = get_value( key, item ) except AttributeError: - rval[key] = None + rval[ key ] = None - rval['model_class'] = self.__class__.__name__ return rval https://bitbucket.org/galaxy/galaxy-central/commits/a699decd482c/ Changeset: a699decd482c User: jgoecks Date: 2013-08-20 20:40:20 Summary: Use APIMixin in History object. Affected #: 1 file diff -r ed4a98b6ca9f0f4dc6bd6e07cff7ee8ef470d0de -r a699decd482ce7732ea61ffb8e13714a0f991381 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -662,7 +662,7 @@ self.user = user self.group = group -class History( object, UsesAnnotations ): +class History( object, APIItem, UsesAnnotations ): api_collection_visible_keys = ( 'id', 'name', 'published', 'deleted' ) api_element_visible_keys = ( 'id', 'name', 'published', 'deleted', 'genome_build', 'purged' ) @@ -680,6 +680,7 @@ self.user = user self.datasets = [] self.galaxy_sessions = [] + self.tags = [] def _next_hid( self ): # TODO: override this with something in the database that ensures @@ -779,31 +780,20 @@ history_name = unicode(history_name, 'utf-8') return history_name - def get_api_value( self, view='collection', value_mapper = None ): - if value_mapper is None: - value_mapper = {} - rval = {} + def get_api_value( self, view='collection', value_mapper = None ): - try: - visible_keys = self.__getattribute__( 'api_' + view + '_visible_keys' ) - except AttributeError: - raise Exception( 'Unknown API view: %s' % view ) - for key in visible_keys: - try: - rval[key] = self.__getattribute__( key ) - if key in value_mapper: - rval[key] = value_mapper.get( key )( rval[key] ) - except AttributeError: - rval[key] = None - + # Get basic value. + rval = super( History, self ).get_api_value( 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 - rval['model_class'] = self.__class__.__name__ + rval[ 'tags' ] = tags_str_list + return rval def set_from_dict( self, new_data ): 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)
-
commits-noreply@bitbucket.org