

def clean(self):
    data = super(CreateNamespaceForm, self).clean()
    metadef_file = data.get('metadef_file', None)
    metadata_raw = data.get('direct_input', None)
    if (metadata_raw and metadef_file):
        raise ValidationError(_('Cannot specify both file and direct input.'))
    if ((not metadata_raw) and (not metadef_file)):
        raise ValidationError(_('No input was provided for the namespace content.'))
    try:
        if metadef_file:
            ns_str = self.files['metadef_file'].read()
        else:
            ns_str = data['direct_input']
        namespace = json.loads(ns_str)
        if data['public']:
            namespace['visibility'] = 'public'
        else:
            namespace['visibility'] = 'private'
        namespace['protected'] = data['protected']
        for protected_prop in constants.METADEFS_PROTECTED_PROPS:
            namespace.pop(protected_prop, None)
        data['namespace'] = namespace
    except Exception as e:
        msg = (_('There was a problem loading the namespace: %s.') % e)
        raise forms.ValidationError(msg)
    return data

dataset/ETHPy150Open openstack/horizon/openstack_dashboard/dashboards/admin/metadata_defs/forms.py CreateNamespaceForm.clean/original