Commits

David Larlet committed 6f08ab4

Overwrite: now works with the location defined by the user, rather than forcing MEDIA_ROOT. Thanks Michael Elsdörfer.

  • Participants
  • Parent commits 564ae31

Comments (0)

Files changed (2)

     * Ivanov E. (Database)
     * Ariel Núñez (packaging)
     * Wim Leers (SymlinkOrCopy + patches)
+    * Michael Elsdörfer (Overwrite + PEP8 compatibility)
 
 Extra thanks to Marty for adding this in Django, 
 you can buy his very interesting book (Pro Django).

File backends/overwrite.py

 from django.core.files.storage import FileSystemStorage
 
 class OverwriteStorage(FileSystemStorage):
+    """
+    Comes from http://www.djangosnippets.org/snippets/976/
+    (even if it already exists in S3Storage for ages)
+    
+    See also Django #4339, which might add this functionality to core.
+    """
     
     def get_available_name(self, name):
         """
         Returns a filename that's free on the target storage system, and
         available for new content to be written to.
-        
-        Comes from http://www.djangosnippets.org/snippets/976/
-        (even if it already exists in S3Storage for ages)
         """
-        # If the filename already exists, remove it as if it was a true file system
         if self.exists(name):
-            os.remove(os.path.join(settings.MEDIA_ROOT, name))
-        return name
+            self.delete(name)
+        return name