Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Better support for recurrence instances #1143

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 edit_instance, split_ics

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)