From 22e4e3764c5b52de9756352724d3e8a6c6b215ce Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Thu, 23 Feb 2012 15:28:45 +0100 Subject: [PATCH] Explicitely create collections on GET requests --- radicale/__init__.py | 12 +++++++++++- radicale/ical.py | 5 +++++ radicale/storage/filesystem.py | 4 ---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index aa3e9e2..e4c407e 100644 --- a/radicale/__init__.py +++ b/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 diff --git a/radicale/ical.py b/radicale/ical.py index 2903c46..4c67c5d 100644 --- a/radicale/ical.py +++ b/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``. diff --git a/radicale/storage/filesystem.py b/radicale/storage/filesystem.py index 4ecc5b7..54b4c59 100644 --- a/radicale/storage/filesystem.py +++ b/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)