mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 04:02:52 -06:00
#9979: Fix fallback to default value
This commit is contained in:
parent
0ef1bc8490
commit
dedee0f9d9
@ -14,6 +14,7 @@ from django_tables2.columns import library
|
|||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
|
|
||||||
from extras.choices import CustomFieldTypeChoices
|
from extras.choices import CustomFieldTypeChoices
|
||||||
|
from utilities.templatetags.builtins.filters import render_markdown
|
||||||
from utilities.utils import content_type_identifier, content_type_name, get_viewname
|
from utilities.utils import content_type_identifier, content_type_name, get_viewname
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -418,14 +419,6 @@ class CustomFieldColumn(tables.Column):
|
|||||||
"""
|
"""
|
||||||
Display custom fields in the appropriate format.
|
Display custom fields in the appropriate format.
|
||||||
"""
|
"""
|
||||||
template_code = """
|
|
||||||
{% if value %}
|
|
||||||
{{ value|markdown }}
|
|
||||||
{% else %}
|
|
||||||
—
|
|
||||||
{% endif %}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, customfield, *args, **kwargs):
|
def __init__(self, customfield, *args, **kwargs):
|
||||||
self.customfield = customfield
|
self.customfield = customfield
|
||||||
kwargs['accessor'] = Accessor(f'custom_field_data__{customfield.name}')
|
kwargs['accessor'] = Accessor(f'custom_field_data__{customfield.name}')
|
||||||
@ -435,7 +428,7 @@ class CustomFieldColumn(tables.Column):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _likify_item(item):
|
def _linkify_item(item):
|
||||||
if hasattr(item, 'get_absolute_url'):
|
if hasattr(item, 'get_absolute_url'):
|
||||||
return f'<a href="{item.get_absolute_url()}">{escape(item)}</a>'
|
return f'<a href="{item.get_absolute_url()}">{escape(item)}</a>'
|
||||||
return escape(item)
|
return escape(item)
|
||||||
@ -451,13 +444,13 @@ class CustomFieldColumn(tables.Column):
|
|||||||
return ', '.join(v for v in value)
|
return ', '.join(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._likify_item(obj) for obj in self.customfield.deserialize(value)
|
self._linkify_item(obj) for obj in self.customfield.deserialize(value)
|
||||||
))
|
))
|
||||||
if self.customfield.type == CustomFieldTypeChoices.TYPE_LONGTEXT:
|
if self.customfield.type == CustomFieldTypeChoices.TYPE_LONGTEXT and value:
|
||||||
return Template(self.template_code).render(Context({"value": value}))
|
return render_markdown(value)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
obj = self.customfield.deserialize(value)
|
obj = self.customfield.deserialize(value)
|
||||||
return mark_safe(self._likify_item(obj))
|
return mark_safe(self._linkify_item(obj))
|
||||||
return self.default
|
return self.default
|
||||||
|
|
||||||
def value(self, value):
|
def value(self, value):
|
||||||
|
Loading…
Reference in New Issue
Block a user