Add support for Evolution VCard WebDAV
This commit is contained in:
parent
8a4be02075
commit
b56db741f4
@ -405,6 +405,7 @@ class Application(object):
|
|||||||
def put(self, environ, collections, content, user):
|
def put(self, environ, collections, content, user):
|
||||||
"""Manage PUT request."""
|
"""Manage PUT request."""
|
||||||
collection = collections[0]
|
collection = collections[0]
|
||||||
|
collection.set_mimetype(environ.get("CONTENT_TYPE"))
|
||||||
headers = {}
|
headers = {}
|
||||||
item_name = xmlutils.name_from_path(environ["PATH_INFO"], collection)
|
item_name = xmlutils.name_from_path(environ["PATH_INFO"], collection)
|
||||||
item = collection.get_item(item_name)
|
item = collection.get_item(item_name)
|
||||||
|
@ -110,11 +110,11 @@ class Item(object):
|
|||||||
line, "X-RADICALE-NAME:%s" % self._name)
|
line, "X-RADICALE-NAME:%s" % self._name)
|
||||||
else:
|
else:
|
||||||
self.text = self.text.replace(
|
self.text = self.text.replace(
|
||||||
"\nUID:", "\nX-RADICALE-NAME:%s\nUID:" % self._name)
|
"\nEND:", "\nX-RADICALE-NAME:%s\nEND:" % self._name)
|
||||||
else:
|
else:
|
||||||
self._name = str(uuid.uuid4())
|
self._name = str(uuid.uuid4())
|
||||||
self.text = self.text.replace(
|
self.text = self.text.replace(
|
||||||
"\nEND:", "\nUID:%s\nEND:" % self._name)
|
"\nEND:", "\nX-RADICALE-NAME:%s\nEND:" % self._name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def etag(self):
|
def etag(self):
|
||||||
@ -342,7 +342,7 @@ class Collection(object):
|
|||||||
items = self.items
|
items = self.items
|
||||||
|
|
||||||
for new_item in self._parse(
|
for new_item in self._parse(
|
||||||
text, (Timezone, Event, Todo, Journal), name):
|
text, (Timezone, Event, Todo, Journal, Card), name):
|
||||||
if new_item.name not in (item.name for item in items):
|
if new_item.name not in (item.name for item in items):
|
||||||
items.append(new_item)
|
items.append(new_item)
|
||||||
|
|
||||||
@ -371,7 +371,7 @@ class Collection(object):
|
|||||||
"""Write calendar with given parameters."""
|
"""Write calendar with given parameters."""
|
||||||
headers = headers or self.headers or (
|
headers = headers or self.headers or (
|
||||||
Header("PRODID:-//Radicale//NONSGML Radicale Server//EN"),
|
Header("PRODID:-//Radicale//NONSGML Radicale Server//EN"),
|
||||||
Header("VERSION:2.0"))
|
Header("VERSION:%s" % self.version))
|
||||||
items = items if items is not None else self.items
|
items = items if items is not None else self.items
|
||||||
|
|
||||||
self._create_dirs(self.path)
|
self._create_dirs(self.path)
|
||||||
@ -379,6 +379,15 @@ class Collection(object):
|
|||||||
text = serialize(self.tag, headers, items)
|
text = serialize(self.tag, headers, items)
|
||||||
return open(self.path, "w").write(text)
|
return open(self.path, "w").write(text)
|
||||||
|
|
||||||
|
def set_mimetype(self, mimetype):
|
||||||
|
"""Set the mimetype of the collection."""
|
||||||
|
with self.props as props:
|
||||||
|
if "tag" not in props:
|
||||||
|
if mimetype == "text/vcard":
|
||||||
|
props["tag"] = "VADDRESSBOOK"
|
||||||
|
else:
|
||||||
|
props["tag"] = "VCALENDAR"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _create_dirs(path):
|
def _create_dirs(path):
|
||||||
"""Create folder if absent."""
|
"""Create folder if absent."""
|
||||||
@ -438,12 +447,11 @@ class Collection(object):
|
|||||||
header_lines = []
|
header_lines = []
|
||||||
|
|
||||||
lines = unfold(self.text)
|
lines = unfold(self.text)
|
||||||
|
for header in ("PRODID", "VERSION"):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith("PRODID:"):
|
if line.startswith("%s:" % header):
|
||||||
header_lines.append(Header(line))
|
|
||||||
for line in lines:
|
|
||||||
if line.startswith("VERSION:"):
|
|
||||||
header_lines.append(Header(line))
|
header_lines.append(Header(line))
|
||||||
|
break
|
||||||
|
|
||||||
return header_lines
|
return header_lines
|
||||||
|
|
||||||
@ -488,3 +496,8 @@ class Collection(object):
|
|||||||
def url(self):
|
def url(self):
|
||||||
"""Get the standard collection URL."""
|
"""Get the standard collection URL."""
|
||||||
return "/%s/" % self.local_path
|
return "/%s/" % self.local_path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def version(self):
|
||||||
|
"""Get the version of the collection type."""
|
||||||
|
return "3.0" if self.tag == "VADDRESSBOOK" else "2.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user