Skip to content
Snippets Groups Projects
Commit c741a2d0 authored by magicfelix's avatar magicfelix
Browse files

WIP: [DAV] Implement timezone conversion

parent 6a268449
No related branches found
No related tags found
1 merge request!1147Implement read-only CalDAV and CardDAV
Pipeline #195817 failed
......@@ -24,7 +24,7 @@ from django.utils.module_loading import import_string
import django_ical.feedgenerator as feedgenerator
import recurring_ical_events
from cache_memoize import cache_memoize
from icalendar import Calendar, Component, Event, Todo
from icalendar import Calendar, Component, Event, Timezone, Todo
if TYPE_CHECKING:
from django.contrib.contenttypes.models import ContentType
......@@ -561,6 +561,11 @@ class ExtendedICal20Feed(feedgenerator.ICal20Feed):
with_reference_object: bool = False,
params: dict[str, any] = None,
):
if params is not None and "timezone" in params:
tz = Timezone.from_ical(params["timezone"])
else:
tz = None
for item in self.items:
component_type = item.get("component_type")
element = Todo() if component_type == "todo" else Event()
......@@ -583,6 +588,18 @@ class ExtendedICal20Feed(feedgenerator.ICal20Feed):
elif ifield == "reference_object":
if with_reference_object:
element.add(efield, val, encode=False)
elif (
ifield == "start_datetime"
or ifield == "end_datetime"
or ifield == "timestamp"
or ifield == "created"
or ifield == "updateddate"
or ifield == "rdate"
or ifield == "exdate"
):
if tz is not None:
val = val.astimezone(tz.to_tz())
element.add(efield, val)
else:
element.add(efield, val)
calendar.add_component(element)
......
......@@ -7,7 +7,7 @@ from django.urls import reverse
from ..core_helpers import EXTENDED_ITEM_ELEMENT_FIELD_MAP
from .base import ElementHandler, QueryBase
from .generic import DAVHref
from .generic import DAVHref, DAVProp
class TimeRangeFilter(ElementHandler):
......@@ -202,7 +202,23 @@ class SupportedCollationSet(ElementHandler):
supported_collation.text = collation
class CalendarQuery(QueryBase, ElementHandler):
class Timezone(ElementHandler):
name = "{urn:ietf:params:xml:ns:caldav}timezone"
invisible = True
class ReportBase(QueryBase):
def post_handle(self):
super().post_handle()
if Timezone.name in self.children:
timezone = self.children.get(Timezone.name)
prop = self.children.get(DAVProp.name)
calendar_data = prop.children.get(CalendarData.name)
calendar_data.params["timezone"] = timezone.content
class CalendarQuery(ReportBase, ElementHandler):
name = "{urn:ietf:params:xml:ns:caldav}calendar-query"
def pre_handle(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment