sharing/bday: add hook for conversion
This commit is contained in:
@@ -25,6 +25,7 @@ Take a look at the class ``BaseCollection`` if you want to implement your own.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from typing import (Callable, ContextManager, Dict, Iterable, Iterator, List,
|
from typing import (Callable, ContextManager, Dict, Iterable, Iterator, List,
|
||||||
@@ -223,7 +224,7 @@ class BaseCollection:
|
|||||||
"""Get the HTTP-datetime of when the collection was modified."""
|
"""Get the HTTP-datetime of when the collection was modified."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def serialize(self) -> str:
|
def serialize(self, vcf_to_ics: bool = False) -> str:
|
||||||
"""Get the unicode string representing the whole collection."""
|
"""Get the unicode string representing the whole collection."""
|
||||||
if self.tag == "VCALENDAR":
|
if self.tag == "VCALENDAR":
|
||||||
in_vcalendar = False
|
in_vcalendar = False
|
||||||
@@ -282,6 +283,22 @@ class BaseCollection:
|
|||||||
vtimezones + components +
|
vtimezones + components +
|
||||||
template[template_insert_pos:])
|
template[template_insert_pos:])
|
||||||
if self.tag == "VADDRESSBOOK":
|
if self.tag == "VADDRESSBOOK":
|
||||||
|
if vcf_to_ics:
|
||||||
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
|
logger.debug("TRACE/storage: convert VCF to ICS")
|
||||||
|
|
||||||
|
items = []
|
||||||
|
for item in self.get_all():
|
||||||
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
|
logger.debug("TRACE/storage/convert VCF to ICS: %r:", item)
|
||||||
|
item_ics = item.convert_vcf_to_ics()
|
||||||
|
if item_ics is None:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
items.append(item_ics.vobject_item)
|
||||||
|
return "".join((item.serialize() for item in items))
|
||||||
|
else:
|
||||||
return "".join((item.serialize() for item in self.get_all()))
|
return "".join((item.serialize() for item in self.get_all()))
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user