|
1 | | -# 1. First, let's update your types.py to ensure it's importing correctly |
2 | | -# cesnet_service_path_plugin/graphql/types.py |
3 | | - |
4 | 1 | from typing import Annotated, List, Optional |
5 | 2 |
|
6 | 3 | from circuits.graphql.types import CircuitType, ProviderType |
@@ -45,6 +42,11 @@ class SegmentType(NetBoxObjectType): |
45 | 42 | install_date: auto |
46 | 43 | termination_date: auto |
47 | 44 | status: auto |
| 45 | + |
| 46 | + # Segment type fields |
| 47 | + segment_type: auto |
| 48 | + type_specific_data: auto |
| 49 | + |
48 | 50 | provider: Annotated["ProviderType", lazy("circuits.graphql.types")] | None |
49 | 51 | provider_segment_id: auto |
50 | 52 | provider_segment_name: auto |
@@ -72,6 +74,36 @@ def has_path_data(self) -> bool: |
72 | 74 | # Fallback: check if path_geometry field has data |
73 | 75 | return bool(self.path_geometry) |
74 | 76 |
|
| 77 | + @field |
| 78 | + def segment_type_display(self) -> Optional[str]: |
| 79 | + """Display name for segment type""" |
| 80 | + if hasattr(self, "get_segment_type_display"): |
| 81 | + return self.get_segment_type_display() |
| 82 | + return None |
| 83 | + |
| 84 | + @field |
| 85 | + def type_specific_display(self) -> Optional[strawberry.scalars.JSON]: |
| 86 | + """Formatted display of type-specific data""" |
| 87 | + if hasattr(self, "get_type_specific_display"): |
| 88 | + return self.get_type_specific_display() |
| 89 | + return None |
| 90 | + |
| 91 | + @field |
| 92 | + def type_specific_schema(self) -> Optional[strawberry.scalars.JSON]: |
| 93 | + """Schema for the segment's type""" |
| 94 | + from cesnet_service_path_plugin.models.segment_types import SEGMENT_TYPE_SCHEMAS |
| 95 | + |
| 96 | + if self.segment_type: |
| 97 | + return SEGMENT_TYPE_SCHEMAS.get(self.segment_type, {}) |
| 98 | + return None |
| 99 | + |
| 100 | + @field |
| 101 | + def has_type_specific_data(self) -> bool: |
| 102 | + """Whether this segment has type-specific data""" |
| 103 | + if hasattr(self, "has_type_specific_data"): |
| 104 | + return self.has_type_specific_data() |
| 105 | + return bool(self.type_specific_data) |
| 106 | + |
75 | 107 | @field |
76 | 108 | def path_geometry_geojson(self) -> Optional[strawberry.scalars.JSON]: |
77 | 109 | """Path geometry as GeoJSON Feature""" |
|
0 commit comments