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

Reorganize & clean up templatetag templates

This commit is contained in:
jeremystretch
2021-12-22 15:05:24 -05:00
parent 37065b7c50
commit f369b5f588
18 changed files with 49 additions and 64 deletions

View File

@ -1,8 +1,7 @@
{# Base layout for the core NetBox UI w/navbar and page content #}
{% extends 'base/base.html' %}
{% load helpers %}
{% load nav %}
{% load search_options %}
{% load search %}
{% load static %}
{% block layout %}

View File

@ -1,4 +1,4 @@
{% load nav %}
{% load navigation %}
{% load static %}
<nav class="sidenav noprint" id="sidenav" data-simplebar>

View File

@ -1,5 +1,4 @@
{% extends 'base/layout.html' %}
{% load get_status %}
{% load helpers %}
{% load render_table from django_tables2 %}

View File

@ -4,6 +4,10 @@ from django import template
register = template.Library()
#
# Filters
#
@register.filter()
def getfield(form, fieldname):
"""
@ -12,38 +16,6 @@ def getfield(form, fieldname):
return form[fieldname]
@register.inclusion_tag('utilities/render_field.html')
def render_field(field, bulk_nullable=False, label=None):
"""
Render a single form field from template
"""
return {
'field': field,
'label': label,
'bulk_nullable': bulk_nullable,
}
@register.inclusion_tag('utilities/render_custom_fields.html')
def render_custom_fields(form):
"""
Render all custom fields in a form
"""
return {
'form': form,
}
@register.inclusion_tag('utilities/render_form.html')
def render_form(form):
"""
Render an entire form from template
"""
return {
'form': form,
}
@register.filter(name='widget_type')
def widget_type(field):
"""
@ -57,7 +29,43 @@ def widget_type(field):
return None
@register.inclusion_tag('utilities/render_errors.html')
#
# Inclusion tags
#
@register.inclusion_tag('form_helpers/render_field.html')
def render_field(field, bulk_nullable=False, label=None):
"""
Render a single form field from template
"""
return {
'field': field,
'label': label,
'bulk_nullable': bulk_nullable,
}
@register.inclusion_tag('form_helpers/render_custom_fields.html')
def render_custom_fields(form):
"""
Render all custom fields in a form
"""
return {
'form': form,
}
@register.inclusion_tag('form_helpers/render_form.html')
def render_form(form):
"""
Render an entire form from template
"""
return {
'form': form,
}
@register.inclusion_tag('form_helpers/render_errors.html')
def render_errors(form):
"""
Render form errors, if they exist.

View File

@ -1,21 +0,0 @@
from django import template
register = template.Library()
TERMS_DANGER = ("delete", "deleted", "remove", "removed")
TERMS_WARNING = ("changed", "updated", "change", "update")
TERMS_SUCCESS = ("created", "added", "create", "add")
@register.simple_tag
def get_status(text: str) -> str:
lower = text.lower()
if lower in TERMS_DANGER:
return "danger"
elif lower in TERMS_WARNING:
return "warning"
elif lower in TERMS_SUCCESS:
return "success"
else:
return "info"

View File

@ -384,7 +384,7 @@ def querystring(request, **kwargs):
return ''
@register.inclusion_tag('utilities/templatetags/utilization_graph.html')
@register.inclusion_tag('helpers/utilization_graph.html')
def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
"""
Display a horizontal bar graph indicating a percentage of utilization.
@ -403,7 +403,7 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
}
@register.inclusion_tag('utilities/templatetags/tag.html')
@register.inclusion_tag('helpers/tag.html')
def tag(tag, url_name=None):
"""
Display a tag, optionally linked to a filtered list of objects.
@ -414,7 +414,7 @@ def tag(tag, url_name=None):
}
@register.inclusion_tag('utilities/templatetags/badge.html')
@register.inclusion_tag('helpers/badge.html')
def badge(value, bg_class='secondary', show_empty=False):
"""
Display the specified number as a badge.
@ -426,7 +426,7 @@ def badge(value, bg_class='secondary', show_empty=False):
}
@register.inclusion_tag('utilities/templatetags/table_config_form.html')
@register.inclusion_tag('helpers/table_config_form.html')
def table_config_form(table, table_name=None):
return {
'table_name': table_name or table.__class__.__name__,
@ -434,7 +434,7 @@ def table_config_form(table, table_name=None):
}
@register.inclusion_tag('utilities/templatetags/applied_filters.html')
@register.inclusion_tag('helpers/applied_filters.html')
def applied_filters(form, query_params):
"""
Display the active filters for a given filter form.

View File

@ -8,7 +8,7 @@ from netbox.navigation_menu import MENUS
register = template.Library()
@register.inclusion_tag("navigation/nav_items.html", takes_context=True)
@register.inclusion_tag("navigation/menu.html", takes_context=True)
def nav(context: Context) -> Dict:
"""
Render the navigation menu.