Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion netbox/extras/forms/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ def save(self, *args, **kwargs):
storage = storages.create_storage(storages.backends["scripts"])

filename = self.cleaned_data['upload_file'].name
self.instance.file_path = filename
data = self.cleaned_data['upload_file']

# If editing an existing file, delete the old one first to avoid random suffix
if self.instance.pk and self.instance.file_path:
try:
storage.delete(self.instance.file_path)
except FileNotFoundError:
pass

# Save the new file and capture the actual filename
self.instance.file_path = filename
storage.save(filename, data)

# need to skip ManagedFileForm save method
Expand Down