Closes #19002: Module type profiles (#19014)

* Move Module & ModuleType models to a separate file

* Add ModuleTypeProfile & related fields

* Initial work on JSON schema validation

* Add attributes property on ModuleType

* Introduce MultipleOfValidator

* Introduce JSONSchemaProperty

* Enable dynamic form field rendering

* Misc cleanup

* Fix migration conflict

* Ensure deterministic ordering of attriubte fields

* Support choices & default values

* Include module type attributes on module view

* Enable modifying individual attributes via REST API

* Enable filtering by attribute values

* Add documentation & tests

* Schema should be optional

* Include attributes column for profiles

* Profile is nullable

* Include some initial profiles to be installed via migration

* Fix migrations conflict

* Fix filterset test

* Misc cleanup

* Fixes #19023: get_field_value() should respect null values in bound forms (#19024)

* Skip filters which do not specify a JSON-serializable value

* Fix handling of array item types

* Fix initial data in schema field during bulk edit

* Implement sanity checking for JSON schema definitions

* Fall back to filtering by string value
This commit is contained in:
Jeremy Stretch
2025-04-01 13:05:06 -04:00
committed by GitHub
parent 864db469ba
commit 8d7889e2c0
47 changed files with 1732 additions and 321 deletions

View File

@@ -68,6 +68,7 @@ __all__ = (
'ModuleBayFilter',
'ModuleBayTemplateFilter',
'ModuleTypeFilter',
'ModuleTypeProfileFilter',
'PlatformFilter',
'PowerFeedFilter',
'PowerOutletFilter',
@@ -559,6 +560,11 @@ class ModuleBayTemplateFilter(ModularComponentTemplateFilterMixin):
position: FilterLookup[str] | None = strawberry_django.filter_field()
@strawberry_django.filter(models.ModuleTypeProfile, lookups=True)
class ModuleTypeProfileFilter(PrimaryModelFilterMixin):
name: FilterLookup[str] | None = strawberry_django.filter_field()
@strawberry_django.filter(models.ModuleType, lookups=True)
class ModuleTypeFilter(ImageAttachmentFilterMixin, PrimaryModelFilterMixin, WeightFilterMixin):
manufacturer: Annotated['ManufacturerFilter', strawberry.lazy('dcim.graphql.filters')] | None = (

View File

@@ -77,6 +77,9 @@ class DCIMQuery:
module_bay_template: ModuleBayTemplateType = strawberry_django.field()
module_bay_template_list: List[ModuleBayTemplateType] = strawberry_django.field()
module_type_profile: ModuleTypeProfileType = strawberry_django.field()
module_type_profile_list: List[ModuleTypeProfileType] = strawberry_django.field()
module_type: ModuleTypeType = strawberry_django.field()
module_type_list: List[ModuleTypeType] = strawberry_django.field()

View File

@@ -61,6 +61,7 @@ __all__ = (
'ModuleType',
'ModuleBayType',
'ModuleBayTemplateType',
'ModuleTypeProfileType',
'ModuleTypeType',
'PlatformType',
'PowerFeedType',
@@ -593,6 +594,16 @@ class ModuleBayTemplateType(ModularComponentTemplateType):
pass
@strawberry_django.type(
models.ModuleTypeProfile,
fields='__all__',
filters=ModuleTypeProfileFilter,
pagination=True
)
class ModuleTypeProfileType(NetBoxObjectType):
module_types: List[Annotated["ModuleType", strawberry.lazy('dcim.graphql.types')]]
@strawberry_django.type(
models.ModuleType,
fields='__all__',
@@ -600,6 +611,7 @@ class ModuleBayTemplateType(ModularComponentTemplateType):
pagination=True
)
class ModuleTypeType(NetBoxObjectType):
profile: Annotated["ModuleTypeProfileType", strawberry.lazy('dcim.graphql.types')] | None
manufacturer: Annotated["ManufacturerType", strawberry.lazy('dcim.graphql.types')]
frontporttemplates: List[Annotated["FrontPortTemplateType", strawberry.lazy('dcim.graphql.types')]]