mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #9647: Introduce customfield_value template tag
This commit is contained in:
@@ -16,33 +16,7 @@
|
||||
<span title="{{ field.description|escape }}">{{ field }}</span>
|
||||
</td>
|
||||
<td>
|
||||
{% if field.type == 'integer' and value is not None %}
|
||||
{{ value }}
|
||||
{% elif field.type == 'longtext' and value %}
|
||||
{{ value|markdown }}
|
||||
{% elif field.type == 'boolean' and value == True %}
|
||||
{% checkmark value true="True" %}
|
||||
{% elif field.type == 'boolean' and value == False %}
|
||||
{% checkmark value false="False" %}
|
||||
{% elif field.type == 'url' and value %}
|
||||
<a href="{{ value }}">{{ value|truncatechars:70 }}</a>
|
||||
{% elif field.type == 'json' and value %}
|
||||
<pre>{{ value|json }}</pre>
|
||||
{% elif field.type == 'multiselect' and value %}
|
||||
{{ value|join:", " }}
|
||||
{% elif field.type == 'object' and value %}
|
||||
{{ value|linkify }}
|
||||
{% elif field.type == 'multiobject' and value %}
|
||||
{% for obj in value %}
|
||||
{{ obj|linkify }}{% if not forloop.last %}<br />{% endif %}
|
||||
{% endfor %}
|
||||
{% elif value %}
|
||||
{{ value }}
|
||||
{% elif field.required %}
|
||||
<span class="text-warning"><i class="mdi mdi-alert"></i> Not defined</span>
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
{% customfield_value field value %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
27
netbox/utilities/templates/builtins/customfield_value.html
Normal file
27
netbox/utilities/templates/builtins/customfield_value.html
Normal file
@@ -0,0 +1,27 @@
|
||||
{% if field.type == 'integer' and value is not None %}
|
||||
{{ value }}
|
||||
{% elif field.type == 'longtext' and value %}
|
||||
{{ value|markdown }}
|
||||
{% elif field.type == 'boolean' and value == True %}
|
||||
{% checkmark value true="True" %}
|
||||
{% elif field.type == 'boolean' and value == False %}
|
||||
{% checkmark value false="False" %}
|
||||
{% elif field.type == 'url' and value %}
|
||||
<a href="{{ value }}">{{ value|truncatechars:70 }}</a>
|
||||
{% elif field.type == 'json' and value %}
|
||||
<pre>{{ value|json }}</pre>
|
||||
{% elif field.type == 'multiselect' and value %}
|
||||
{{ value|join:", " }}
|
||||
{% elif field.type == 'object' and value %}
|
||||
{{ value|linkify }}
|
||||
{% elif field.type == 'multiobject' and value %}
|
||||
{% for object in value %}
|
||||
{{ object|linkify }}{% if not forloop.last %}<br />{% endif %}
|
||||
{% endfor %}
|
||||
{% elif value %}
|
||||
{{ value }}
|
||||
{% elif field.required %}
|
||||
<span class="text-warning"><i class="mdi mdi-alert"></i> Not defined</span>
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
@@ -18,6 +18,21 @@ def tag(value, viewname=None):
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('builtins/customfield_value.html')
|
||||
def customfield_value(customfield, value):
|
||||
"""
|
||||
Render a custom field value according to the field type.
|
||||
|
||||
Args:
|
||||
customfield: A CustomField instance
|
||||
value: The custom field value applied to an object
|
||||
"""
|
||||
return {
|
||||
'customfield': customfield,
|
||||
'value': value,
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('builtins/badge.html')
|
||||
def badge(value, bg_color=None, show_empty=False):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user