From 23b58ccbe82be8f8362232ba271c8e772d3ab48a Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 4 Mar 2021 15:56:12 -0500 Subject: [PATCH] Override value() on custom table columns --- netbox/utilities/tables.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py index f2f567783..bd52851ca 100644 --- a/netbox/utilities/tables.py +++ b/netbox/utilities/tables.py @@ -133,6 +133,9 @@ class BooleanColumn(tables.Column): rendered = '' return mark_safe(rendered) + def value(self, value): + return str(value) + class ButtonsColumn(tables.TemplateColumn): """ @@ -177,6 +180,10 @@ class ButtonsColumn(tables.TemplateColumn): super().__init__(template_code=template_code, *args, **kwargs) + # Exclude from export by default + if 'exclude_from_export' not in kwargs: + self.exclude_from_export = True + self.extra_context.update({ 'buttons': buttons or self.buttons, 'return_url_extra': return_url_extra, @@ -201,6 +208,9 @@ class ChoiceFieldColumn(tables.Column): ) return self.default + def value(self, value): + return value + class ColorColumn(tables.Column): """ @@ -211,6 +221,9 @@ class ColorColumn(tables.Column): f' ' ) + def value(self, value): + return f'#{value}' + class ColoredLabelColumn(tables.TemplateColumn): """ @@ -224,6 +237,9 @@ class ColoredLabelColumn(tables.TemplateColumn): def __init__(self, *args, **kwargs): super().__init__(template_code=self.template_code, *args, **kwargs) + def value(self, value): + return str(value) + class LinkedCountColumn(tables.Column): """ @@ -247,6 +263,9 @@ class LinkedCountColumn(tables.Column): return mark_safe(f'{value}') return value + def value(self, value): + return value + class TagColumn(tables.TemplateColumn): """ @@ -265,3 +284,6 @@ class TagColumn(tables.TemplateColumn): template_code=self.template_code, extra_context={'url_name': url_name} ) + + def value(self, value): + return ",".join([tag.name for tag in value.all()])