Default implementation for BaseCollection.serialize

This commit is contained in:
Unrud 2017-06-09 02:29:55 +02:00 committed by Unrud
parent 47d311b101
commit dbd06a1952

View File

@ -504,7 +504,16 @@ class BaseCollection:
def serialize(self):
"""Get the unicode string representing the whole collection."""
raise NotImplementedError
if self.get_meta("tag") == "VCALENDAR":
collection = vobject.iCalendar()
for item in self.get_all():
for content in ("vevent", "vtodo", "vjournal"):
for component in getattr(item, "%s_list" % content, ()):
collection.add(component)
return collection.serialize()
elif self.get_meta("tag") == "VADDRESSBOOK":
return "".join(item.serialize() for item in self.get_all())
return ""
@classmethod
@contextmanager