From f66a265fcf2eff66e05ceb6237add43a23ab3668 Mon Sep 17 00:00:00 2001 From: Jason Yates Date: Sat, 8 Jan 2022 21:55:07 +0000 Subject: [PATCH 1/2] Fixes #8246 - Circuits list view to display formatted commit rate Adds a custom column class to format the commit rate in the circuits table view using humanize_speed template helper. Export still exports the raw number. --- netbox/circuits/tables.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/netbox/circuits/tables.py b/netbox/circuits/tables.py index 86a55eba5..0b7ad203d 100644 --- a/netbox/circuits/tables.py +++ b/netbox/circuits/tables.py @@ -22,6 +22,25 @@ CIRCUITTERMINATION_LINK = """ {% endif %} """ +# +# Table columns +# + +class CommitRateColumn(tables.TemplateColumn): + """ + Humanize the commit rate in the column view + """ + + template_code = """ + {% load helpers %} + {{ record.commit_rate|humanize_speed }} + """ + + def __init__(self, *args, **kwargs): + super().__init__(template_code=self.template_code, *args, **kwargs) + + def value(self, value): + return str(value) if value else None # # Providers @@ -119,6 +138,7 @@ class CircuitTable(BaseTable): template_code=CIRCUITTERMINATION_LINK, verbose_name='Side Z' ) + commit_rate = CommitRateColumn() comments = MarkdownColumn() tags = TagColumn( url_name='circuits:circuit_list' From f7324934731c311012bddfe7a843d56841cb7dbe Mon Sep 17 00:00:00 2001 From: Jason Yates Date: Sat, 8 Jan 2022 22:24:25 +0000 Subject: [PATCH 2/2] Fixing code style E302 --- netbox/circuits/tables.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/netbox/circuits/tables.py b/netbox/circuits/tables.py index 0b7ad203d..29bf704f0 100644 --- a/netbox/circuits/tables.py +++ b/netbox/circuits/tables.py @@ -26,6 +26,7 @@ CIRCUITTERMINATION_LINK = """ # Table columns # + class CommitRateColumn(tables.TemplateColumn): """ Humanize the commit rate in the column view @@ -46,6 +47,7 @@ class CommitRateColumn(tables.TemplateColumn): # Providers # + class ProviderTable(BaseTable): pk = ToggleColumn() name = tables.Column(