Skip to content

Commit 281da71

Browse files
committed
Merge branch 'segment_status_extension' into 'main'
Segment status extension Closes #34 See merge request 701/netbox/cesnet_service_path_plugin!43
2 parents f3ddc8f + 05e616d commit 281da71

File tree

16 files changed

+192
-32
lines changed

16 files changed

+192
-32
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/forms/segment.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from utilities.forms.widgets.datetime import DatePicker
2323

2424
from cesnet_service_path_plugin.models import Segment
25-
from cesnet_service_path_plugin.models.custom_choices import StatusChoices
25+
from cesnet_service_path_plugin.models.custom_choices import StatusChoices, OwnershipTypeChoices
2626
from cesnet_service_path_plugin.models.segment_types import (
2727
SEGMENT_TYPE_SCHEMAS,
2828
SegmentTypeChoices,
@@ -38,6 +38,7 @@
3838
class SegmentForm(NetBoxModelForm):
3939
comments = CommentField(required=False, label="Comments", help_text="Comments")
4040
status = forms.ChoiceField(required=True, choices=StatusChoices, initial=None)
41+
ownership_type = forms.ChoiceField(required=True, choices=OwnershipTypeChoices, initial=None)
4142
provider_segment_id = forms.CharField(label=" ID", required=False, help_text="Provider Segment ID")
4243
provider = DynamicModelChoiceField(
4344
queryset=Provider.objects.all(),
@@ -369,6 +370,7 @@ class Meta:
369370
"name",
370371
"segment_type",
371372
"status",
373+
"ownership_type",
372374
"network_label",
373375
"install_date",
374376
"termination_date",
@@ -390,6 +392,7 @@ class Meta:
390392
"segment_type",
391393
"network_label",
392394
"status",
395+
"ownership_type",
393396
InlineFields("install_date", "termination_date", label="Dates"),
394397
name="Basic Information",
395398
),
@@ -432,6 +435,7 @@ class SegmentFilterForm(NetBoxModelFilterSetForm):
432435

433436
name = forms.CharField(required=False)
434437
status = forms.MultipleChoiceField(required=False, choices=StatusChoices, initial=None)
438+
ownership_type = forms.MultipleChoiceField(required=False, choices=OwnershipTypeChoices, initial=None)
435439
network_label = forms.CharField(required=False)
436440

437441
# Basic segment type filter
@@ -739,6 +743,12 @@ class SegmentBulkEditForm(NetBoxModelBulkEditForm):
739743
initial="",
740744
widget=forms.Select(attrs={"class": "form-control"}),
741745
)
746+
ownership_type = forms.ChoiceField(
747+
choices=add_blank_choice(OwnershipTypeChoices),
748+
required=False,
749+
initial="",
750+
widget=forms.Select(attrs={"class": "form-control"}),
751+
)
742752
provider = DynamicModelChoiceField(
743753
queryset=Provider.objects.all(),
744754
required=False,
@@ -752,5 +762,5 @@ class SegmentBulkEditForm(NetBoxModelBulkEditForm):
752762
comments = CommentField()
753763

754764
model = Segment
755-
fieldsets = (FieldSet("provider", "status", "segment_type", name="Segment"),)
765+
fieldsets = (FieldSet("provider", "status", "ownership_type", "segment_type", name="Segment"),)
756766
nullable_fields = ("comments",)

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
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.7 on 2025-11-12 12:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('cesnet_service_path_plugin', '0031_alter_segmentfinancialinfo_charge_currency'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='segment',
15+
name='ownership_type',
16+
field=models.CharField(default='leased', max_length=30),
17+
),
18+
]

cesnet_service_path_plugin/models/custom_choices.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,37 @@ class StatusChoices(ChoiceSet):
77
ACTIVE = "active"
88
PLANNED = "planned"
99
OFFLINE = "offline"
10+
DECOMMISSIONED = "decommissioned"
11+
SURVEYED = "surveyed"
1012

1113
CHOICES = [
1214
(ACTIVE, "Active", "green"),
1315
(PLANNED, "Planned", "orange"),
1416
(OFFLINE, "Offline", "red"),
17+
(DECOMMISSIONED, "Decommissioned", "gray"),
18+
(SURVEYED, "Surveyed", "blue"),
19+
]
20+
21+
22+
class OwnershipTypeChoices(ChoiceSet):
23+
"""
24+
owned
25+
leased
26+
shared
27+
foreign
28+
"""
29+
30+
key = "cesnet_service_path_plugin.choices.ownership_type"
31+
OWNED = "owned"
32+
LEASED = "leased"
33+
SHARED = "shared"
34+
FOREIGN = "foreign"
35+
36+
CHOICES = [
37+
(OWNED, "Owned", "green"),
38+
(LEASED, "Leased", "blue"),
39+
(SHARED, "Shared", "yellow"),
40+
(FOREIGN, "Foreign", "red"),
1541
]
1642

1743

cesnet_service_path_plugin/models/segment.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.utils import timezone
77
from netbox.models import NetBoxModel
88

9-
from cesnet_service_path_plugin.models.custom_choices import StatusChoices
9+
from cesnet_service_path_plugin.models.custom_choices import StatusChoices, OwnershipTypeChoices
1010
from cesnet_service_path_plugin.models.segment_types import (
1111
SEGMENT_TYPE_SCHEMAS,
1212
SegmentTypeChoices,
@@ -27,6 +27,14 @@ class Segment(NetBoxModel):
2727
null=False,
2828
)
2929

30+
ownership_type = models.CharField(
31+
max_length=30,
32+
choices=OwnershipTypeChoices,
33+
default=OwnershipTypeChoices.LEASED,
34+
blank=False,
35+
null=False,
36+
)
37+
3038
# New segment type field
3139
segment_type = models.CharField(
3240
max_length=30,
@@ -170,6 +178,9 @@ def save(self, *args, **kwargs):
170178
def get_status_color(self):
171179
return StatusChoices.colors.get(self.status, "gray")
172180

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

cesnet_service_path_plugin/tables/segment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class SegmentTable(NetBoxTable):
88
tags = columns.TagColumn()
99
name = tables.Column(linkify=True)
1010
status = ChoiceFieldColumn()
11+
ownership_type = ChoiceFieldColumn()
1112
segment_type = ChoiceFieldColumn()
1213
provider = tables.Column(linkify=True)
1314
site_a = tables.Column(linkify=True)
@@ -64,6 +65,7 @@ class Meta(NetBoxTable.Meta):
6465
"tags",
6566
"actions",
6667
"status",
68+
"ownership_type",
6769
"date_status",
6870
)
6971

@@ -78,5 +80,6 @@ class Meta(NetBoxTable.Meta):
7880
"location_b",
7981
"has_path_data", # Added to default view
8082
"status",
83+
"ownership_type",
8184
"date_status",
8285
)

cesnet_service_path_plugin/templates/cesnet_service_path_plugin/inc/map_status_colors.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)