Просмотр исходного кода

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.
Jason Yates 4 лет назад
Родитель
Сommit
f66a265fcf
1 измененных файлов с 20 добавлено и 0 удалено
  1. 20 0
      netbox/circuits/tables.py

+ 20 - 0
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'