mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
Closes #9647: Introduce customfield_value template tag
This commit is contained in:
parent
c11af40a06
commit
a57398b0d6
@ -215,6 +215,8 @@ The following custom template tags are available in NetBox.
|
|||||||
|
|
||||||
::: utilities.templatetags.builtins.tags.checkmark
|
::: utilities.templatetags.builtins.tags.checkmark
|
||||||
|
|
||||||
|
::: utilities.templatetags.builtins.tags.customfield_value
|
||||||
|
|
||||||
::: utilities.templatetags.builtins.tags.tag
|
::: utilities.templatetags.builtins.tags.tag
|
||||||
|
|
||||||
## Filters
|
## Filters
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
* [#9075](https://github.com/netbox-community/netbox/issues/9075) - Introduce `AbortRequest` exception for cleanly interrupting object mutations
|
* [#9075](https://github.com/netbox-community/netbox/issues/9075) - Introduce `AbortRequest` exception for cleanly interrupting object mutations
|
||||||
* [#9092](https://github.com/netbox-community/netbox/issues/9092) - Add support for `ObjectChildrenView` generic view
|
* [#9092](https://github.com/netbox-community/netbox/issues/9092) - Add support for `ObjectChildrenView` generic view
|
||||||
* [#9414](https://github.com/netbox-community/netbox/issues/9414) - Add `clone()` method to NetBoxModel for copying instance attributes
|
* [#9414](https://github.com/netbox-community/netbox/issues/9414) - Add `clone()` method to NetBoxModel for copying instance attributes
|
||||||
|
* [#9647](https://github.com/netbox-community/netbox/issues/9647) - Introduce `customfield_value` template tag
|
||||||
|
|
||||||
### Other Changes
|
### Other Changes
|
||||||
|
|
||||||
|
@ -16,33 +16,7 @@
|
|||||||
<span title="{{ field.description|escape }}">{{ field }}</span>
|
<span title="{{ field.description|escape }}">{{ field }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if field.type == 'integer' and value is not None %}
|
{% customfield_value field value %}
|
||||||
{{ 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 %}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% 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')
|
@register.inclusion_tag('builtins/badge.html')
|
||||||
def badge(value, bg_color=None, show_empty=False):
|
def badge(value, bg_color=None, show_empty=False):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user