mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-15 19:52:52 -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 self.choice_set.choices
|
||||||
return []
|
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):
|
def populate_initial_data(self, content_types):
|
||||||
"""
|
"""
|
||||||
Populate initial custom field data upon either a) the creation of a new CustomField, or
|
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>')
|
return mark_safe('<i class="mdi mdi-close-thick text-danger"></i>')
|
||||||
if self.customfield.type == CustomFieldTypeChoices.TYPE_URL:
|
if self.customfield.type == CustomFieldTypeChoices.TYPE_URL:
|
||||||
return mark_safe(f'<a href="{escape(value)}">{escape(value)}</a>')
|
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:
|
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:
|
if self.customfield.type == CustomFieldTypeChoices.TYPE_MULTIOBJECT:
|
||||||
return mark_safe(', '.join(
|
return mark_safe(', '.join(
|
||||||
self._linkify_item(obj) for obj in self.customfield.deserialize(value)
|
self._linkify_item(obj) for obj in self.customfield.deserialize(value)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from django import template
|
from django import template
|
||||||
from django.http import QueryDict
|
from django.http import QueryDict
|
||||||
|
|
||||||
|
from extras.choices import CustomFieldTypeChoices
|
||||||
from utilities.utils import dict_to_querydict
|
from utilities.utils import dict_to_querydict
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -38,6 +39,11 @@ def customfield_value(customfield, value):
|
|||||||
customfield: A CustomField instance
|
customfield: A CustomField instance
|
||||||
value: The custom field value applied to an object
|
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 {
|
return {
|
||||||
'customfield': customfield,
|
'customfield': customfield,
|
||||||
'value': value,
|
'value': value,
|
||||||
|
Loading…
Reference in New Issue
Block a user