Add support for VJOURNAL items (closes #435)
This commit is contained in:
parent
5f14a92633
commit
d061c09344
@ -64,8 +64,8 @@ class Item(object):
|
|||||||
# An item must have a name, determined in order by:
|
# An item must have a name, determined in order by:
|
||||||
#
|
#
|
||||||
# - the ``name`` parameter
|
# - the ``name`` parameter
|
||||||
# - the ``X-RADICALE-NAME`` iCal property (for Events and Todos)
|
# - the ``X-RADICALE-NAME`` iCal property (for Events, Todos, Journals)
|
||||||
# - the ``UID`` iCal property (for Events and Todos)
|
# - the ``UID`` iCal property (for Events, Todos, Journals)
|
||||||
# - the ``TZID`` iCal property (for Timezones)
|
# - the ``TZID`` iCal property (for Timezones)
|
||||||
if not self._name:
|
if not self._name:
|
||||||
for line in self.text.splitlines():
|
for line in self.text.splitlines():
|
||||||
@ -124,6 +124,11 @@ class Todo(Item):
|
|||||||
# pylint: enable=W0511
|
# pylint: enable=W0511
|
||||||
|
|
||||||
|
|
||||||
|
class Journal(Item):
|
||||||
|
"""Internal journal class."""
|
||||||
|
tag = "VJOURNAL"
|
||||||
|
|
||||||
|
|
||||||
class Timezone(Item):
|
class Timezone(Item):
|
||||||
"""Internal timezone class."""
|
"""Internal timezone class."""
|
||||||
tag = "VTIMEZONE"
|
tag = "VTIMEZONE"
|
||||||
@ -190,7 +195,8 @@ class Calendar(object):
|
|||||||
"""
|
"""
|
||||||
items = self.items
|
items = self.items
|
||||||
|
|
||||||
for new_item in self._parse(text, (Timezone, Event, Todo), name):
|
for new_item in self._parse(
|
||||||
|
text, (Timezone, Event, Todo, Journal), 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)
|
||||||
|
|
||||||
@ -198,10 +204,11 @@ class Calendar(object):
|
|||||||
|
|
||||||
def remove(self, name):
|
def remove(self, name):
|
||||||
"""Remove object named ``name`` from calendar."""
|
"""Remove object named ``name`` from calendar."""
|
||||||
todos = [todo for todo in self.todos if todo.name != name]
|
components = [
|
||||||
events = [event for event in self.events if event.name != name]
|
component for component in self.components
|
||||||
|
if component.name != name]
|
||||||
|
|
||||||
items = self.timezones + todos + events
|
items = self.timezones + components
|
||||||
self.write(items=items)
|
self.write(items=items)
|
||||||
|
|
||||||
def replace(self, name, text):
|
def replace(self, name, text):
|
||||||
@ -259,7 +266,12 @@ class Calendar(object):
|
|||||||
@property
|
@property
|
||||||
def items(self):
|
def items(self):
|
||||||
"""Get list of all items in calendar."""
|
"""Get list of all items in calendar."""
|
||||||
return self._parse(self.text, (Event, Todo, Timezone))
|
return self._parse(self.text, (Event, Todo, Journal, Timezone))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def components(self):
|
||||||
|
"""Get list of all components in calendar."""
|
||||||
|
return self._parse(self.text, (Event, Todo, Journal))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def events(self):
|
def events(self):
|
||||||
@ -271,6 +283,11 @@ class Calendar(object):
|
|||||||
"""Get list of ``Todo`` items in calendar."""
|
"""Get list of ``Todo`` items in calendar."""
|
||||||
return self._parse(self.text, (Todo,))
|
return self._parse(self.text, (Todo,))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def journals(self):
|
||||||
|
"""Get list of ``Journal`` items in calendar."""
|
||||||
|
return self._parse(self.text, (Journal,))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def timezones(self):
|
def timezones(self):
|
||||||
"""Get list of ``Timezome`` items in calendar."""
|
"""Get list of ``Timezome`` items in calendar."""
|
||||||
|
@ -101,7 +101,7 @@ def propfind(path, xml_request, calendar, depth):
|
|||||||
else:
|
else:
|
||||||
# depth is 1, infinity or not specified
|
# depth is 1, infinity or not specified
|
||||||
# we limit ourselves to depth == 1
|
# we limit ourselves to depth == 1
|
||||||
items = [calendar] + calendar.events + calendar.todos
|
items = [calendar] + calendar.components
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
|
|
||||||
@ -152,12 +152,10 @@ def propfind(path, xml_request, calendar, depth):
|
|||||||
tag.text = path
|
tag.text = path
|
||||||
element.append(tag)
|
element.append(tag)
|
||||||
elif tag == _tag("C", "supported-calendar-component-set"):
|
elif tag == _tag("C", "supported-calendar-component-set"):
|
||||||
comp = ET.Element(_tag("C", "comp"))
|
for component in ("VTODO", "VEVENT", "VJOURNAL"):
|
||||||
comp.set("name", "VTODO") # pylint: disable=W0511
|
comp = ET.Element(_tag("C", "comp"))
|
||||||
element.append(comp)
|
comp.set("name", component)
|
||||||
comp = ET.Element(_tag("C", "comp"))
|
element.append(comp)
|
||||||
comp.set("name", "VEVENT")
|
|
||||||
element.append(comp)
|
|
||||||
elif tag == _tag("D", "current-user-privilege-set"):
|
elif tag == _tag("D", "current-user-privilege-set"):
|
||||||
privilege = ET.Element(_tag("D", "privilege"))
|
privilege = ET.Element(_tag("D", "privilege"))
|
||||||
privilege.append(ET.Element(_tag("D", "all")))
|
privilege.append(ET.Element(_tag("D", "all")))
|
||||||
@ -227,7 +225,7 @@ def report(path, xml_request, calendar):
|
|||||||
else:
|
else:
|
||||||
# Reference is a calendar
|
# Reference is a calendar
|
||||||
path = hreference
|
path = hreference
|
||||||
items = calendar.events + calendar.todos
|
items = calendar.components
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
response = ET.Element(_tag("D", "response"))
|
response = ET.Element(_tag("D", "response"))
|
||||||
@ -248,7 +246,7 @@ def report(path, xml_request, calendar):
|
|||||||
if tag == _tag("D", "getetag"):
|
if tag == _tag("D", "getetag"):
|
||||||
element.text = item.etag
|
element.text = item.etag
|
||||||
elif tag == _tag("C", "calendar-data"):
|
elif tag == _tag("C", "calendar-data"):
|
||||||
if isinstance(item, (ical.Event, ical.Todo)):
|
if isinstance(item, (ical.Event, ical.Todo, ical.Journal)):
|
||||||
element.text = ical.serialize(
|
element.text = ical.serialize(
|
||||||
calendar.headers, calendar.timezones + [item])
|
calendar.headers, calendar.timezones + [item])
|
||||||
prop.append(element)
|
prop.append(element)
|
||||||
|
Loading…
Reference in New Issue
Block a user