Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBX add (numbers changed) #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions phonebox_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PhoneBoxConfig(PluginConfig):
name = 'phonebox_plugin'
verbose_name = 'PhoneBox Plugin'
description = 'Telephone Number Management Plugin for NetBox.'
version = 'v0.0.4-beta.1'
version = 'v0.0.6-beta.1'
author = 'Igor Korotchenkov'
author_email = '[email protected]'
base_url = 'phonebox'
Expand All @@ -16,4 +16,4 @@ class PhoneBoxConfig(PluginConfig):
'*': None
}

config = PhoneBoxConfig
config = PhoneBoxConfig
2 changes: 1 addition & 1 deletion phonebox_plugin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

@admin.register(Number)
class NumPlanAdmin(admin.ModelAdmin):
list_display = ("number", "tenant", "description", "provider", "forward_to")
list_display = ('number', 'fio', 'pbx', 'tenant', 'region', 'site', 'provider')
2 changes: 1 addition & 1 deletion phonebox_plugin/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""REST API for PhoneBox Plugin"""
"""REST API for PhoneBox Plugin"""
4 changes: 1 addition & 3 deletions phonebox_plugin/api/nested_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ class NestedNumberSerializer(WritableNestedSerializer):

class Meta:
model = models.Number
fields = [
"id", "label", "number", "tenant",
]
fields = ["id", "label", "number", "tenant"]
2 changes: 1 addition & 1 deletion phonebox_plugin/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class Meta:
model = Number
fields = [
"id", "label", "number", "tenant", "region", "forward_to", "description", "provider", "tags",
]
]
3 changes: 1 addition & 2 deletions phonebox_plugin/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from rest_framework.routers import DefaultRouter
from . import views


router = DefaultRouter()
router.APIRootView = views.PhoneBoxPluginRootView

router.register(r'numbers', views.NumberViewSet)

app_name = "phonebox_plugin-api"
urlpatterns = router.urls
urlpatterns = router.urls
2 changes: 1 addition & 1 deletion phonebox_plugin/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def get_view_name(self):
class NumberViewSet(ModelViewSet):
queryset = Number.objects.prefetch_related('tenant', 'region', 'tags')
serializer_class = serializers.NumberSerializer
filterset_class = filters.NumberFilterSet
filterset_class = filters.NumberFilterSet
18 changes: 18 additions & 0 deletions phonebox_plugin/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,26 @@ class VoiceCircuitTypeChoices(ChoiceSet):
(ANALOG_VOICE_CIRCUIT, 'Analog Voice Circuit'),
)

class PBXTypeChoices(ChoiceSet):
VOIP_PBX = 'voip_pbx'
DIGITAL_PBX = 'digital_pbx'
ANALOG_PBX = 'analog_pbx'
CHOICES = (
(VOIP_PBX, 'VoIP PBX'),
(DIGITAL_PBX, 'Digital PBX'),
(ANALOG_PBX, 'Analog PBX'),
)

VOICE_CIRCUIT_ASSIGNMENT_MODELS = Q(
Q(app_label='dcim', model='interface') |
Q(app_label='virtualization', model='vminterface')
)

PBX_ASSIGNMENT_MODELS = Q(
Q(app_label='dcim', model='interface') |
Q(app_label='virtualization', model='vminterface')
)

NUMBER_ASSIGNMENT_MODELS = Q(
Q(app_label='dcim', model='interface')
)
63 changes: 47 additions & 16 deletions phonebox_plugin/filters.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import django_filters
from django.db.models import Q
from circuits.models import Provider
from dcim.models import Region, Site
from tenancy.models import Tenant
from .models import Number, VoiceCircuit
from packaging import version
from django.conf import settings
from circuits.models import Provider
from dcim.models import Region, Site, Location, Device
from tenancy.models import Tenant
from .models import Number, VoiceCircuit, PBX
from packaging import version
from django.conf import settings

NETBOX_CURRENT_VERSION = version.parse(settings.VERSION)

Expand All @@ -14,7 +14,7 @@
from utilities.filters import TagFilter
else:
from netbox.filtersets import BaseFilterSet
from extras.filters import TagFilter
from extras.filters import TagFilter


class NumberFilterSet(BaseFilterSet):
Expand All @@ -29,12 +29,12 @@ class NumberFilterSet(BaseFilterSet):
to_field_name='number',
label='number',
)
tenant = django_filters.ModelMultipleChoiceFilter(
queryset=Tenant.objects.all(),
field_name='tenant__id',
to_field_name='id',
label='Tenant (id)',
)
# tenant = django_filters.ModelMultipleChoiceFilter(
# queryset=Tenant.objects.all(),
# field_name='tenant__id',
# to_field_name='id',
# label='Tenant (id)',
# )
region = django_filters.ModelMultipleChoiceFilter(
queryset=Region.objects.all(),
field_name='region__id',
Expand All @@ -45,13 +45,13 @@ class NumberFilterSet(BaseFilterSet):
queryset=Provider.objects.all(),
field_name='provider__id',
to_field_name='id',
label='Region (id)',
label='Provider (id)',
)
forward_to = django_filters.ModelMultipleChoiceFilter(
field_name='forward_to',
queryset=Number.objects.all(),
to_field_name='number',
label='forward_to',
label='Forward_to',
)
tag = TagFilter()

Expand All @@ -77,7 +77,7 @@ class VoiceCircuitFilterSet(BaseFilterSet):
field_name='name',
queryset=VoiceCircuit.objects.all(),
to_field_name='name',
label='name',
label='Name',
)
tenant = django_filters.ModelMultipleChoiceFilter(
queryset=Tenant.objects.all(),
Expand Down Expand Up @@ -115,3 +115,34 @@ def search(self, queryset, name, value):
return queryset.filter(
Q(name__icontains=value)
)

class PbxTelephonyFilterSet(BaseFilterSet):

q = django_filters.CharFilter(
method='search',
label='Search',
)
name = django_filters.ModelMultipleChoiceFilter(
field_name='name',
queryset=PBX.objects.all(),
to_field_name='name',
label='Name',
)
region = django_filters.ModelMultipleChoiceFilter(
queryset=Region.objects.all(),
field_name='region__id',
to_field_name='id',
label='Region (id)',
)
tag = TagFilter()

class Meta():
model = PBX
fields = ('name',)

def search(self, queryset, name, value):
if not value.strip():
return queryset
return queryset.filter(
Q(name__icontains=value)
)
Loading