Removed unnecessary check

This commit is contained in:
Wolf-Bastian Poettner 2020-02-01 14:14:13 +00:00
parent 3027053256
commit 060bdc947a

View File

@ -420,36 +420,34 @@ def update_filename(sender, instance, **kwargs):
if instance.filename == new_filename: if instance.filename == new_filename:
return return
# Check if filename needs changing # Determine the full "target" path
if new_filename != instance.filename: path_new = instance.filename_to_path(new_filename)
# Determine the full "target" path dir_new = instance.filename_to_path(os.path.dirname(new_filename))
path_new = instance.filename_to_path(new_filename)
dir_new = instance.filename_to_path(os.path.dirname(new_filename))
# Create new path # Create new path
instance.create_source_directory() instance.create_source_directory()
# Determine the full "current" path # Determine the full "current" path
path_current = instance.filename_to_path(instance.filename) path_current = instance.filename_to_path(instance.filename)
# Move file # Move file
try: try:
os.rename(path_current, path_new) os.rename(path_current, path_new)
except PermissionError: except PermissionError:
# Do not update filename in object # Do not update filename in object
return return
# Delete empty directory # Delete empty directory
old_dir = os.path.dirname(instance.filename) old_dir = os.path.dirname(instance.filename)
old_path = instance.filename_to_path(old_dir) old_path = instance.filename_to_path(old_dir)
delete_empty_directory(old_path) delete_empty_directory(old_path)
instance.filename = new_filename instance.filename = new_filename
# Save instance # Save instance
# This will not cause a cascade of post_save signals, as next time # This will not cause a cascade of post_save signals, as next time
# nothing needs to be renamed # nothing needs to be renamed
instance.save() instance.save()
@receiver(models.signals.post_delete, sender=Document) @receiver(models.signals.post_delete, sender=Document)