Commits

Rich Leland committed 14016bc Merge

Merged changes from default.

Comments (0)

Files changed (6)

+django-storages change log
+==========================
+
+1.1.3 (2011-08-15)
+******************
+
+* Created this lovely change log
+* Fixed `#89`_: broken StringIO import in CloudFiles backend
+* Merged `pull request #5`_: HashPathStorage path bug
+
+.. _#89: https://bitbucket.org/david/django-storages/issue/89/112-broke-the-mosso-backend
+.. _pull request #5: https://bitbucket.org/david/django-storages/pull-request/5/fixed-path-bug-and-added-testcase-for
+

storages/backends/hashpath.py

         dir_name, file_name = os.path.split(name)
 
         # Return the name if the file is already there
-        if os.path.exists(name):
+        if os.path.exists(self.path(name)):
             return name
 
         # Try to create the directory relative to the media root

storages/backends/mosso.py

 Custom storage for django with Mosso Cloud Files backend.
 Created by Rich Leland <rich@richleland.com>.
 """
-from _io import StringIO
 import os
+
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured
 from django.core.files import File
 from django.utils.text import get_valid_filename
 
 try:
+    from cStringIO import StringIO
+except:
+    from StringIO import StringIO
+
+try:
     import cloudfiles
     from cloudfiles.errors import NoSuchObject
 except ImportError:
         cloud_obj = self.container.create_object(name)
         cloud_obj.size = content.size
 
-        content.open()        
+        content.open()
         # If the content type is available, pass it in directly rather than
         # getting the cloud object to try to guess.
         if hasattr(content.file, 'content_type'):

Empty file added.

storages/tests/__init__.py

+from storages.tests.hashpath import *

storages/tests/hashpath.py

+import os
+import shutil
+
+from django.test import TestCase
+from django.core.files.base import ContentFile
+from django.conf import settings
+
+from storages.backends.hashpath import HashPathStorage
+
+
+class HashPathStorageTest(TestCase):
+
+    def setUp(self):
+        self.storage = HashPathStorage()
+        
+        # make sure the profile upload folder exists
+        if not os.path.exists(settings.MEDIA_ROOT):
+            os.makedirs(settings.MEDIA_ROOT)
+            
+    def tearDown(self):
+        # remove uploaded profile picture
+        if os.path.exists(settings.MEDIA_ROOT):
+            shutil.rmtree(settings.MEDIA_ROOT)
+
+    def test_save_same_file(self):
+        """
+        saves a file twice, the file should only be stored once, because the
+        content/hash is the same
+        """
+        
+        path_1 = self.storage.save('test', ContentFile('new content'))
+        
+        path_2 = self.storage.save('test', ContentFile('new content'))
+
+        self.assertEqual(path_1, path_2)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.