1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #5926: Strip leading/trailing whitespace from TemplateColumns rendered for export

This commit is contained in:
Jeremy Stretch
2021-03-26 16:20:01 -04:00
parent b793ee3aff
commit 1544823d73

View File

@ -4,6 +4,7 @@ from django.contrib.contenttypes.fields import GenericForeignKey
from django.core.exceptions import FieldDoesNotExist
from django.db.models.fields.related import RelatedField
from django.urls import reverse
from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from django_tables2 import RequestConfig
from django_tables2.data import TableQuerysetData
@ -11,6 +12,18 @@ from django_tables2.data import TableQuerysetData
from .paginator import EnhancedPaginator, get_paginate_count
def stripped_value(self, value):
"""
Replaces TemplateColumn's value() method to both strip HTML tags and remove any leading/trailing whitespace.
"""
return strip_tags(value).strip()
# TODO: We're monkey-patching TemplateColumn here to strip leading/trailing whitespace. This will no longer
# be necessary if django-tables2 PR #794 is accepted. (See #5926)
tables.TemplateColumn.value = stripped_value
class BaseTable(tables.Table):
"""
Default table for object lists