diff --git a/openstack_dashboard/dashboards/project/firewalls/forms.py b/openstack_dashboard/dashboards/project/firewalls/forms.py index dca7cf6c01..1320ca9dfa 100644 --- a/openstack_dashboard/dashboards/project/firewalls/forms.py +++ b/openstack_dashboard/dashboards/project/firewalls/forms.py @@ -36,9 +36,12 @@ class UpdateRule(forms.SelfHandlingForm): max_length=80, label=_("Description")) protocol = forms.ChoiceField( label=_("Protocol"), required=False, + choices=[('TCP', _('TCP')), ('UDP', _('UDP')), ('ICMP', _('ICMP')), + ('ANY', _('ANY'))], help_text=_('Protocol for the firewall rule')) action = forms.ChoiceField( label=_("Action"), required=False, + choices=[('ALLOW', _('ALLOW')), ('DENY', _('DENY'))], help_text=_('Action for the firewall rule')) source_ip_address = forms.IPField( label=_("Source IP Address/Subnet"), @@ -68,26 +71,6 @@ class UpdateRule(forms.SelfHandlingForm): failure_url = 'horizon:project:firewalls:index' - def __init__(self, request, *args, **kwargs): - super(UpdateRule, self).__init__(request, *args, **kwargs) - - protocol = kwargs['initial']['protocol'] - protocol = protocol.upper() if protocol else 'ANY' - action = kwargs['initial']['action'].upper() - - protocol_choices = [(protocol, protocol)] - for tup in [('TCP', _('TCP')), ('UDP', _('UDP')), ('ICMP', _('ICMP')), - ('ANY', _('ANY'))]: - if tup[0] != protocol: - protocol_choices.append(tup) - self.fields['protocol'].choices = protocol_choices - - action_choices = [(action, action)] - for tup in [('ALLOW', _('ALLOW')), ('DENY', _('DENY'))]: - if tup[0] != action: - action_choices.append(tup) - self.fields['action'].choices = action_choices - def handle(self, request, context): rule_id = self.initial['rule_id'] name_or_id = context.get('name') or rule_id diff --git a/openstack_dashboard/dashboards/project/firewalls/views.py b/openstack_dashboard/dashboards/project/firewalls/views.py index a36e939513..a90d87e65c 100644 --- a/openstack_dashboard/dashboards/project/firewalls/views.py +++ b/openstack_dashboard/dashboards/project/firewalls/views.py @@ -145,6 +145,9 @@ class UpdateRuleView(forms.ModalFormView): def get_initial(self): rule = self._get_object() initial = rule.get_dict() + protocol = initial['protocol'] + initial['protocol'] = protocol.upper() if protocol else 'ANY' + initial['action'] = initial['action'].upper() return initial