From 10af7f55ead90fdf9dd199e03136b57bcd59accd Mon Sep 17 00:00:00 2001 From: Christian Geier Date: Wed, 22 Jun 2022 10:08:37 +0200 Subject: [PATCH] WIP --- khal/controllers.py | 6 +++++- khal/icalendar.py | 12 ++++++++++++ tests/icalendar_test.py | 12 +++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/khal/controllers.py b/khal/controllers.py index 83ed64d46..92947964a 100644 --- a/khal/controllers.py +++ b/khal/controllers.py @@ -643,7 +643,11 @@ def import_event(vevent, collection, locale, batch, format=None, env=None): if batch or confirm(f"Do you want to import this event into `{calendar_name}`?"): try: collection.new(Item(vevent), collection=calendar_name) - except DuplicateUid: + except DuplicateUid as error: + uid = str(error) + existing_event = collection.get_event(href=uid, calendar=calendar_name) + if existing_event.recurring: + breakpoint() if batch or confirm( "An event with the same UID already exists. Do you want to update it?"): collection.force_update(Item(vevent), collection=calendar_name) diff --git a/khal/icalendar.py b/khal/icalendar.py index d91b9872d..cbc74947a 100644 --- a/khal/icalendar.py +++ b/khal/icalendar.py @@ -502,6 +502,18 @@ def delete_instance(vevent, instance): vevent.add('RDATE', rdates) +def edit_instance(vevents, instance): + """add `instance` to vevents + + if an instance with that recuid already exists, replace it. Also make sure, + that recuid is not excluded + """ + + + + return vevents + + def sort_key(vevent): """helper function to determine order of VEVENTS so that recurrence-id events come after the corresponding rrule event, etc diff --git a/tests/icalendar_test.py b/tests/icalendar_test.py index ebfaf97df..1167bd441 100644 --- a/tests/icalendar_test.py +++ b/tests/icalendar_test.py @@ -3,7 +3,7 @@ import icalendar -from khal.icalendar import split_ics +from khal.icalendar import split_ics, edit_instance from .utils import LOCALE_BERLIN, _get_text, normalize_component @@ -87,3 +87,13 @@ def test_split_ics_without_uid(): assert vevents vevents2 = split_ics(cal) assert vevents[0] == vevents2[0] + + +def test_edit_instance(): + """test if adding a recuid instance to a recurring event works""" + cal = icalendar.Calendar.from_ical(_get_text("event_rrule")) + instance = icalendar.Calendar.from_ical(_get_text("event_rrule_recuid_instance_only")) + breakpoint() + + + updated_instance = edit_instance(cal, instance)