mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Merge branch 'develop' into develop-2.9
This commit is contained in:
@ -161,6 +161,10 @@ direction = ChoiceVar(choices=CHOICES)
|
|||||||
|
|
||||||
In the example above, selecting the choice labeled "North" will submit the value `n`.
|
In the example above, selecting the choice labeled "North" will submit the value `n`.
|
||||||
|
|
||||||
|
### MultiChoiceVar
|
||||||
|
|
||||||
|
Similar to `ChoiceVar`, but allows for the selection of multiple choices.
|
||||||
|
|
||||||
### ObjectVar
|
### ObjectVar
|
||||||
|
|
||||||
A particular object within NetBox. Each ObjectVar must specify a particular model, and allows the user to select one of the available instances. ObjectVar accepts several arguments, listed below.
|
A particular object within NetBox. Each ObjectVar must specify a particular model, and allows the user to select one of the available instances. ObjectVar accepts several arguments, listed below.
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
# NetBox v2.8
|
# NetBox v2.8
|
||||||
|
|
||||||
|
## v2.8.10 (FUTURE)
|
||||||
|
|
||||||
|
### Enhancements
|
||||||
|
|
||||||
|
* [#4885](https://github.com/netbox-community/netbox/issues/4885) - Add MultiChoiceVar for custom scripts
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#4992](https://github.com/netbox-community/netbox/issues/4992) - Add `display_name` to nested VRF serializer
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## v2.8.9 (2020-08-04)
|
## v2.8.9 (2020-08-04)
|
||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
@ -34,6 +34,7 @@ __all__ = [
|
|||||||
'IPAddressVar',
|
'IPAddressVar',
|
||||||
'IPAddressWithMaskVar',
|
'IPAddressWithMaskVar',
|
||||||
'IPNetworkVar',
|
'IPNetworkVar',
|
||||||
|
'MultiChoiceVar',
|
||||||
'MultiObjectVar',
|
'MultiObjectVar',
|
||||||
'ObjectVar',
|
'ObjectVar',
|
||||||
'Script',
|
'Script',
|
||||||
@ -167,6 +168,13 @@ class ChoiceVar(ScriptVariable):
|
|||||||
self.field_attrs['choices'] = choices
|
self.field_attrs['choices'] = choices
|
||||||
|
|
||||||
|
|
||||||
|
class MultiChoiceVar(ChoiceVar):
|
||||||
|
"""
|
||||||
|
Like ChoiceVar, but allows for the selection of multiple choices.
|
||||||
|
"""
|
||||||
|
form_field = forms.MultipleChoiceField
|
||||||
|
|
||||||
|
|
||||||
class ObjectVar(ScriptVariable):
|
class ObjectVar(ScriptVariable):
|
||||||
"""
|
"""
|
||||||
A single object within NetBox.
|
A single object within NetBox.
|
||||||
|
@ -5,6 +5,12 @@ from netaddr import IPAddress, IPNetwork
|
|||||||
from dcim.models import DeviceRole
|
from dcim.models import DeviceRole
|
||||||
from extras.scripts import *
|
from extras.scripts import *
|
||||||
|
|
||||||
|
CHOICES = (
|
||||||
|
('ff0000', 'Red'),
|
||||||
|
('00ff00', 'Green'),
|
||||||
|
('0000ff', 'Blue')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ScriptVariablesTest(TestCase):
|
class ScriptVariablesTest(TestCase):
|
||||||
|
|
||||||
@ -101,12 +107,6 @@ class ScriptVariablesTest(TestCase):
|
|||||||
|
|
||||||
def test_choicevar(self):
|
def test_choicevar(self):
|
||||||
|
|
||||||
CHOICES = (
|
|
||||||
('ff0000', 'Red'),
|
|
||||||
('00ff00', 'Green'),
|
|
||||||
('0000ff', 'Blue')
|
|
||||||
)
|
|
||||||
|
|
||||||
class TestScript(Script):
|
class TestScript(Script):
|
||||||
|
|
||||||
var1 = ChoiceVar(
|
var1 = ChoiceVar(
|
||||||
@ -114,12 +114,37 @@ class ScriptVariablesTest(TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Validate valid choice
|
# Validate valid choice
|
||||||
data = {'var1': CHOICES[0][0]}
|
data = {'var1': 'ff0000'}
|
||||||
form = TestScript().as_form(data)
|
form = TestScript().as_form(data)
|
||||||
self.assertTrue(form.is_valid())
|
self.assertTrue(form.is_valid())
|
||||||
self.assertEqual(form.cleaned_data['var1'], CHOICES[0][0])
|
self.assertEqual(form.cleaned_data['var1'], 'ff0000')
|
||||||
|
|
||||||
# Validate invalid choices
|
# Validate invalid choice
|
||||||
|
data = {'var1': 'taupe'}
|
||||||
|
form = TestScript().as_form(data)
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
|
||||||
|
def test_multichoicevar(self):
|
||||||
|
|
||||||
|
class TestScript(Script):
|
||||||
|
|
||||||
|
var1 = MultiChoiceVar(
|
||||||
|
choices=CHOICES
|
||||||
|
)
|
||||||
|
|
||||||
|
# Validate single choice
|
||||||
|
data = {'var1': ['ff0000']}
|
||||||
|
form = TestScript().as_form(data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
self.assertEqual(form.cleaned_data['var1'], ['ff0000'])
|
||||||
|
|
||||||
|
# Validate multiple choices
|
||||||
|
data = {'var1': ('ff0000', '00ff00')}
|
||||||
|
form = TestScript().as_form(data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
self.assertEqual(form.cleaned_data['var1'], ['ff0000', '00ff00'])
|
||||||
|
|
||||||
|
# Validate invalid choice
|
||||||
data = {'var1': 'taupe'}
|
data = {'var1': 'taupe'}
|
||||||
form = TestScript().as_form(data)
|
form = TestScript().as_form(data)
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
|
@ -26,7 +26,7 @@ class NestedVRFSerializer(WritableNestedSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.VRF
|
model = models.VRF
|
||||||
fields = ['id', 'url', 'name', 'rd', 'prefix_count']
|
fields = ['id', 'url', 'name', 'rd', 'display_name', 'prefix_count']
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -22,7 +22,7 @@ class AppTest(APITestCase):
|
|||||||
|
|
||||||
class VRFTest(APIViewTestCases.APIViewTestCase):
|
class VRFTest(APIViewTestCases.APIViewTestCase):
|
||||||
model = VRF
|
model = VRF
|
||||||
brief_fields = ['id', 'name', 'prefix_count', 'rd', 'url']
|
brief_fields = ['display_name', 'id', 'name', 'prefix_count', 'rd', 'url']
|
||||||
create_data = [
|
create_data = [
|
||||||
{
|
{
|
||||||
'name': 'VRF 4',
|
'name': 'VRF 4',
|
||||||
|
Reference in New Issue
Block a user