mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
Adds selection custom field labels to UI
This commit is contained in:
parent
4d13f4d252
commit
285187542d
@ -232,6 +232,11 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
return self.choice_set.choices
|
||||
return []
|
||||
|
||||
def get_choice_label(self, value):
|
||||
if not hasattr(self, '_choice_map'):
|
||||
self._choice_map = dict(self.choices)
|
||||
return self._choice_map.get(value, value)
|
||||
|
||||
def populate_initial_data(self, content_types):
|
||||
"""
|
||||
Populate initial custom field data upon either a) the creation of a new CustomField, or
|
||||
|
@ -483,8 +483,10 @@ class CustomFieldColumn(tables.Column):
|
||||
return mark_safe('<i class="mdi mdi-close-thick text-danger"></i>')
|
||||
if self.customfield.type == CustomFieldTypeChoices.TYPE_URL:
|
||||
return mark_safe(f'<a href="{escape(value)}">{escape(value)}</a>')
|
||||
if self.customfield.type == CustomFieldTypeChoices.TYPE_SELECT:
|
||||
return self.customfield.get_choice_label(value)
|
||||
if self.customfield.type == CustomFieldTypeChoices.TYPE_MULTISELECT:
|
||||
return ', '.join(v for v in value)
|
||||
return ', '.join(self.customfield.get_choice_label(v) for v in value)
|
||||
if self.customfield.type == CustomFieldTypeChoices.TYPE_MULTIOBJECT:
|
||||
return mark_safe(', '.join(
|
||||
self._linkify_item(obj) for obj in self.customfield.deserialize(value)
|
||||
|
@ -1,6 +1,7 @@
|
||||
from django import template
|
||||
from django.http import QueryDict
|
||||
|
||||
from extras.choices import CustomFieldTypeChoices
|
||||
from utilities.utils import dict_to_querydict
|
||||
|
||||
__all__ = (
|
||||
@ -38,6 +39,11 @@ def customfield_value(customfield, value):
|
||||
customfield: A CustomField instance
|
||||
value: The custom field value applied to an object
|
||||
"""
|
||||
if value:
|
||||
if customfield.type == CustomFieldTypeChoices.TYPE_SELECT:
|
||||
value = customfield.get_choice_label(value)
|
||||
elif customfield.type == CustomFieldTypeChoices.TYPE_MULTISELECT:
|
||||
value = [customfield.get_choice_label(v) for v in value]
|
||||
return {
|
||||
'customfield': customfield,
|
||||
'value': value,
|
||||
|
Loading…
Reference in New Issue
Block a user