From 5ce989a6482600a55257a2e9e19d4888c40f3b50 Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Thu, 26 Jan 2023 19:33:01 +0100 Subject: [PATCH] Let tasks have NEEDS-ACTION as default status when creating them (sort of a workaround for DAViCal) --- caldav/lib/vcal.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/caldav/lib/vcal.py b/caldav/lib/vcal.py index 9cf6f78f..2a976dc2 100644 --- a/caldav/lib/vcal.py +++ b/caldav/lib/vcal.py @@ -142,6 +142,16 @@ def create_ical(ical_fragment=None, objtype=None, language="en_DK", **props): if not props.get("uid") and not "\nUID:" in (ical_fragment or ""): component.add("uid", uuid.uuid1()) my_instance.add_component(component) + ## STATUS should default to NEEDS-ACTION for tasks, if it's not set + ## (otherwise we cannot easily add a task to a davical calendar and + ## then find it again - ref https://gitlab.com/davical-project/davical/-/issues/281 + if ( + not props.get("STATUS") + and not "\nSTATUS:" in (ical_fragment or "") + and objtype == "VTODO" + ): + props["STATUS"] = "NEEDS-ACTION" + else: if not ical_fragment.strip().startswith("BEGIN:VCALENDAR"): ical_fragment = ( @@ -152,6 +162,7 @@ def create_ical(ical_fragment=None, objtype=None, language="en_DK", **props): my_instance = icalendar.Calendar.from_ical(ical_fragment) component = my_instance.subcomponents[0] ical_fragment = None + for prop in props: if props[prop] is not None: if isinstance(props[prop], datetime.datetime) and not props[prop].tzinfo: