Fixed broken import because of missing transaction

This commit is contained in:
Eliot Berriot 2018-02-27 17:43:50 +01:00
parent 1e2ab3ee06
commit b5226367a5
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
7 changed files with 41 additions and 9 deletions

View file

@ -1,6 +1,8 @@
import os
import shutil
from django.db import transaction
def rename_file(instance, field_name, new_name, allow_missing_file=False):
field = getattr(instance, field_name)
@ -17,3 +19,9 @@ def rename_file(instance, field_name, new_name, allow_missing_file=False):
field.name = os.path.join(initial_path, new_name_with_extension)
instance.save()
return new_name_with_extension
def on_commit(f, *args, **kwargs):
return transaction.on_commit(
lambda: f(*args, **kwargs)
)