'Cycle through metadata and return as dictionary.'

def serialize_metadata(self, dataset_assoc, key, excluded=None, **context):

    excluded = ([] if (excluded is None) else excluded)
    metadata = {}
    for (name, spec) in dataset_assoc.metadata.spec.items():
        if (name in excluded):
            continue
        val = dataset_assoc.metadata.get(name)
        if isinstance(val, model.MetadataFile):
            if (not self.app.config.expose_dataset_path):
                continue
            val = val.file_name
        elif ((val is None) and hasattr(dataset_assoc.datatype, name)):
            val = getattr(dataset_assoc.datatype, name)
        metadata[name] = val
    return metadata
