'Validate and parse incomming data payload for a visualization.'

def _validate_and_parse_payload(self, payload):

    valid_but_uneditable_keys = ('id', 'model_class')
    ValidationError = exceptions.RequestParameterInvalidException
    validated_payload = {}
    for (key, val) in payload.items():
        if (key == 'type'):
            if (not isinstance(val, string_types)):
                raise ValidationError(('%s    must    be    a    string    or    unicode:    %s' % (key, str(type(val)))))
            val = util.sanitize_html.sanitize_html(val, 'utf-8')
        elif (key == 'config'):
            if (not isinstance(val, dict)):
                raise ValidationError(('%s    must    be    a    dictionary:    %s' % (key, str(type(val)))))
        elif (key == 'annotation'):
            if (not isinstance(val, string_types)):
                raise ValidationError(('%s    must    be    a    string    or    unicode:    %s' % (key, str(type(val)))))
            val = util.sanitize_html.sanitize_html(val, 'utf-8')
        elif (key == 'title'):
            if (not isinstance(val, string_types)):
                raise ValidationError(('%s    must    be    a    string    or    unicode:    %s' % (key, str(type(val)))))
            val = util.sanitize_html.sanitize_html(val, 'utf-8')
        elif (key == 'slug'):
            if (not isinstance(val, string_types)):
                raise ValidationError(('%s    must    be    a    string:    %s' % (key, str(type(val)))))
            val = util.sanitize_html.sanitize_html(val, 'utf-8')
        elif (key == 'dbkey'):
            if (not isinstance(val, string_types)):
                raise ValidationError(('%s    must    be    a    string    or    unicode:    %s' % (key, str(type(val)))))
            val = util.sanitize_html.sanitize_html(val, 'utf-8')
        elif (key not in valid_but_uneditable_keys):
            continue
        validated_payload[key] = val
    return validated_payload
