

def handle(self, request, context):
    policy_id = self.initial['policy_id']
    policy_name_or_id = (self.initial['name'] or policy_id)
    try:
        insert_rule_id = context['firewall_rule_id']
        insert_rule = api.fwaas.rule_get(request, insert_rule_id)
        body = {
            'firewall_rule_id': insert_rule_id,
            'insert_before': context['insert_before'],
            'insert_after': context['insert_after'],
        }
        policy = api.fwaas.policy_insert_rule(request, policy_id, **body)
        msg = (_('Rule %(rule)s was successfully inserted to policy %(policy)s.') % {
            'rule': (insert_rule.name or insert_rule.id),
            'policy': policy_name_or_id,
        })
        LOG.debug(msg)
        messages.success(request, msg)
        return policy
    except Exception as e:
        msg = (_('Failed to insert rule to policy %(name)s: %(reason)s') % {
            'name': policy_id,
            'reason': e,
        })
        LOG.error(msg)
        redirect = reverse(self.failure_url)
        exceptions.handle(request, msg, redirect=redirect)

dataset/ETHPy150Open openstack/horizon/openstack_dashboard/dashboards/project/firewalls/forms.py InsertRuleToPolicy.handle/original