Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions netbox_routing/forms/static.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.utils.translation import gettext as _

from dcim.models import Device
from ipam.models import VRF
from netbox.forms import NetBoxModelForm
Expand All @@ -7,15 +9,41 @@
DynamicModelMultipleChoiceField,
CommentField,
)
from utilities.forms.rendering import FieldSet


class StaticRouteForm(NetBoxModelForm):
devices = DynamicModelMultipleChoiceField(queryset=Device.objects.all())
devices = DynamicModelMultipleChoiceField(
queryset=Device.objects.all(),
label=_('Devices'),
)
vrf = DynamicModelChoiceField(
queryset=VRF.objects.all(), required=False, label='VRF'
queryset=VRF.objects.all(),
required=False,
label=_('VRF'),
)
comments = CommentField()

fieldsets = (
FieldSet(
'devices',
'vrf',
),
FieldSet(
'prefix',
'next_hop',
'metric',
name=_('Route'),
),
FieldSet(
'name',
'description',
'tag',
'permanent',
name=_('Metadata'),
),
)

class Meta:
model = StaticRoute
fields = (
Expand Down
9 changes: 7 additions & 2 deletions netbox_routing/models/static.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.db.models import CheckConstraint, Q
from django.urls import reverse
from django.utils.translation import gettext as _

from ipam.fields import IPNetworkField
from netbox.models import PrimaryModel
Expand All @@ -20,8 +21,12 @@ class StaticRoute(PrimaryModel):
null=True,
verbose_name='VRF',
)
prefix = IPNetworkField(help_text='IPv4 or IPv6 network with mask')
next_hop = IPAddressField()
prefix = IPNetworkField(
help_text=_('IPv4 or IPv6 network with mask'),
)
next_hop = IPAddressField(
verbose_name=_('Next Hop'),
)
name = models.CharField(
max_length=50,
verbose_name='Name',
Expand Down
2 changes: 1 addition & 1 deletion netbox_routing/navigation/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

static = PluginMenuItem(
link='plugins:netbox_routing:staticroute_list',
link_text='Static Route',
link_text='Static Routes',
permissions=['netbox_routing.view_staticroute'],
buttons=(
PluginMenuButton(
Expand Down
5 changes: 0 additions & 5 deletions netbox_routing/tests/static/test_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# from django.core.exceptions import ValidationError
from django.test import TestCase

# from utilities.testing import create_test_device

# from netbox_routing.models import *

__all__ = ('StaticRouteTestCase',)


Expand Down
2 changes: 2 additions & 0 deletions netbox_routing/views/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class StaticRouteDevicesView(ObjectChildrenView):
tab = ViewTab(
label='Assigned Devices',
badge=lambda obj: Device.objects.filter(static_routes=obj).count(),
permission='dcim.view_device',
hide_if_empty=True,
)

def get_children(self, request, parent):
Expand Down