1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #4246: Fix duplication of field attributes when multiple IPNetworkVars are present in a script

This commit is contained in:
Jeremy Stretch
2020-02-24 10:01:31 -05:00
parent 25d126d4ff
commit b97d3b0716
2 changed files with 3 additions and 8 deletions

View File

@ -13,6 +13,7 @@
* [#4239](https://github.com/netbox-community/netbox/issues/4239) - Fix exception when selecting all filtered objects during bulk edit * [#4239](https://github.com/netbox-community/netbox/issues/4239) - Fix exception when selecting all filtered objects during bulk edit
* [#4240](https://github.com/netbox-community/netbox/issues/4240) - Fix exception when filtering foreign keys by NULL * [#4240](https://github.com/netbox-community/netbox/issues/4240) - Fix exception when filtering foreign keys by NULL
* [#4241](https://github.com/netbox-community/netbox/issues/4241) - Correct IP address hyperlinks on interface view * [#4241](https://github.com/netbox-community/netbox/issues/4241) - Correct IP address hyperlinks on interface view
* [#4246](https://github.com/netbox-community/netbox/issues/4246) - Fix duplication of field attributes when multiple IPNetworkVars are present in a script
--- ---

View File

@ -63,10 +63,6 @@ class ScriptVariable:
self.field_attrs['widget'] = widget self.field_attrs['widget'] = widget
self.field_attrs['required'] = required self.field_attrs['required'] = required
# Initialize the list of optional validators if none have already been defined
if 'validators' not in self.field_attrs:
self.field_attrs['validators'] = []
def as_field(self): def as_field(self):
""" """
Render the variable as a Django form field. Render the variable as a Django form field.
@ -227,14 +223,12 @@ class IPNetworkVar(ScriptVariable):
An IPv4 or IPv6 prefix. An IPv4 or IPv6 prefix.
""" """
form_field = IPNetworkFormField form_field = IPNetworkFormField
field_attrs = {
'validators': [prefix_validator]
}
def __init__(self, min_prefix_length=None, max_prefix_length=None, *args, **kwargs): def __init__(self, min_prefix_length=None, max_prefix_length=None, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# Optional minimum/maximum prefix lengths # Set prefix validator and optional minimum/maximum prefix lengths
self.field_attrs['validators'] = [prefix_validator]
if min_prefix_length is not None: if min_prefix_length is not None:
self.field_attrs['validators'].append( self.field_attrs['validators'].append(
MinPrefixLengthValidator(min_prefix_length) MinPrefixLengthValidator(min_prefix_length)