Skip to content

Commit

Permalink
Merge pull request #19 from inventree/delete-old-files
Browse files Browse the repository at this point in the history
Add option to delete old wireviz files
  • Loading branch information
SchrodingersGat authored May 26, 2023
2 parents e59e9dd + a1d37d2 commit f5903a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inventree_wireviz/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version information for the inventree-wireviz plugin"""

PLUGIN_VERSION = "0.3.2"
PLUGIN_VERSION = "0.3.3"
20 changes: 20 additions & 0 deletions inventree_wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f5903a8

Please sign in to comment.