Coverage for dcim/graphql/filter_mixins.py: 93%
85 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
1from dataclasses import dataclass
2from typing import TYPE_CHECKING, Annotated
4import strawberry
5import strawberry_django
6from strawberry import ID
7from strawberry_django import BaseFilterLookup, FilterLookup, StrFilterLookup
9from core.graphql.filters import ContentTypeFilter
11from .enums import *
13if TYPE_CHECKING: 13 ↛ 14line 13 didn't jump to line 14 because the condition on line 13 was never true
14 from dcim.graphql.filters import LocationFilter, RegionFilter, SiteFilter, SiteGroupFilter
15 from extras.graphql.filters import ConfigTemplateFilter
16 from ipam.graphql.filters import VLANFilter, VLANTranslationPolicyFilter
17 from netbox.graphql.filter_lookups import FloatLookup, IntegerLookup
19 from .filters import *
21__all__ = (
22 'CabledObjectModelFilterMixin',
23 'ComponentModelFilterMixin',
24 'ComponentTemplateFilterMixin',
25 'InterfaceBaseFilterMixin',
26 'ModularComponentFilterMixin',
27 'ModularComponentTemplateFilterMixin',
28 'RackFilterMixin',
29 'RenderConfigFilterMixin',
30 'ScopedFilterMixin',
31)
34@dataclass
35class ScopedFilterMixin:
36 scope_type: Annotated['ContentTypeFilter', strawberry.lazy('core.graphql.filters')] | None = (
37 strawberry_django.filter_field()
38 )
39 scope_id: ID | None = strawberry_django.filter_field()
41 # Cached relations
42 _location: Annotated['LocationFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
43 strawberry_django.filter_field(name='location')
44 )
45 _region: Annotated['RegionFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
46 strawberry_django.filter_field(name='region')
47 )
48 _site_group: Annotated['SiteGroupFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
49 strawberry_django.filter_field(name='site_group')
50 )
51 _site: Annotated['SiteFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
52 strawberry_django.filter_field(name='site')
53 )
56@dataclass
57class ComponentModelFilterMixin:
58 _site: Annotated['SiteFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
59 strawberry_django.filter_field(name='site')
60 )
61 _location: Annotated['LocationFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
62 strawberry_django.filter_field(name='location')
63 )
64 _rack: Annotated['RackFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
65 strawberry_django.filter_field(name='rack')
66 )
67 device: Annotated['DeviceFilter', strawberry.lazy('dcim.graphql.filters')] | None = strawberry_django.filter_field()
68 device_id: ID | None = strawberry_django.filter_field()
69 name: StrFilterLookup | None = strawberry_django.filter_field()
70 label: StrFilterLookup | None = strawberry_django.filter_field()
71 description: StrFilterLookup | None = strawberry_django.filter_field()
74@dataclass
75class ModularComponentFilterMixin(ComponentModelFilterMixin):
76 module: Annotated['ModuleFilter', strawberry.lazy('dcim.graphql.filters')] | None = strawberry_django.filter_field()
77 module_id: ID | None = strawberry_django.filter_field()
78 inventory_items: Annotated['InventoryItemFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
79 strawberry_django.filter_field()
80 )
83@dataclass
84class CabledObjectModelFilterMixin:
85 cable: Annotated['CableFilter', strawberry.lazy('dcim.graphql.filters')] | None = strawberry_django.filter_field()
86 cable_id: ID | None = strawberry_django.filter_field()
87 cable_end: (
88 BaseFilterLookup[Annotated['CableEndEnum', strawberry.lazy('dcim.graphql.enums')]] | None
89 ) = strawberry_django.filter_field()
90 mark_connected: FilterLookup[bool] | None = strawberry_django.filter_field()
93@dataclass
94class ComponentTemplateFilterMixin:
95 device_type: Annotated['DeviceTypeFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
96 strawberry_django.filter_field()
97 )
98 device_type_id: ID | None = strawberry_django.filter_field()
99 name: StrFilterLookup | None = strawberry_django.filter_field()
100 label: StrFilterLookup | None = strawberry_django.filter_field()
101 description: StrFilterLookup | None = strawberry_django.filter_field()
104@dataclass
105class ModularComponentTemplateFilterMixin(ComponentTemplateFilterMixin):
106 module_type: Annotated['ModuleTypeFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
107 strawberry_django.filter_field()
108 )
111@dataclass
112class RenderConfigFilterMixin:
113 config_template: Annotated['ConfigTemplateFilter', strawberry.lazy('extras.graphql.filters')] | None = (
114 strawberry_django.filter_field()
115 )
116 config_template_id: ID | None = strawberry_django.filter_field()
119@dataclass
120class InterfaceBaseFilterMixin:
121 enabled: FilterLookup[bool] | None = strawberry_django.filter_field()
122 mtu: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
123 strawberry_django.filter_field()
124 )
125 mode: (
126 BaseFilterLookup[Annotated['InterfaceModeEnum', strawberry.lazy('dcim.graphql.enums')]] | None
127 ) = strawberry_django.filter_field()
128 bridge: Annotated['InterfaceFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
129 strawberry_django.filter_field()
130 )
131 bridge_id: ID | None = strawberry_django.filter_field()
132 untagged_vlan: Annotated['VLANFilter', strawberry.lazy('ipam.graphql.filters')] | None = (
133 strawberry_django.filter_field()
134 )
135 tagged_vlans: Annotated['VLANFilter', strawberry.lazy('ipam.graphql.filters')] | None = (
136 strawberry_django.filter_field()
137 )
138 qinq_svlan: Annotated['VLANFilter', strawberry.lazy('ipam.graphql.filters')] | None = (
139 strawberry_django.filter_field()
140 )
141 vlan_translation_policy: (
142 Annotated['VLANTranslationPolicyFilter', strawberry.lazy('ipam.graphql.filters')] | None
143 ) = strawberry_django.filter_field()
144 primary_mac_address: Annotated['MACAddressFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
145 strawberry_django.filter_field()
146 )
147 primary_mac_address_id: ID | None = strawberry_django.filter_field()
150@dataclass
151class RackFilterMixin:
152 width: BaseFilterLookup[Annotated['RackWidthEnum', strawberry.lazy('dcim.graphql.enums')]] | None = (
153 strawberry_django.filter_field()
154 )
155 u_height: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
156 strawberry_django.filter_field()
157 )
158 starting_unit: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
159 strawberry_django.filter_field()
160 )
161 desc_units: FilterLookup[bool] | None = strawberry_django.filter_field()
162 outer_width: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
163 strawberry_django.filter_field()
164 )
165 outer_height: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
166 strawberry_django.filter_field()
167 )
168 outer_depth: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
169 strawberry_django.filter_field()
170 )
171 outer_unit: BaseFilterLookup[Annotated['RackDimensionUnitEnum', strawberry.lazy('dcim.graphql.enums')]] | None = (
172 strawberry_django.filter_field()
173 )
174 mounting_depth: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
175 strawberry_django.filter_field()
176 )
177 max_weight: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
178 strawberry_django.filter_field()
179 )
180 cooling_capability: (
181 BaseFilterLookup[Annotated['RackCoolingCapabilityEnum', strawberry.lazy('dcim.graphql.enums')]] | None
182 ) = strawberry_django.filter_field()
183 cooling_capacity: Annotated['FloatLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
184 strawberry_django.filter_field()
185 )