Address PR feedback, revert changes to render_fieldset template tag

This commit is contained in:
Jason Novinger 2025-05-16 15:12:56 -05:00
parent cb82810b27
commit c68b739d0a
4 changed files with 9 additions and 14 deletions

View File

@ -1,7 +1,7 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import gettext_lazy as _
from netbox.choices import *
from utilities.conversion import to_grams, to_meters

View File

@ -7,6 +7,7 @@ from django.utils.translation import gettext_lazy as _
__all__ = (
'CheckLastUpdatedMixin',
'DistanceValidationMixin',
)

View File

@ -6,7 +6,7 @@
<h2 class="col-9 offset-3">{{ heading }}</h2>
</div>
{% endif %}
{% for layout, title, items, has_field_errors in rows %}
{% for layout, title, items in rows %}
{% if layout == 'field' %}
{# Single form field #}
@ -25,10 +25,10 @@
{% elif layout == 'inline' %}
{# 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>
{% for field in items %}
<div class="col mb-1 {% if field.errors %} has-errors{% endif %}">
<div class="col mb-1">
{{ field }}
<div class="form-text">{% trans field.label %}</div>
{% if field.errors %}

View File

@ -51,11 +51,8 @@ def widget_type(field):
def render_fieldset(form, fieldset):
"""
Render a group set of fields.
The signature for row tuples is (layout, title, items, has_field_errors).
"""
rows = []
for item in fieldset.items:
# 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
]
rows.append(
('inline', item.label, fields, any(f.errors for f in fields))
('inline', item.label, 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]
} 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 not any(tab['active'] for tab in tabs):
tabs[0]['active'] = True
rows.append(
('tabs', None, tabs, has_field_errors)
('tabs', None, tabs)
)
elif type(item) is ObjectAttribute:
value = getattr(form.instance, item.name)
label = value._meta.verbose_name if hasattr(value, '_meta') else item.name
rows.append(
('attribute', label.title(), [value], False)
('attribute', label.title(), [value])
)
# A single form field
@ -101,7 +95,7 @@ def render_fieldset(form, fieldset):
if field.name in getattr(form, 'nullable_fields', []):
field._nullable = True
rows.append(
('field', None, [field], bool(field.errors))
('field', None, [field])
)
return {