Browse Source

Added CSV export for cables

Jeremy Stretch 7 years ago
parent
commit
1119209fa0
1 changed files with 19 additions and 0 deletions
  1. 19 0
      netbox/dcim/models.py

+ 19 - 0
netbox/dcim/models.py

@@ -2407,6 +2407,11 @@ class Cable(ChangeLoggedModel):
 
 
     objects = CableQuerySet.as_manager()
     objects = CableQuerySet.as_manager()
 
 
+    csv_headers = [
+        'termination_a_type', 'termination_a_id', 'termination_b_type', 'termination_b_id', 'type', 'status', 'label',
+        'color', 'length', 'length_unit',
+    ]
+
     class Meta:
     class Meta:
         unique_together = (
         unique_together = (
             ('termination_a_type', 'termination_a_id'),
             ('termination_a_type', 'termination_a_id'),
@@ -2461,6 +2466,20 @@ class Cable(ChangeLoggedModel):
 
 
         super(Cable, self).save(*args, **kwargs)
         super(Cable, self).save(*args, **kwargs)
 
 
+    def to_csv(self):
+        return (
+            '{}.{}'.format(self.termination_a_type.app_label, self.termination_a_type.model),
+            self.termination_a_id,
+            '{}.{}'.format(self.termination_b_type.app_label, self.termination_b_type.model),
+            self.termination_b_id,
+            self.get_type_display(),
+            self.get_status_display(),
+            self.label,
+            self.color,
+            self.length,
+            self.length_unit,
+        )
+
     def get_path_endpoints(self):
     def get_path_endpoints(self):
         """
         """
         Traverse both ends of a cable path and return its connected endpoints. Note that one or both endpoints may be
         Traverse both ends of a cable path and return its connected endpoints. Note that one or both endpoints may be