Skip to content

Commit 6b96fea

Browse files
committed
updated api, filterset and graphql by ownership_type, added method get color to ownership type
1 parent 7c4481d commit 6b96fea

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

cesnet_service_path_plugin/api/serializers/segment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Meta:
5555
"name",
5656
"segment_type",
5757
"status",
58+
"ownership_type",
5859
"network_label",
5960
"install_date",
6061
"termination_date",
@@ -82,6 +83,7 @@ class Meta:
8283
"name",
8384
"segment_type",
8485
"status",
86+
"ownership_type",
8587
"has_path_data",
8688
"tags",
8789
)
@@ -197,6 +199,7 @@ class Meta:
197199
"name",
198200
"segment_type",
199201
"status",
202+
"ownership_type",
200203
"network_label",
201204
"install_date",
202205
"termination_date",
@@ -225,6 +228,7 @@ class Meta:
225228
"name",
226229
"segment_type",
227230
"status",
231+
"ownership_type",
228232
"has_path_data",
229233
"tags",
230234
)

cesnet_service_path_plugin/filtersets/segment.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from netbox.filtersets import NetBoxModelFilterSet
99

1010
from cesnet_service_path_plugin.models import Segment
11-
from cesnet_service_path_plugin.models.custom_choices import StatusChoices
11+
from cesnet_service_path_plugin.models.custom_choices import StatusChoices, OwnershipTypeChoices
1212
from cesnet_service_path_plugin.models.segment_types import SegmentTypeChoices
1313

1414
logger = logging.getLogger(__name__)
@@ -23,6 +23,7 @@ class SegmentFilterSet(NetBoxModelFilterSet):
2323
name = django_filters.CharFilter(lookup_expr="icontains")
2424
network_label = django_filters.CharFilter(lookup_expr="icontains")
2525
status = django_filters.MultipleChoiceFilter(choices=StatusChoices, null_value=None)
26+
ownership_type = django_filters.MultipleChoiceFilter(choices=OwnershipTypeChoices, null_value=None)
2627

2728
# Basic segment type filter
2829
segment_type = django_filters.MultipleChoiceFilter(
@@ -521,6 +522,7 @@ def search(self, queryset, name, value):
521522
network_label = Q(network_label__icontains=value)
522523
provider_segment_id = Q(provider_segment_id__icontains=value)
523524
status = Q(status__iexact=value)
525+
ownership_type = Q(ownership_type__iexact=value)
524526
segment_type = Q(segment_type__iexact=value)
525527

526528
return queryset.filter(
@@ -532,5 +534,6 @@ def search(self, queryset, name, value):
532534
| network_label
533535
| provider_segment_id
534536
| status
537+
| ownership_type
535538
| segment_type
536539
)

cesnet_service_path_plugin/graphql/filters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class SegmentFilter(NetBoxModelFilterMixin):
3939
install_date: FilterLookup[str] | None = strawberry_django.filter_field() # Date fields as string
4040
termination_date: FilterLookup[str] | None = strawberry_django.filter_field()
4141
status: FilterLookup[str] | None = strawberry_django.filter_field()
42+
ownership_type: FilterLookup[str] | None = strawberry_django.filter_field()
4243
provider_segment_id: FilterLookup[str] | None = strawberry_django.filter_field()
4344
comments: FilterLookup[str] | None = strawberry_django.filter_field()
4445

cesnet_service_path_plugin/graphql/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class SegmentType(NetBoxObjectType):
8181
install_date: auto
8282
termination_date: auto
8383
status: auto
84+
ownership_type: auto
8485

8586
# Segment type fields
8687
segment_type: auto

cesnet_service_path_plugin/models/segment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ def save(self, *args, **kwargs):
178178
def get_status_color(self):
179179
return StatusChoices.colors.get(self.status, "gray")
180180

181+
def get_ownership_type_color(self):
182+
return OwnershipTypeChoices.colors.get(self.ownership_type, "gray")
183+
181184
def get_segment_type_color(self):
182185
"""Get color for segment type badge"""
183186
return SegmentTypeChoices.colors.get(self.segment_type, "gray")

0 commit comments

Comments
 (0)