mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Fixes #9829: Arrange custom fields by group when editing objects
This commit is contained in:
parent
d442f8fd60
commit
466931d2fb
@ -105,6 +105,7 @@ Custom field UI visibility has no impact on API operation.
|
|||||||
* [#9765](https://github.com/netbox-community/netbox/issues/9765) - Report correct segment count under cable trace UI view
|
* [#9765](https://github.com/netbox-community/netbox/issues/9765) - Report correct segment count under cable trace UI view
|
||||||
* [#9794](https://github.com/netbox-community/netbox/issues/9794) - Fix link to connect a rear port to a circuit termination
|
* [#9794](https://github.com/netbox-community/netbox/issues/9794) - Fix link to connect a rear port to a circuit termination
|
||||||
* [#9818](https://github.com/netbox-community/netbox/issues/9818) - Fix circuit side selection when connecting a cable to a circuit termination
|
* [#9818](https://github.com/netbox-community/netbox/issues/9818) - Fix circuit side selection when connecting a cable to a circuit termination
|
||||||
|
* [#9829](https://github.com/netbox-community/netbox/issues/9829) - Arrange custom fields by group when editing objects
|
||||||
* [#9843](https://github.com/netbox-community/netbox/issues/9843) - Fix rendering of custom field values (regression from #9647)
|
* [#9843](https://github.com/netbox-community/netbox/issues/9843) - Fix rendering of custom field values (regression from #9647)
|
||||||
* [#9844](https://github.com/netbox-community/netbox/issues/9844) - Fix interface api request when creating/editing L2VPN termination
|
* [#9844](https://github.com/netbox-community/netbox/issues/9844) - Fix interface api request when creating/editing L2VPN termination
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ class CustomFieldsMixin:
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.custom_fields = {}
|
self.custom_fields = {}
|
||||||
|
self.custom_field_groups = {}
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
@ -58,3 +59,6 @@ class CustomFieldsMixin:
|
|||||||
|
|
||||||
# Annotate the field in the list of CustomField form fields
|
# Annotate the field in the list of CustomField form fields
|
||||||
self.custom_fields[field_name] = customfield
|
self.custom_fields[field_name] = customfield
|
||||||
|
if customfield.group_name not in self.custom_field_groups:
|
||||||
|
self.custom_field_groups[customfield.group_name] = []
|
||||||
|
self.custom_field_groups[customfield.group_name].append(field_name)
|
||||||
|
@ -94,29 +94,18 @@ class NetBoxModelBulkEditForm(BootstrapMixin, CustomFieldsMixin, forms.Form):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.fields['pk'].queryset = self.model.objects.all()
|
self.fields['pk'].queryset = self.model.objects.all()
|
||||||
|
|
||||||
|
self._extend_nullable_fields()
|
||||||
|
|
||||||
def _get_form_field(self, customfield):
|
def _get_form_field(self, customfield):
|
||||||
return customfield.to_form_field(set_initial=False, enforce_required=False)
|
return customfield.to_form_field(set_initial=False, enforce_required=False)
|
||||||
|
|
||||||
def _append_customfield_fields(self):
|
def _extend_nullable_fields(self):
|
||||||
"""
|
nullable_custom_fields = [
|
||||||
Append form fields for all CustomFields assigned to this object type.
|
name for name, customfield in self.custom_fields.items() if not customfield.required
|
||||||
"""
|
]
|
||||||
nullable_custom_fields = []
|
|
||||||
for customfield in self._get_custom_fields(self._get_content_type()):
|
|
||||||
field_name = f'cf_{customfield.name}'
|
|
||||||
self.fields[field_name] = self._get_form_field(customfield)
|
|
||||||
|
|
||||||
# Record non-required custom fields as nullable
|
|
||||||
if not customfield.required:
|
|
||||||
nullable_custom_fields.append(field_name)
|
|
||||||
|
|
||||||
# Annotate the field in the list of CustomField form fields
|
|
||||||
self.custom_fields[field_name] = customfield
|
|
||||||
|
|
||||||
# Annotate nullable custom fields (if any) on the form instance
|
|
||||||
if nullable_custom_fields:
|
|
||||||
self.nullable_fields = (*self.nullable_fields, *nullable_custom_fields)
|
self.nullable_fields = (*self.nullable_fields, *nullable_custom_fields)
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
{% for group_name, fields in custom_fields.items %}
|
{% for group_name, fields in custom_fields.items %}
|
||||||
{% if group_name %}
|
{% if group_name %}
|
||||||
<h6><strong>{{ group_name }}</strong></h6>
|
<h6>{{ group_name }}</h6>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<table class="table table-hover attr-table">
|
<table class="table table-hover attr-table">
|
||||||
{% for field, value in fields.items %}
|
{% for field, value in fields.items %}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
{% load form_helpers %}
|
{% load form_helpers %}
|
||||||
|
|
||||||
{% for field in form %}
|
{% for group, fields in form.custom_field_groups.items %}
|
||||||
{% if field.name in form.custom_fields %}
|
{% if group %}
|
||||||
{% render_field field %}
|
<div class="row">
|
||||||
|
<h6 class="offset-sm-3 mb-3">{{ group }}</h6>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% for name in fields %}
|
||||||
|
{% render_field form|getfield:name %}
|
||||||
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Loading…
Reference in New Issue
Block a user