Sebastian Annies committed 0b6ff83

create pseudo directories for every '/' in the filename

Comments (0)

Files changed (1)


 Custom storage for django with Mosso Cloud Files backend.
 Created by Rich Leland <>.
+from _io import StringIO
+import os
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured
 from django.core.files import File
         Use the Cloud Files service to write ``content`` to a remote file
         (called ``name``).
+        (path, last) = os.path.split(name)
+        if path:
+            try:
+                self.container.get_object(path)
+            except NoSuchObject:
+                self._save(path, CloudStorageDirectory(path))
         cloud_obj = self.container.create_object(name)
         cloud_obj.size = content.size
         return '%s/%s' % (self.container_url, name)
+class CloudStorageDirectory(File):
+    """
+    A File-like object that creates a directory at cloudfiles
+    """
+    def __init__(self, name):
+        super(CloudStorageDirectory, self).__init__(StringIO(), name=name)
+        self.file.content_type = 'application/directory'
+        self.size = 0
+    def __str__(self):
+        return 'directory'
+    def __nonzero__(self):
+        return True
+    def open(self, mode=None):
+    def close(self):
+        pass
 class CloudFilesStorageFile(File):
     closed = False
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
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.