Reuse existing files as previews, icons or featured images #161

Merged
Anna Sirota merged 11 commits from files-allow-reuse-between-ext into main 2024-06-04 12:23:26 +02:00
Showing only changes of commit f1ca1d4f91 - Show all commits

View File

@ -188,16 +188,16 @@ class ExtensionUpdateForm(forms.ModelForm):
self.icon_form, self.icon_form,
] ]
seen_hashes = {} seen_hashes = {}
for f in new_file_forms:
hash = f.instance.original_hash
if hash and hash not in seen_hashes:
seen_hashes[hash] = f.instance
# Ignore duplicate files in the formsets: point all forms sharing the hash to the same # Ignore duplicate files in the formsets: point all forms sharing the hash to the same
# file instance, when forms call .save() it'll be on the same instance. # file instance, when forms call .save() it'll be on the same instance.
for f in new_file_forms: for f in new_file_forms:
hash = f.instance.original_hash hash = f.instance.original_hash
if hash: if not hash:
continue
if hash in seen_hashes:
f.instance = seen_hashes[hash] f.instance = seen_hashes[hash]
else:
seen_hashes[hash] = f.instance
return all(is_valid_flags) return all(is_valid_flags)
def clean_team(self): def clean_team(self):