diff --git a/inventree_wireviz/version.py b/inventree_wireviz/version.py index 5adf05a..83a489e 100644 --- a/inventree_wireviz/version.py +++ b/inventree_wireviz/version.py @@ -1,3 +1,3 @@ """Version information for the inventree-wireviz plugin""" -PLUGIN_VERSION = "0.3.2" +PLUGIN_VERSION = "0.3.3" diff --git a/inventree_wireviz/wireviz.py b/inventree_wireviz/wireviz.py index 347514f..28cce3e 100644 --- a/inventree_wireviz/wireviz.py +++ b/inventree_wireviz/wireviz.py @@ -59,6 +59,12 @@ class WirevizPlugin(EventMixin, PanelMixin, SettingsMixin, InvenTreePlugin): 'description': 'Path to store uploaded wireviz template files (relative to media root)', 'default': 'wireviz', }, + "DELETE_OLD_FILES": { + 'name': 'Delete Old Files', + 'description': 'Delete old wireviz files when uploading a new wireviz file', + 'default': True, + 'validator': bool, + }, "EXTRACT_BOM": { 'name': 'Extract BOM Data', 'description': 'Automatically extract BOM data from wireviz diagrams', @@ -159,6 +165,20 @@ def process_event(self, event, *args, **kwargs): # Check if the attachment is a .wireviz file if filename.endswith(".wireviz"): self.process_wireviz_file(filename) + + # Delete *old* wireviz files + if self.get_setting('DELETE_OLD_FILES'): + for attach in PartAttachment.objects.filter(part=self.part): + # Don't delete this one! + if attach.pk == attachment.pk: + continue + + fn = attach.attachment.name + + # Delete old wireviz files + if fn.endswith(".wireviz"): + attach.delete() + except PartAttachment.DoesNotExist: pass