Parcourir la source

Closes #9451: Add export_raw argument for TemplateColumn

jeremystretch il y a 3 ans
Parent
commit
5838a9f3a0

+ 2 - 1
docs/plugins/development/tables.md

@@ -85,4 +85,5 @@ The table column classes listed below are supported for use in plugins. These cl
 
 ::: netbox.tables.TemplateColumn
     selection:
-      members: false
+      members:
+        - __init__

+ 1 - 0
docs/release-notes/version-3.2.md

@@ -11,6 +11,7 @@
 * [#9277](https://github.com/netbox-community/netbox/issues/9277) - Introduce `CSRF_COOKIE_NAME` configuration parameter
 * [#9347](https://github.com/netbox-community/netbox/issues/9347) - Include services in global search
 * [#9379](https://github.com/netbox-community/netbox/issues/9379) - Redirect to virtual chassis view after adding a member device
+* [#9451](https://github.com/netbox-community/netbox/issues/9451) - Add `export_raw` argument for TemplateColumn
 
 ### Bug Fixes
 

+ 13 - 0
netbox/netbox/tables/columns.py

@@ -90,6 +90,15 @@ class TemplateColumn(tables.TemplateColumn):
     """
     PLACEHOLDER = mark_safe('—')
 
+    def __init__(self, export_raw=False, **kwargs):
+        """
+        Args:
+            export_raw: If true, data export returns the raw field value rather than the rendered template. (Default:
+                        False)
+        """
+        super().__init__(**kwargs)
+        self.export_raw = export_raw
+
     def render(self, *args, **kwargs):
         ret = super().render(*args, **kwargs)
         if not ret.strip():
@@ -97,6 +106,10 @@ class TemplateColumn(tables.TemplateColumn):
         return ret
 
     def value(self, **kwargs):
+        if self.export_raw:
+            # Skip template rendering and export raw value
+            return kwargs.get('value')
+
         ret = super().value(**kwargs)
         if ret == self.PLACEHOLDER:
             return ''