How to use the horizon.messages 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 / project / routers / ports / forms.py View on Github external
def handle(self, request, data):
        try:
            enable_snat = None
            if 'enable_snat' in data:
                enable_snat = data['enable_snat']
            api.neutron.router_add_gateway(request,
                                           self.initial['router_id'],
                                           data['network_id'],
                                           enable_snat)
            msg = _('Gateway interface is added')
            messages.success(request, msg)
            return True
        except Exception as e:
            LOG.info('Failed to set gateway to router %(id)s: %(exc)s',
                     {'id': self.initial['router_id'], 'exc': e})
            msg = _('Failed to set gateway: %s') % e
            redirect = reverse(self.failure_url)
            exceptions.handle(request, msg, redirect=redirect)
github openstack / freezer-web-ui / disaster_recovery / jobs / tables.py View on Github external
def single(self, table, request, job_id):
        freezer_api.Job(request).stop(job_id)
        messages.success(request, _("Job has stopped"))
        return shortcuts.redirect('horizon:disaster_recovery:jobs:index')
github openstack / senlin-dashboard / senlin_dashboard / cluster / receivers / forms.py View on Github external
def handle(self, request, data):
        try:
            params = yaml.safe_load(data.get("params"))
        except Exception as ex:
            raise ValidationError(_('The parameters is not a valid '
                                    'YAML formatted: %s') % six.text_type(ex))
        data["params"] = params

        try:
            receiver = senlin.receiver_create(request, **data)
            messages.success(
                request,
                _('Your receiver %s has been created successfully.') %
                data['name'])
            return receiver
        except Exception as e:
            redirect = reverse(INDEX_URL)
            msg = _('Unable to create new receiver: %s') % e
            exceptions.handle(request, msg, redirect=redirect)
            return False
github openstack / mistral-dashboard / mistraldashboard / workflows / forms.py View on Github external
def handle(self, request, data):
        try:
            data['workflow_identifier'] = data.pop('workflow_name')
            data['workflow_input'] = {}
            for param in self.workflow_parameters:
                value = data.pop(param)
                if value == "":
                    value = None
                data['workflow_input'][param] = value
            ex = api.execution_create(request, **data)

            msg = _('Execution has been created with id "%s".') % ex.id
            messages.success(request, msg)

            return True
        except Exception as e:
            msg = _('Failed to execute workflow "%s".') % e
            redirect = reverse('horizon:mistral:workflows:index')
            exceptions.handle(request, msg, redirect=redirect)
github openstack / adjutant-ui / adjutant_ui / content / email / forms.py View on Github external
def handle(self, request, data):
        try:
            response = api.adjutant.email_update(request, data['new_email'])
            if response.status_code == 202:
                msg = _("Confirmation email sent to %s.")
                messages.success(request, msg % data['new_email'])
            elif response.status_code == 400:
                messages.warning(request, _(
                    'Unable to update email. May already be in use.'))
            else:
                messages.error(request, _('Failed to update email.'))
            return True
        except Exception as e:
            messages.error(request, _('Failed to update email. %s' % str(e)))
            return False
github openstack / horizon / openstack_dashboard / dashboards / admin / networks / forms.py View on Github external
self._hide_provider_network_type()
            else:
                self.fields['network_type'].choices = network_type_choices

        try:
            if api.neutron.is_extension_supported(request,
                                                  'network_availability_zone'):
                zones = api.neutron.list_availability_zones(
                    self.request, 'network', 'available')
                self.fields['az_hints'].choices = [(zone['name'], zone['name'])
                                                   for zone in zones]
            else:
                del self.fields['az_hints']
        except Exception:
            msg = _('Failed to get availability zone list.')
            messages.warning(request, msg)
            del self.fields['az_hints']
github openstack / tacker-horizon / lbaas.py View on Github external
def _pool_get(request, pool_id, expand_resource=False):
    try:
        pool = neutronclient(request).show_pool(pool_id).get('pool')
    except Exception:
        messages.warning(request, _("Unable to get pool detail."))
        return None
    if expand_resource:
        # TODO(lyj): The expand resource(subnet, member etc.) attached
        # to a pool could be deleted without cleanup pool related database,
        # this will cause exceptions if we trying to get the deleted resources.
        # so we need to handle the situation by showing a warning message here.
        # we can safely remove the try/except once the neutron bug is fixed
        # https://bugs.launchpad.net/neutron/+bug/1406854
        try:
            pool['subnet'] = neutron.subnet_get(request, pool['subnet_id'])
        except Exception:
            messages.warning(request, _("Unable to get subnet for pool "
                                        "%(pool)s.") % {"pool": pool_id})
        pool['vip'] = _get_vip(request, pool, vip_dict=None,
                               expand_name_only=False)
        try:
github openstack / manila-ui / manila_ui / dashboards / project / shares / replicas / forms.py View on Github external
def handle(self, request, data):
        try:
            replica = manila.share_replica_create(request,
                                                  data['share_id'],
                                                  data['availability_zone'])
            message = _('Creating replica for share "%s".') % data['share_id']
            messages.success(request, message)
            return replica
        except Exception:
            redirect = reverse("horizon:project:shares:manage_replicas",
                               args=[data['share_id']])
            exceptions.handle(request,
                              _('Unable to create share replica.'),
                              redirect=redirect)
github openstack / horizon / openstack_dashboard / dashboards / project / data_processing / clusters / tables.py View on Github external
def get_data(self, request, instance_id):
        try:
            return saharaclient.cluster_get(request, instance_id)
        except api_base.APIException as e:
            if e.error_code == 404:
                raise Http404
            else:
                messages.error(request,
                               _("Unable to update row"))
github openstack / monasca-ui / monitoring / alarms / forms.py View on Github external
def handle(self, request, data):
        try:
            alarm_actions = [notification.get('id')
                             for notification in data['notifications']]
            api.monitor.alarm_create(
                request,
                name=data['name'],
                expression=data['expression'],
                description=data['description'],
                severity=data['severity'],
                alarm_actions=alarm_actions,
                ok_actions=alarm_actions,
                undetermined_actions=alarm_actions,
            )
            messages.success(request,
                             _('Alarm has been created successfully.'))
        except Exception as e:
            exceptions.handle(request, _('Unable to create the alarm: %s') % e.message)
            return False
        return True