(sketch)
return attributes
Returns a dict with all attributes of a sketch.
Returns a dict with all attributes of a sketch.
Returns a dict with all attributes of a sketch .
def get_sketch_attributes(sketch):
    """Returns a dict with all attributes of a sketch."""
    attributes = {}
    ontology_def = ontology.ONTOLOGY
    for attribute in sketch.attributes:
        if attribute.sketch_id != sketch.id:
            continue
        name = attribute.name
        attribute_values = []
        ontology_string = attribute.ontology
        ontology_dict = ontology_def.get(ontology_string, {})
        cast_as_str = ontology_dict.get('cast_as', 'str')

        for attr_value in attribute.values:
            try:
                value = ontology.OntologyManager.decode_value(
                    attr_value.value, cast_as_str)
            except ValueError:
                value = 'Unable to cast'
            except NotImplementedError:
                value = f'Ontology {cast_as_str} not yet defined.'

            attribute_values.append(value)

        values = attribute_values
        if len(attribute_values) == 1:
            values = attribute_values[0]

        attributes[name] = {
          'value': values,
          'ontology': ontology_string,
        }
    return attributes
def get_sketch_attributes ( sketch ) : attributes = { } ontology_def = ontology . ONTOLOGY for attribute in sketch . attributes : if attribute . sketch_id != sketch . id : continue name = attribute . name attribute_values = [ ] ontology_string = attribute . ontology ontology_dict = ontology_def . get ( ontology_string , { } ) cast_as_str = ontology_dict . get ( 'cast_as' , 'str' ) for attr_value in attribute . values : try : value = ontology . OntologyManager . decode_value ( attr_value . value , cast_as_str ) except ValueError : value = 'Unable to cast' except NotImplementedError : value = f'Ontology {cast_as_str} not yet defined.' attribute_values . append ( value ) values = attribute_values if len ( attribute_values ) == 1 : values = attribute_values [ 0 ] attributes [ name ] = { 'value' : values , 'ontology' : ontology_string , } return attributes