Skip to content

Commit

Permalink
Merge pull request #28 from knobix/fix-runtime-with-netbox-3.3-and-later
Browse files Browse the repository at this point in the history
Fix runtime with NetBox 3.3 and later
  • Loading branch information
iDebugAll committed Apr 18, 2023
2 parents f326a55 + ece8fad commit e6ba932
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 3 deletions.
8 changes: 7 additions & 1 deletion phonebox_plugin/api/nested_serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from rest_framework import serializers
from phonebox_plugin import models
from netbox.api import WritableNestedSerializer

try:
from netbox.api import ChoiceField, WritableNestedSerializer
except ImportError:
from netbox.api.fields import ChoiceField
from netbox.api.serializers.nested import WritableNestedSerializer

from tenancy.api.nested_serializers import NestedTenantSerializer

__all__ = ["NestedNumberSerializer", ]
Expand Down
62 changes: 62 additions & 0 deletions phonebox_plugin/templates/phonebox_plugin/list_view_3.4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{% extends 'base/layout.html' %}
{% load buttons %}
{% load static %}
{% load plugins %}
{% load helpers %}


{% block controls %}

<div class="pull-right noprint">
{% if perms.phonebox_plugin.add_number %}
<a href="/plugins/phonebox/add_number/" type="button" class="btn btn-sm btn-success">
<i class="mdi mdi-plus-thick"></i> Add
</a>
{% endif %}
{% if perms.phonebox_plugin.add_number %}
<a href="/plugins/phonebox/import_numbers/" type="button" class="btn btn-sm btn-info">
<i class="mdi mdi-upload"></i> Import
</a>
{% endif %}
</div>

{% endblock %}


{% block content %}

<ul class="nav nav-tabs px-3">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="numbers-tab" data-bs-toggle="tab" data-bs-target="#numbers" type="button" role="tab" aria-controls="numbers" aria-selected="true">
Numbers
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="filters-form-tab" data-bs-toggle="tab" data-bs-target="#filters-form" type="button" role="tab" aria-controls="filters-form" aria-selected="false">
Filters
{% if filter_form %}{% badge filter_form.changed_data|length %}{% endif %}
</button>
</li>
</ul>

<div class="tab-content">
<div class="tab-pane active" id="numbers" role="tabpanel" aria-labelledby="numbers-tab">

{# Applied filters #}
{% if filter_form %}
{% applied_filters model filter_form request.GET %}
{% endif %}

<h2>{% block title %}Numbers{% endblock %}</h2>
<div class="row">
<div class="col-md-12">
{% include 'phonebox_plugin/obj_table.html' with bulk_delete_url="plugins:phonebox_plugin:number_bulk_delete" bulk_edit_url="plugins:phonebox_plugin:number_bulk_edit" %}
</div>
</div>
</div>
<div class="tab-pane" id="filters-form" role="tabpanel" aria-labelledby="filters-form-tab">
{% include 'inc/filter_list.html' %}
</div>
</div>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{% extends 'base/layout.html' %}
{% load buttons %}
{% load static %}
{% load plugins %}
{% load helpers %}


{% block controls %}

<div class="pull-right noprint">
{% if perms.phonebox_plugin.add_voice_circuit %}
<a href="{% url 'plugins:phonebox_plugin:add_voice_circuit' %}" type="button" class="btn btn-sm btn-success">
<i class="mdi mdi-plus-thick"></i> Add
</a>
{% endif %}
{% if perms.phonebox_plugin.add_voice_circuit %}
<a href="{% url 'plugins:phonebox_plugin:import_voice_circuits' %}" type="button" class="btn btn-sm btn-info">
<i class="mdi mdi-upload"></i> Import
</a>
{% endif %}
</div>

{% endblock %}


{% block content %}

<ul class="nav nav-tabs px-3">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="voice_circuits-tab" data-bs-toggle="tab" data-bs-target="#voice_circuits" type="button" role="tab" aria-controls="voice_circuits" aria-selected="true">
Voice Circuits
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="filters-form-tab" data-bs-toggle="tab" data-bs-target="#filters-form" type="button" role="tab" aria-controls="filters-form" aria-selected="false">
Filters
{% if filter_form %}{% badge filter_form.changed_data|length %}{% endif %}
</button>
</li>
</ul>

<div class="tab-content">
<div class="tab-pane active" id="voice_circuits" role="tabpanel" aria-labelledby="voice_circuits-tab">

{# Applied filters #}
{% if filter_form %}
{% applied_filters model filter_form request.GET %}
{% endif %}

<h2>{% block title %}Voice Circuits{% endblock %}</h2>
<div class="row">
<div class="col-md-12">
{% include 'phonebox_plugin/obj_table.html' with bulk_delete_url="plugins:phonebox_plugin:voice_circuit_bulk_delete" bulk_edit_url="plugins:phonebox_plugin:voice_circuit_bulk_edit" %}
</div>
</div>
</div>
<div class="tab-pane" id="filters-form" role="tabpanel" aria-labelledby="filters-form-tab">
{% include 'inc/filter_list.html' %}
</div>
</div>

{% endblock %}
8 changes: 6 additions & 2 deletions phonebox_plugin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class NumberListView(generic.ObjectListView):
filterset = filters.NumberFilterSet
filterset_form = forms.NumberFilterForm
table = tables.NumberTable
if NETBOX_CURRENT_VERSION >= version.parse("3.0"):
if NETBOX_CURRENT_VERSION >= version.parse("3.0") and NETBOX_CURRENT_VERSION < version.parse("3.4"):
template_name = "phonebox_plugin/list_view_3.x.html"
elif NETBOX_CURRENT_VERSION >= version.parse("3.4"):
template_name = "phonebox_plugin/list_view_3.4.html"
else:
template_name = "phonebox_plugin/list_view.html"

Expand Down Expand Up @@ -76,8 +78,10 @@ class VoiceCircuitListView(generic.ObjectListView):
filterset = filters.VoiceCircuitFilterSet
filterset_form = forms.VoiceCircuitFilterForm
table = tables.VoiceCircuitTable
if NETBOX_CURRENT_VERSION >= version.parse("3.0"):
if NETBOX_CURRENT_VERSION >= version.parse("3.0") and NETBOX_CURRENT_VERSION < version.parse("3.4"):
template_name = "phonebox_plugin/voice_circuit_list_view_3.x.html"
elif NETBOX_CURRENT_VERSION >= version.parse("3.4"):
template_name = "phonebox_plugin/voice_circuit_list_view_3.4.html"
else:
template_name = "phonebox_plugin/voice_circuit_list_view.html"

Expand Down

0 comments on commit e6ba932

Please sign in to comment.