Misc cleanup

This commit is contained in:
Jeremy Stretch 2025-03-26 15:50:14 -04:00
parent 5f707320ea
commit ad9c5ca419
5 changed files with 21 additions and 7 deletions

View File

@ -100,7 +100,7 @@ class ModuleTypeSerializer(NetBoxModelSerializer):
model = ModuleType
fields = [
'id', 'url', 'display_url', 'display', 'profile', 'manufacturer', 'model', 'part_number', 'airflow',
'weight', 'weight_unit', 'description', 'attributes', 'comments', 'tags', 'custom_fields', 'created',
'weight', 'weight_unit', 'description', 'attribute_data', 'comments', 'tags', 'custom_fields', 'created',
'last_updated',
]
brief_fields = ('id', 'url', 'display', 'profile', 'manufacturer', 'model', 'description')

View File

@ -408,7 +408,8 @@ class DeviceTypeForm(NetBoxModelForm):
class ModuleTypeProfileForm(NetBoxModelForm):
schema = JSONField(
label=_('Schema')
label=_('Schema'),
help_text=_("Enter a valid JSON schema to define supported attributes.")
)
comments = CommentField()

View File

@ -13,6 +13,7 @@ from extras.models import ConfigContextModel, CustomField
from netbox.models import PrimaryModel
from netbox.models.features import ImageAttachmentsMixin
from netbox.models.mixins import WeightMixin
from utilities.string import title
from .device_components import *
__all__ = (
@ -131,7 +132,7 @@ class ModuleType(ImageAttachmentsMixin, PrimaryModel, WeightMixin):
return {}
attrs = {}
for name, options in self.profile.schema.get('properties', {}).items():
key = options.get('title', name)
key = options.get('title', title(name))
attrs[key] = self.attribute_data.get(name)
return dict(sorted(attrs.items()))

View File

@ -1486,7 +1486,7 @@ class DeviceTypeTestCase(TestCase, ChangeLoggedFilterSetTests):
class ModuleTypeTestCase(TestCase, ChangeLoggedFilterSetTests):
queryset = ModuleType.objects.all()
filterset = ModuleTypeFilterSet
ignore_fields = ['attributes']
ignore_fields = ['attribute_data']
@classmethod
def setUpTestData(cls):

View File

@ -7,7 +7,7 @@
{% block title %}{{ object.name }}{% endblock %}
{% block content %}
<div class="row">
<div class="row mb-3">
<div class="col col-md-6">
<div class="card">
<h2 class="card-header">{% trans "Module Type Profile" %}</h2>
@ -34,13 +34,25 @@
</h2>
<pre id="profile_schema">{{ object.schema|json }}</pre>
</div>
{% include 'inc/panels/related_objects.html' %}
{% include 'inc/panels/custom_fields.html' %}
{% plugin_right_page object %}
</div>
</div>
<div class="row">
<div class="row mb-3">
<div class="col col-md-12">
<div class="card">
<h2 class="card-header">
{% trans "Module Types" %}
{% if perms.dcim.add_moduletype %}
<div class="card-actions">
<a href="{% url 'dcim:moduletype_add' %}?profile={{ object.pk }}" class="btn btn-ghost-primary btn-sm">
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> {% trans "Add Module Type" %}
</a>
</div>
{% endif %}
</h2>
{% htmx_table 'dcim:moduletype_list' profile_id=object.pk %}
</div>
{% plugin_full_width_page object %}
</div>
</div>