How to use the horizon.forms.SelfHandlingForm function in horizon

To help you get started, we’ve selected a few horizon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / horizon / openstack_dashboard / dashboards / admin / metadata_defs / forms.py View on Github external
def handle(self, request, data):
        try:
            namespace = glance.metadefs_namespace_create(request,
                                                         data['namespace'])
            messages.success(request,
                             _('Namespace %s has been created.') %
                             namespace['namespace'])
            return namespace
        except Exception as e:
            msg = _('Unable to create new namespace. %s')
            msg %= e.message.split('Failed validating', 1)[0]
            exceptions.handle(request, message=msg)
            return False


class ManageResourceTypesForm(forms.SelfHandlingForm):
    def handle(self, request, context):
        namespace_name = self.initial['id']
        current_names = self.get_names(self.initial['resource_types'])
        try:
            updated_types = json.loads(self.data['resource_types'])
            selected_types = [updated_type for updated_type in updated_types
                              if updated_type.pop('selected', False)]
            for current_name in current_names:
                glance.metadefs_namespace_remove_resource_type(
                    self.request, namespace_name, current_name)
            for selected_type in selected_types:
                selected_type.pop('$$hashKey', None)
                selected_type.pop('created_at', None)
                selected_type.pop('updated_at', None)
                glance.metadefs_namespace_add_resource_type(
                    self.request, namespace_name, selected_type)
github openstack / senlin-dashboard / senlin_dashboard / cluster / nodes / forms.py View on Github external
else:
        try:
            metadata_dict = yaml.safe_load(metadata)
        except Exception as ex:
            raise Exception(_('The specified metadata is not a valid '
                              'YAML: %s') % six.text_type(ex))
    params = {"name": name,
              "profile_id": profile_id,
              "cluster_id": cluster_id,
              "role": role,
              "metadata": metadata_dict}

    return params


class CreateForm(forms.SelfHandlingForm):
    name = forms.CharField(max_length=255, label=_("Node Name"))
    profile_id = forms.ThemableChoiceField(
        label=_("Profile"),
        help_text=_("Profile used for this node."))
    cluster_id = forms.ThemableChoiceField(
        label=_("Cluster"),
        required=False,
        help_text=_("Cluster for this node."))
    role = forms.CharField(
        max_length=255,
        label=_("Role"),
        required=False,
        help_text=_("Role for this node in the specific cluster."))
    metadata = forms.CharField(
        label=_("Metadata"),
        required=False,
github openstack / horizon / openstack_dashboard / dashboards / project / volume_groups / forms.py View on Github external
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


from django.urls import reverse
from django.utils.translation import ugettext_lazy as _

from horizon import exceptions
from horizon import forms
from horizon import messages

from openstack_dashboard.api import cinder


class UpdateForm(forms.SelfHandlingForm):
    name = forms.CharField(max_length=255, label=_("Name"))
    description = forms.CharField(max_length=255,
                                  widget=forms.Textarea(attrs={'rows': 4}),
                                  label=_("Description"),
                                  required=False)

    def clean(self):
        cleaned_data = super(UpdateForm, self).clean()
        new_desc = cleaned_data.get('description')
        old_desc = self.initial['description']
        if old_desc and not new_desc:
            error_msg = _("Description is required.")
            self._errors['description'] = self.error_class([error_msg])
            return cleaned_data

        return cleaned_data
github intel / virtual-storage-manager / source / vsm-dashboard / vsm_dashboard / dashboards / vsm / cluster-import / form.py View on Github external
from django.core import validators
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from horizon import exceptions
from horizon import forms
from horizon import messages
from horizon.utils.validators import validate_port_range
import logging

from vsm_dashboard.api import vsm as vsm_api

LOG = logging.getLogger(__name__)

class ImportCluster(forms.SelfHandlingForm):
    failure_url = 'horizon:vsm:cluster-import:index'
    monitor_host = forms.ChoiceField(label=_("Monitor Host"),
                                    required=True)
    monitor_keyring = forms.CharField(label=_("Monitor Keyring"),
                                    max_length=255,
                                    min_length=1,
                                    required=True)
    cluster_conf = forms.CharField(label=_("Cluster Conf"),
                                    max_length=255,
                                    min_length=1,
                                    required=True)
    def __init__(self, request, *args, **kwargs):
        super(ImportCluster, self).__init__(request, *args, **kwargs)
        monitor_list = []
        try:
            #get the serverlist
github openstack / horizon / openstack_dashboard / dashboards / project / vpn / forms.py View on Github external
import logging

from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from horizon import exceptions
from horizon import forms
from horizon import messages

from openstack_dashboard import api


LOG = logging.getLogger(__name__)


class UpdateVPNService(forms.SelfHandlingForm):
    name = forms.CharField(max_length=80, label=_("Name"), required=False)
    vpnservice_id = forms.CharField(
        label=_("ID"),
        widget=forms.TextInput(attrs={'readonly': 'readonly'}))
    description = forms.CharField(
        required=False, max_length=80, label=_("Description"))
    admin_state_up = forms.BooleanField(label=_("Enable Admin State"),
                                        required=False)

    failure_url = 'horizon:project:vpn:index'

    def handle(self, request, context):
        try:
            data = {'vpnservice': {'name': context['name'],
                                   'description': context['description'],
                                   'admin_state_up': context['admin_state_up'],
github intel / virtual-storage-manager / source / vsm-dashboard / vsm_dashboard / dashboards / vsm / cephupgrade / form.py View on Github external
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.


from django.utils.translation import ugettext_lazy as _
from horizon import forms


import logging


LOG = logging.getLogger(__name__)


class CephUpgrade(forms.SelfHandlingForm):
    package_url = forms.CharField(label=_("Package URL"),
                            max_length=255,
                            min_length=1,
                            initial='http://ceph.com/debian-hammer/',
                            error_messages={
                            'required': _('This field is required.'),},
                            )

    key_url  = forms.CharField(label=_("Key URL"),
                            max_length=255,
                            min_length=1,
                            initial='https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc',
                            error_messages={
                            'required': _('This field is required.'),},
                            )
    proxy  = forms.CharField(label=_("Proxy URL"),
github openstack / manila-ui / manila_ui / dashboards / project / share_networks / forms.py View on Github external
try:
            manila.share_network_update(request, share_net_id,
                                        name=data['name'],
                                        description=data['description'])

            message = _('Updating share network "%s"') % data['name']
            messages.info(request, message)
            return True
        except Exception:
            redirect = reverse("horizon:project:shares:index")
            exceptions.handle(request,
                              _('Unable to update share network.'),
                              redirect=redirect)


class AddSecurityServiceForm(forms.SelfHandlingForm):
    sec_service = forms.MultipleChoiceField(
        label=_("Networks"),
        required=True,
        widget=forms.CheckboxSelectMultiple(),
        error_messages={
            'required': _(
                "At least one security service"
                " must be specified.")})

    def __init__(self, request, *args, **kwargs):
        super(AddSecurityServiceForm, self).__init__(
            request, *args, **kwargs)
        sec_services_choices = manila.security_service_list(request)
        self.fields['sec_service'].choices = [(' ', ' ')] + \
                                             [(choice.id, choice.name or
                                              choice.id) for choice in
github openstack / horizon / openstack_dashboard / dashboards / router / nexus1000v / forms.py View on Github external
'tenant_id': data['project']}
            profile = api.neutron.profile_create(request,
                                                 **params)
            msg = _('Network Profile %s '
                    'was successfully created.') % data['name']
            LOG.debug(msg)
            messages.success(request, msg)
            return profile
        except Exception:
            redirect = reverse('horizon:router:nexus1000v:index')
            msg = _('Failed to create network profile %s') % data['name']
            LOG.error(msg)
            exceptions.handle(request, msg, redirect=redirect)


class UpdateNetworkProfile(forms.SelfHandlingForm):

    """Update Network Profile form."""

    profile_id = forms.CharField(label=_("ID"),
                                 widget=forms.HiddenInput())
    name = forms.CharField(max_length=255,
                           label=_("Name"))
    segment_type = forms.ChoiceField(label=_('Segment Type'),
                                     choices=[('vlan', 'VLAN'),
                                              ('vxlan', 'VXLAN')],
                                     widget=forms.Select
                                     (attrs={'class': 'switchable'}))
    segment_range = forms.CharField(max_length=255,
                                    label=_("Segment Range"))
    physical_network = forms.CharField(max_length=255,
                                       label=_("Physical Network"),
github openstack / horizon / openstack_dashboard / dashboards / project / backups / forms.py View on Github external
import operator

from django.urls import reverse
from django.utils.translation import ugettext_lazy as _

from horizon import exceptions
from horizon import forms
from horizon import messages

from openstack_dashboard import api
from openstack_dashboard.dashboards.project.containers \
    import utils as containers_utils


class CreateBackupForm(forms.SelfHandlingForm):
    name = forms.CharField(max_length=255, label=_("Backup Name"))
    description = forms.CharField(widget=forms.Textarea(attrs={'rows': 4}),
                                  label=_("Description"),
                                  required=False)
    container_name = forms.CharField(
        max_length=255,
        label=_("Container Name"),
        validators=[containers_utils.no_slash_validator],
        required=False)
    volume_id = forms.CharField(widget=forms.HiddenInput())
    snapshot_id = forms.ThemableChoiceField(label=_("Backup Snapshot"),
                                            required=False)

    def __init__(self, request, *args, **kwargs):
        super(CreateBackupForm, self).__init__(request, *args, **kwargs)
        if kwargs['initial'].get('snapshot_id'):
github openstack / cloudkitty-dashboard / cloudkittydashboard / dashboards / admin / hashmap / forms.py View on Github external
import logging

from django.utils.translation import ugettext_lazy as _
from horizon import exceptions as horizon_exceptions
from horizon import forms
from horizon import messages
from keystoneauth1 import exceptions

from cloudkittydashboard.api import cloudkitty as api

from openstack_dashboard import api as api_keystone

LOG = logging.getLogger(__name__)


class CreateServiceForm(forms.SelfHandlingForm):
    services_choices = [("service", _("Service")),
                        ("custom_service", _("Custom service"))]
    service_type = forms.ChoiceField(
        label=_("Service type"),
        choices=services_choices,
        widget=forms.Select(attrs={
            'class': 'switchable',
            'data-slug': 'servicetype'}))
    service = forms.DynamicChoiceField(
        label=_("Service"),
        help_text=_("Services are provided by main collector."),
        widget=forms.Select(attrs={
            'class': 'switched',
            'data-switch-on': 'servicetype',
            'data-required-when-shown': 'true',
            'data-servicetype-service': _('Service')}),