Skip to content

Commit 147009a

Browse files
authored
Merge pull request #210 from pl0xym0r/209_object_journaling
Add Journaling to objects
2 parents 4c45cac + 478de68 commit 147009a

File tree

10 files changed

+28
-104
lines changed

10 files changed

+28
-104
lines changed

netbox_bgp/api/serializers.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
class RoutingPolicySerializer(NetBoxModelSerializer):
29-
url = HyperlinkedIdentityField(view_name="plugins:netbox_bgp:routingpolicy")
29+
url = HyperlinkedIdentityField(view_name="plugins-api:netbox_bgp-api:routingpolicy-detail")
3030

3131
class Meta:
3232
model = RoutingPolicy
@@ -44,7 +44,7 @@ class Meta:
4444

4545

4646
class PrefixListSerializer(NetBoxModelSerializer):
47-
url = HyperlinkedIdentityField(view_name="plugins:netbox_bgp:prefixlist")
47+
url = HyperlinkedIdentityField(view_name="plugins-api:netbox_bgp-api:prefixlist-detail")
4848

4949
class Meta:
5050
model = PrefixList
@@ -63,7 +63,7 @@ class Meta:
6363

6464

6565
class BGPPeerGroupSerializer(NetBoxModelSerializer):
66-
url = HyperlinkedIdentityField(view_name="plugins:netbox_bgp:bgppeergroup")
66+
url = HyperlinkedIdentityField(view_name="plugins-api:netbox_bgp-api:bgppeergroup-detail")
6767

6868
import_policies = SerializedPKRelatedField(
6969
queryset=RoutingPolicy.objects.all(),
@@ -99,7 +99,7 @@ class Meta:
9999

100100

101101
class BGPSessionSerializer(NetBoxModelSerializer):
102-
url = HyperlinkedIdentityField(view_name="plugins:netbox_bgp:bgpsession")
102+
url = HyperlinkedIdentityField(view_name="plugins-api:netbox_bgp-api:bgpsession-detail")
103103
status = ChoiceField(choices=SessionStatusChoices, required=False)
104104
site = SiteSerializer(nested=True, required=False, allow_null=True)
105105
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
@@ -188,7 +188,7 @@ def to_representation(self, instance):
188188
class CommunitySerializer(NetBoxModelSerializer):
189189
status = ChoiceField(choices=CommunityStatusChoices, required=False)
190190
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
191-
url = HyperlinkedIdentityField(view_name="plugins:netbox_bgp:community")
191+
url = HyperlinkedIdentityField(view_name="plugins-api:netbox_bgp-api:community-detail")
192192

193193
class Meta:
194194
model = Community
@@ -212,7 +212,7 @@ class Meta:
212212

213213

214214
class CommunityListSerializer(NetBoxModelSerializer):
215-
url = HyperlinkedIdentityField(view_name="plugins:netbox_bgp:communitylist")
215+
url = HyperlinkedIdentityField(view_name="plugins-api:netbox_bgp-api:communitylist-detail")
216216

217217
class Meta:
218218
model = CommunityList

netbox_bgp/api/urls.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from .views import (
44
BGPSessionViewSet, RoutingPolicyViewSet, BGPPeerGroupViewSet, CommunityViewSet,
55
PrefixListViewSet, PrefixListRuleViewSet, RoutingPolicyRuleViewSet,
6-
CommunityListViewSet, CommunityListRuleViewSet
6+
CommunityListViewSet, CommunityListRuleViewSet, RootView
77
)
88

9+
910
router = NetBoxRouter()
11+
router.APIRootView = RootView
1012
router.register('session', BGPSessionViewSet, 'session')
1113
router.register('bgpsession', BGPSessionViewSet, 'bgpsession')
1214
router.register('routing-policy', RoutingPolicyViewSet)

netbox_bgp/api/views.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from netbox.api.viewsets import NetBoxModelViewSet
2+
from rest_framework.routers import APIRootView
23

34
from .serializers import (
45
BGPSessionSerializer, RoutingPolicySerializer, BGPPeerGroupSerializer,
@@ -16,6 +17,10 @@
1617
RoutingPolicyRuleFilterSet, CommunityListFilterSet, CommunityListRuleFilterSet
1718
)
1819

20+
class RootView(APIRootView):
21+
def get_view_name(self):
22+
return 'BGP'
23+
1924

2025
class BGPSessionViewSet(NetBoxModelViewSet):
2126
queryset = BGPSession.objects.all()
@@ -66,7 +71,6 @@ class PrefixListViewSet(NetBoxModelViewSet):
6671

6772

6873
class PrefixListRuleViewSet(NetBoxModelViewSet):
69-
7074
queryset = PrefixListRule.objects.all()
7175
serializer_class = PrefixListRuleSerializer
7276
filterset_class = PrefixListRuleFilterSet

netbox_bgp/templates/netbox_bgp/bgppeergroup.html

-14
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,6 @@
99
<li class="breadcrumb-item"><a href="{% url 'plugins:netbox_bgp:bgppeergroup_list' %}">Peer Groups</a></li>
1010
{% endblock %}
1111

12-
{% block tabs %}
13-
<ul class="nav nav-tabs px-3">
14-
{% block tab_items %}
15-
<li class="nav-item" role="presentation">
16-
<a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">{{ object|meta:"verbose_name"|bettertitle }}</a>
17-
</li>
18-
{% endblock tab_items %}
19-
{% if perms.extras.view_objectchange %}
20-
<li role="presentation" class="nav-item">
21-
<a href="{% url 'plugins:netbox_bgp:bgppeergroup_changelog' pk=object.pk %}" class="nav-link{% if active_tab == 'changelog'%} active{% endif %}">Change Log</a>
22-
</li>
23-
{% endif %}
24-
</ul>
25-
{% endblock tabs %}
2612

2713
{% block content %}
2814
<div class="row mb-3">

netbox_bgp/templates/netbox_bgp/bgpsession.html

-14
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,6 @@
99
<li class="breadcrumb-item"><a href="{% url 'plugins:netbox_bgp:bgpsession_list' %}">BGP Sessions</a></li>
1010
{% endblock %}
1111

12-
{% block tabs %}
13-
<ul class="nav nav-tabs px-3">
14-
{% block tab_items %}
15-
<li class="nav-item" role="presentation">
16-
<a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">{{ object|meta:"verbose_name"|bettertitle }}</a>
17-
</li>
18-
{% endblock tab_items %}
19-
{% if perms.extras.view_objectchange %}
20-
<li role="presentation" class="nav-item">
21-
<a href="{% url 'plugins:netbox_bgp:bgpsession_changelog' pk=object.pk %}" class="nav-link{% if active_tab == 'changelog'%} active{% endif %}">Change Log</a>
22-
</li>
23-
{% endif %}
24-
</ul>
25-
{% endblock tabs %}
2612

2713
{% block content %}
2814
<div class="row mb-3">

netbox_bgp/templates/netbox_bgp/community.html

-14
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@
88
<li class="breadcrumb-item"><a href="{% url 'plugins:netbox_bgp:community_list' %}">Communities</a></li>
99
{% endblock %}
1010

11-
{% block tabs %}
12-
<ul class="nav nav-tabs px-3">
13-
{% block tab_items %}
14-
<li class="nav-item" role="presentation">
15-
<a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">{{ object|meta:"verbose_name"|bettertitle }}</a>
16-
</li>
17-
{% endblock tab_items %}
18-
{% if perms.extras.view_objectchange %}
19-
<li role="presentation" class="nav-item">
20-
<a href="{% url 'plugins:netbox_bgp:community_changelog' pk=object.pk %}" class="nav-link{% if active_tab == 'changelog'%} active{% endif %}">Change Log</a>
21-
</li>
22-
{% endif %}
23-
</ul>
24-
{% endblock tabs %}
2511

2612
{% block content %}
2713
<div class="row mb-3">

netbox_bgp/templates/netbox_bgp/communitylist.html

-14
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@
1717
{% endif %}
1818
</div>
1919
{% endblock extra_controls %}
20-
{% block tabs %}
21-
<ul class="nav nav-tabs px-3">
22-
{% block tab_items %}
23-
<li class="nav-item" role="presentation">
24-
<a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">{{ object|meta:"verbose_name"|bettertitle }}</a>
25-
</li>
26-
{% endblock tab_items %}
27-
{% if perms.extras.view_objectchange %}
28-
<li role="presentation" class="nav-item">
29-
<a href="{% url 'plugins:netbox_bgp:communitylist_changelog' pk=object.pk %}" class="nav-link{% if active_tab == 'changelog'%} active{% endif %}">Change Log</a>
30-
</li>
31-
{% endif %}
32-
</ul>
33-
{% endblock tabs %}
3420

3521
{% block content %}
3622
<div class="row mb-3">

netbox_bgp/templates/netbox_bgp/prefixlist.html

-14
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@
1717
{% endif %}
1818
</div>
1919
{% endblock extra_controls %}
20-
{% block tabs %}
21-
<ul class="nav nav-tabs px-3">
22-
{% block tab_items %}
23-
<li class="nav-item" role="presentation">
24-
<a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">{{ object|meta:"verbose_name"|bettertitle }}</a>
25-
</li>
26-
{% endblock tab_items %}
27-
{% if perms.extras.view_objectchange %}
28-
<li role="presentation" class="nav-item">
29-
<a href="{% url 'plugins:netbox_bgp:prefixlist_changelog' pk=object.pk %}" class="nav-link{% if active_tab == 'changelog'%} active{% endif %}">Change Log</a>
30-
</li>
31-
{% endif %}
32-
</ul>
33-
{% endblock tabs %}
3420

3521
{% block content %}
3622
<div class="row mb-3">

netbox_bgp/templates/netbox_bgp/routingpolicy.html

-14
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@
1717
{% endif %}
1818
</div>
1919
{% endblock extra_controls %}
20-
{% block tabs %}
21-
<ul class="nav nav-tabs px-3">
22-
{% block tab_items %}
23-
<li class="nav-item" role="presentation">
24-
<a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">{{ object|meta:"verbose_name"|bettertitle }}</a>
25-
</li>
26-
{% endblock tab_items %}
27-
{% if perms.extras.view_objectchange %}
28-
<li role="presentation" class="nav-item">
29-
<a href="{% url 'plugins:netbox_bgp:routingpolicy_changelog' pk=object.pk %}" class="nav-link{% if active_tab == 'changelog'%} active{% endif %}">Change Log</a>
30-
</li>
31-
{% endif %}
32-
</ul>
33-
{% endblock tabs %}
3420

3521
{% block content %}
3622
<div class="row mb-3">

netbox_bgp/urls.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
from django.urls import path
2-
from netbox.views.generic import ObjectChangeLogView
1+
from django.urls import include, path
2+
from utilities.urls import get_model_urls
3+
34
from .models import (
45
BGPSession, Community, RoutingPolicy,
56
BGPPeerGroup, RoutingPolicyRule, PrefixList,
67
PrefixListRule, CommunityList, CommunityListRule
78
)
8-
99
from . import views
1010

11+
app_name = 'netbox_bgp'
12+
1113
urlpatterns = [
1214
# Community
1315
path('community/', views.CommunityListView.as_view(), name='community_list'),
@@ -18,7 +20,7 @@
1820
path('community/<int:pk>/', views.CommunityView.as_view(), name='community'),
1921
path('community/<int:pk>/edit/', views.CommunityEditView.as_view(), name='community_edit'),
2022
path('community/<int:pk>/delete/', views.CommunityDeleteView.as_view(), name='community_delete'),
21-
path('community/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='community_changelog', kwargs={'model': Community}),
23+
path('community/<int:pk>/', include(get_model_urls('netbox_bgp', 'community'))),
2224
# Community Lists
2325
path('community-list/', views.CommunityListListView.as_view(), name='communitylist_list'),
2426
path('community-list/add/', views.CommunityListEditView.as_view(), name='communitylist_add'),
@@ -28,15 +30,15 @@
2830
path('community-list/<int:pk>/', views.CommListView.as_view(), name='communitylist'),
2931
path('community-list/<int:pk>/edit/', views.CommunityListEditView.as_view(), name='communitylist_edit'),
3032
path('community-list/<int:pk>/delete/', views.CommunityListDeleteView.as_view(), name='communitylist_delete'),
31-
path('community-list/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='communitylist_changelog', kwargs={'model': CommunityList}),
33+
path('community-list/<int:pk>/', include(get_model_urls('netbox_bgp', 'communitylist'))),
3234
# Community List Rules
3335
path('community-list-rule/', views.CommunityListRuleListView.as_view(), name='communitylistrule_list'),
3436
path('community-list-rule/add/', views.CommunityListRuleEditView.as_view(), name='communitylistrule_add'),
3537
path('community-list-rule/delete/', views.CommunityListRuleBulkDeleteView.as_view(), name='communitylistrule_bulk_delete'),
3638
path('community-list-rule/<int:pk>/', views.CommunityListRuleView.as_view(), name='communitylistrule'),
3739
path('community-list-rule/<int:pk>/edit/', views.CommunityListRuleEditView.as_view(), name='communitylistrule_edit'),
3840
path('community-list-rule/<int:pk>/delete/', views.CommunityListRuleDeleteView.as_view(), name='communitylistrule_delete'),
39-
path('community-list-rule/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='communitylistrule_changelog', kwargs={'model': CommunityListRule}),
41+
path('community-list-rule/<int:pk>/', include(get_model_urls('netbox_bgp', 'communitylistrule'))),
4042
# Sessions
4143
path('session/', views.BGPSessionListView.as_view(), name='bgpsession_list'),
4244
path('session/add/', views.BGPSessionAddView.as_view(), name='bgpsession_add'),
@@ -46,7 +48,7 @@
4648
path('session/<int:pk>/', views.BGPSessionView.as_view(), name='bgpsession'),
4749
path('session/<int:pk>/edit/', views.BGPSessionEditView.as_view(), name='bgpsession_edit'),
4850
path('session/<int:pk>/delete/', views.BGPSessionDeleteView.as_view(), name='bgpsession_delete'),
49-
path('session/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='bgpsession_changelog', kwargs={'model': BGPSession}),
51+
path('session/<int:pk>/', include(get_model_urls('netbox_bgp', 'bgpsession'))),
5052
# Routing Policies
5153
path('routing-policy/', views.RoutingPolicyListView.as_view(), name='routingpolicy_list'),
5254
path('routing-policy/add/', views.RoutingPolicyEditView.as_view(), name='routingpolicy_add'),
@@ -56,7 +58,7 @@
5658
path('routing-policy/<int:pk>/', views.RoutingPolicyView.as_view(), name='routingpolicy'),
5759
path('routing-policy/<int:pk>/edit/', views.RoutingPolicyEditView.as_view(), name='routingpolicy_edit'),
5860
path('routing-policy/<int:pk>/delete/', views.RoutingPolicyDeleteView.as_view(), name='routingpolicy_delete'),
59-
path('routing-policy/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='routingpolicy_changelog', kwargs={'model': RoutingPolicy}),
61+
path('routing-policy<int:pk>/', include(get_model_urls('netbox_bgp', 'routingpolicy'))),
6062
# Peer Groups
6163
path('peer-group/', views.BGPPeerGroupListView.as_view(), name='bgppeergroup_list'),
6264
path('peer-group/add/', views.BGPPeerGroupEditView.as_view(), name='bgppeergroup_add'),
@@ -66,15 +68,15 @@
6668
path('peer-group/<int:pk>/', views.BGPPeerGroupView.as_view(), name='bgppeergroup'),
6769
path('peer-group/<int:pk>/edit/', views.BGPPeerGroupEditView.as_view(), name='bgppeergroup_edit'),
6870
path('peer-group/<int:pk>/delete/', views.BGPPeerGroupDeleteView.as_view(), name='bgppeergroup_delete'),
69-
path('peer-group/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='bgppeergroup_changelog', kwargs={'model': BGPPeerGroup}),
71+
path('peer-group/<int:pk>/', include(get_model_urls('netbox_bgp', 'bgppeergroup'))),
7072
# Routing Policy Rules
7173
path('routing-policy-rule/', views.RoutingPolicyRuleListView.as_view(), name='routingpolicyrule_list'),
7274
path('routing-policy-rule/add/', views.RoutingPolicyRuleEditView.as_view(), name='routingpolicyrule_add'),
7375
path('routing-policy-rule/delete/', views.RoutingPolicyRuleBulkDeleteView.as_view(), name='routingpolicyrule_bulk_delete'),
7476
path('routing-policy-rule/<int:pk>/', views.RoutingPolicyRuleView.as_view(), name='routingpolicyrule'),
7577
path('routing-policy-rule/<int:pk>/edit/', views.RoutingPolicyRuleEditView.as_view(), name='routingpolicyrule_edit'),
7678
path('routing-policy-rule/<int:pk>/delete/', views.RoutingPolicyRuleDeleteView.as_view(), name='routingpolicyrule_delete'),
77-
path('routing-policy-rule/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='routingpolicyrule_changelog', kwargs={'model': RoutingPolicyRule}),
79+
path('routing-policy-rule/<int:pk>/', include(get_model_urls('netbox_bgp', 'routingpolicyrule'))),
7880
# Prefix Lists
7981
path('prefix-list/', views.PrefixListListView.as_view(), name='prefixlist_list'),
8082
path('prefix-list/add/', views.PrefixListEditView.as_view(), name='prefixlist_add'),
@@ -84,13 +86,13 @@
8486
path('prefix-list/<int:pk>/', views.PrefixListView.as_view(), name='prefixlist'),
8587
path('prefix-list/<int:pk>/edit/', views.PrefixListEditView.as_view(), name='prefixlist_edit'),
8688
path('prefix-list/<int:pk>/delete/', views.PrefixListDeleteView.as_view(), name='prefixlist_delete'),
87-
path('prefix-list/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='prefixlist_changelog', kwargs={'model': PrefixList}),
89+
path('prefix-list/<int:pk>/', include(get_model_urls('netbox_bgp', 'prefixlist'))),
8890
# Prefix List Rules
8991
path('prefix-list-rule/', views.PrefixListRuleListView.as_view(), name='prefixlistrule_list'),
9092
path('prefix-list-rule/add/', views.PrefixListRuleEditView.as_view(), name='prefixlistrule_add'),
9193
path('prefix-list-rule/delete/', views.PrefixListRuleBulkDeleteView.as_view(), name='prefixlistrule_bulk_delete'),
9294
path('prefix-list-rule/<int:pk>/', views.PrefixListRuleView.as_view(), name='prefixlistrule'),
9395
path('prefix-list-rule/<int:pk>/edit/', views.PrefixListRuleEditView.as_view(), name='prefixlistrule_edit'),
9496
path('prefix-list-rule/<int:pk>/delete/', views.PrefixListRuleDeleteView.as_view(), name='prefixlistrule_delete'),
95-
path('prefix-list-rule/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='prefixlistrule_changelog', kwargs={'model': PrefixListRule}),
97+
path('prefix-list-rule/<int:pk>/', include(get_model_urls('netbox_bgp', 'prefixlistrule'))),
9698
]

0 commit comments

Comments
 (0)