Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
geier committed Jun 24, 2022
1 parent 573f85f commit 10af7f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion khal/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions khal/icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion tests/icalendar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 10af7f5

Please sign in to comment.