mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
re-enable markdown in custom columns
This commit is contained in:
@ -550,3 +550,28 @@ class MarkdownColumn(tables.TemplateColumn):
|
||||
|
||||
def value(self, value):
|
||||
return value
|
||||
|
||||
|
||||
class CustomFieldMarkdownColumn(tables.TemplateColumn):
|
||||
"""
|
||||
Render a Markdown string in a longtext custom column.
|
||||
"""
|
||||
template_code = """
|
||||
{% if value %}
|
||||
{{ value|markdown }}
|
||||
{% else %}
|
||||
—
|
||||
{% endif %}
|
||||
"""
|
||||
|
||||
def __init__(self, customfield, *args, **kwargs):
|
||||
self.customfield = customfield
|
||||
kwargs['accessor'] = Accessor(f'custom_field_data__{customfield.name}')
|
||||
kwargs['template_code'] = self.template_code
|
||||
if 'verbose_name' not in kwargs:
|
||||
kwargs['verbose_name'] = customfield.label or customfield.name
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def value(self, value):
|
||||
return value
|
||||
|
@ -7,6 +7,7 @@ from django.db.models.fields.related import RelatedField
|
||||
from django_tables2.data import TableQuerysetData
|
||||
|
||||
from extras.models import CustomField, CustomLink
|
||||
from extras.choices import CustomFieldTypeChoices
|
||||
from netbox.tables import columns
|
||||
from utilities.paginator import EnhancedPaginator, get_paginate_count
|
||||
|
||||
@ -180,7 +181,7 @@ class NetBoxTable(BaseTable):
|
||||
content_type = ContentType.objects.get_for_model(self._meta.model)
|
||||
custom_fields = CustomField.objects.filter(content_types=content_type)
|
||||
extra_columns.extend([
|
||||
(f'cf_{cf.name}', columns.CustomFieldColumn(cf)) for cf in custom_fields
|
||||
(f'cf_{cf.name}', columns.CustomFieldMarkdownColumn(cf) if cf.type == CustomFieldTypeChoices.TYPE_LONGTEXT else columns.CustomFieldColumn(cf)) for cf in custom_fields
|
||||
])
|
||||
custom_links = CustomLink.objects.filter(content_type=content_type, enabled=True)
|
||||
extra_columns.extend([
|
||||
|
Reference in New Issue
Block a user