1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add support for form fieldsets

This commit is contained in:
Jeremy Stretch
2021-02-25 13:08:02 -05:00
parent 992657cbe0
commit 2a517cde9f
2 changed files with 52 additions and 5 deletions

View File

@ -30,14 +30,53 @@
</div>
{% endif %}
{% block form %}
<div class="panel panel-default">
<div class="panel-heading"><strong>{{ obj_type|capfirst }}</strong></div>
{% if form.Meta.fieldsets %}
{# Render grouped fields accoring to Form #}
{% for group, fields in form.Meta.fieldsets %}
<div class="panel panel-default">
<div class="panel-heading"><strong>{{ group }}</strong></div>
<div class="panel-body">
{% for name in fields %}
{% render_field form|getfield:name %}
{% endfor %}
</div>
</div>
{% endfor %}
{% if form.custom_fields %}
<div class="panel panel-default">
<div class="panel-heading"><strong>Custom Fields</strong></div>
<div class="panel-body">
{% block form_fields %}
{% render_form form %}
{% endblock %}
{% render_custom_fields form %}
</div>
</div>
{% endif %}
{% if form.tags %}
<div class="panel panel-default">
<div class="panel-heading"><strong>Tags</strong></div>
<div class="panel-body">
{% render_field form.tags %}
</div>
</div>
{% endif %}
{% if form.comments %}
<div class="panel panel-default">
<div class="panel-heading"><strong>Comments</strong></div>
<div class="panel-body">
{% render_field form.comments %}
</div>
</div>
{% endif %}
{% else %}
{# Render all fields in a single group #}
<div class="panel panel-default">
<div class="panel-heading"><strong>{{ obj_type|capfirst }}</strong></div>
<div class="panel-body">
{% block form_fields %}
{% render_form form %}
{% endblock %}
</div>
</div>
{% endif %}
{% endblock %}
</div>
</div>

View File

@ -4,6 +4,14 @@ from django import template
register = template.Library()
@register.filter()
def getfield(form, fieldname):
"""
Return the specified field of a Form.
"""
return form[fieldname]
@register.inclusion_tag('utilities/render_field.html')
def render_field(field, bulk_nullable=False):
"""