1
0
Эх сурвалжийг харах

Explicitely create collections on GET requests

Guillaume Ayoub 14 жил өмнө
parent
commit
22e4e3764c

+ 11 - 1
radicale/__init__.py

@@ -290,7 +290,13 @@ class Application(object):
         return status, {}, answer
 
     def get(self, environ, collections, content, user):
-        """Manage GET request."""
+        """Manage GET request.
+
+        In Radicale, GET requests create collections when the URL is not
+        available. This is useful for clients with no MKCOL or MKCALENDAR
+        support.
+
+        """
         # Display a "Radicale works!" message if the root URL is requested
         if environ["PATH_INFO"] == "/":
             headers = {"Content-type": "text/html"}
@@ -311,6 +317,10 @@ class Application(object):
             else:
                 return client.GONE, {}, None
         else:
+            # Create the collection if it does not exist
+            if not collection.exists:
+                collection.write()
+
             # Get whole collection
             answer_text = collection.text
             etag = collection.etag

+ 5 - 0
radicale/ical.py

@@ -284,6 +284,11 @@ class Collection(object):
         """Get the collection properties."""
         raise NotImplementedError
 
+    @property
+    def exists(self):
+        """``True`` if the collection exists on the storage, else ``False``."""
+        return self.is_node(self.path) or self.is_leaf(self.path)
+
     @staticmethod
     def _parse(text, item_types, name=None):
         """Find items with type in ``item_types`` in ``text``.

+ 0 - 4
radicale/storage/filesystem.py

@@ -96,10 +96,6 @@ class Collection(ical.Collection):
 
     @property
     def last_modified(self):
-        # Create collection if needed
-        if not os.path.exists(self._path):
-            self.write()
-
         modification_time = time.gmtime(os.path.getmtime(self._path))
         return time.strftime("%a, %d %b %Y %H:%M:%S +0000", modification_time)