mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 04:32:51 -06:00
Address PR feedback, revert changes to render_fieldset template tag
This commit is contained in:
parent
cb82810b27
commit
c68b739d0a
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from netbox.choices import *
|
from netbox.choices import *
|
||||||
from utilities.conversion import to_grams, to_meters
|
from utilities.conversion import to_grams, to_meters
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'CheckLastUpdatedMixin',
|
'CheckLastUpdatedMixin',
|
||||||
|
'DistanceValidationMixin',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<h2 class="col-9 offset-3">{{ heading }}</h2>
|
<h2 class="col-9 offset-3">{{ heading }}</h2>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for layout, title, items, has_field_errors in rows %}
|
{% for layout, title, items in rows %}
|
||||||
|
|
||||||
{% if layout == 'field' %}
|
{% if layout == 'field' %}
|
||||||
{# Single form field #}
|
{# Single form field #}
|
||||||
@ -25,10 +25,10 @@
|
|||||||
|
|
||||||
{% elif layout == 'inline' %}
|
{% elif layout == 'inline' %}
|
||||||
{# Multiple form fields on the same line #}
|
{# Multiple form fields on the same line #}
|
||||||
<div class="row mb-3 {% if has_field_errors %} has-errors{% endif %}">
|
<div class="row mb-3">
|
||||||
<label class="col col-3 col-form-label text-lg-end">{{ title|default:'' }}</label>
|
<label class="col col-3 col-form-label text-lg-end">{{ title|default:'' }}</label>
|
||||||
{% for field in items %}
|
{% for field in items %}
|
||||||
<div class="col mb-1 {% if field.errors %} has-errors{% endif %}">
|
<div class="col mb-1">
|
||||||
{{ field }}
|
{{ field }}
|
||||||
<div class="form-text">{% trans field.label %}</div>
|
<div class="form-text">{% trans field.label %}</div>
|
||||||
{% if field.errors %}
|
{% if field.errors %}
|
||||||
|
@ -51,11 +51,8 @@ def widget_type(field):
|
|||||||
def render_fieldset(form, fieldset):
|
def render_fieldset(form, fieldset):
|
||||||
"""
|
"""
|
||||||
Render a group set of fields.
|
Render a group set of fields.
|
||||||
|
|
||||||
The signature for row tuples is (layout, title, items, has_field_errors).
|
|
||||||
"""
|
"""
|
||||||
rows = []
|
rows = []
|
||||||
|
|
||||||
for item in fieldset.items:
|
for item in fieldset.items:
|
||||||
|
|
||||||
# Multiple fields side-by-side
|
# Multiple fields side-by-side
|
||||||
@ -64,7 +61,7 @@ def render_fieldset(form, fieldset):
|
|||||||
form[name] for name in item.fields if name in form.fields
|
form[name] for name in item.fields if name in form.fields
|
||||||
]
|
]
|
||||||
rows.append(
|
rows.append(
|
||||||
('inline', item.label, fields, any(f.errors for f in fields))
|
('inline', item.label, fields)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Tabbed groups of fields
|
# Tabbed groups of fields
|
||||||
@ -77,21 +74,18 @@ def render_fieldset(form, fieldset):
|
|||||||
'fields': [form[name] for name in tab['fields'] if name in form.fields]
|
'fields': [form[name] for name in tab['fields'] if name in form.fields]
|
||||||
} for tab in item.tabs
|
} for tab in item.tabs
|
||||||
]
|
]
|
||||||
has_field_errors = any(
|
|
||||||
field.errors for tab in tabs for field in tab['fields']
|
|
||||||
)
|
|
||||||
# If none of the tabs has been marked as active, activate the first one
|
# If none of the tabs has been marked as active, activate the first one
|
||||||
if not any(tab['active'] for tab in tabs):
|
if not any(tab['active'] for tab in tabs):
|
||||||
tabs[0]['active'] = True
|
tabs[0]['active'] = True
|
||||||
rows.append(
|
rows.append(
|
||||||
('tabs', None, tabs, has_field_errors)
|
('tabs', None, tabs)
|
||||||
)
|
)
|
||||||
|
|
||||||
elif type(item) is ObjectAttribute:
|
elif type(item) is ObjectAttribute:
|
||||||
value = getattr(form.instance, item.name)
|
value = getattr(form.instance, item.name)
|
||||||
label = value._meta.verbose_name if hasattr(value, '_meta') else item.name
|
label = value._meta.verbose_name if hasattr(value, '_meta') else item.name
|
||||||
rows.append(
|
rows.append(
|
||||||
('attribute', label.title(), [value], False)
|
('attribute', label.title(), [value])
|
||||||
)
|
)
|
||||||
|
|
||||||
# A single form field
|
# A single form field
|
||||||
@ -101,7 +95,7 @@ def render_fieldset(form, fieldset):
|
|||||||
if field.name in getattr(form, 'nullable_fields', []):
|
if field.name in getattr(form, 'nullable_fields', []):
|
||||||
field._nullable = True
|
field._nullable = True
|
||||||
rows.append(
|
rows.append(
|
||||||
('field', None, [field], bool(field.errors))
|
('field', None, [field])
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user