Open julien4215 opened 8 months ago
No, editing a single instance is more trivial than deleting a single instance. As for now there is no explicit way of doing it in the caldav library (arguably it's outside the scope of the caldav library since this is more in the icalendar layer than the caldav layer - but usability beats purity, so I would be willing to accept a pull request on that if it's done in a good way).
I think the best way to do this is to use calendar.search(begin=..., end=..., expand=True)
to find the recurrence instance you want to edit - then when you got it, you may edit it and save it back to the calendar. The server should take care that only that instance is affected.
I tried to do this with Nextcloud calendar but when I save the single occurence I edited, it deletes the recurrence event and keeps only the single ocurrence.
Here is the code I used
with caldav.DAVClient(url=url, username=username, password=password) as client:
calendar = client.calendar(url=calendar_url)
now = datetime.now()
events_fetched = calendar.search(start=now, end=now+timedelta(days=5), event=True, expand=True)
e = events_fetched[0]
e.icalendar_component["description"] = "Some description"
e.save()
I should write up some test code for this and see how different servers behave. Unfortunately I can't promise that I will have time for it anytime soon.
Sure, I understand. Thank you for your quick answer.
I came to think on some things ...
1) Please ensure that there exists a property e.icalendar_component['recurrence_id']
. If that one is missing, then for sure it's a client side problem.
2) The correct and safe way to edit a recurrence instance on is probably like this:
e = calendar.event_by_uid(...)
).e.icalendar_component
. It's convenient in the very most cases, but it will ignore the existance of recurrences (but they shouldn't be deleted from the calendar anyway). All the data is available in list format under e.icalendar_instance.subcomponents
. If the recurrence instance you want to edit does not exist there, you have to make it yourself and append it to that list.e.save()
.I leave this open, because ... probably, this is the only correct way to edit recurring instances, and if so, then the library should do that work. I will have to write tests and run it towards different servers and investigate.
Lots of work - and fairly low priority from my side, but if nothing else I think I have a plan for how to deal with it.
Thanks a lot for the explanations ! I will try this solution.
It worked ! Just to clarify if someone faces the same issue.
There is a typo in the property, it is recurrence-id
.
It shouldn't be missing on the recurrence instance (events obtained by expanding the recurrence) but there is no recurrence-id
property for the recurrence event.
Right, I made a mistake in the post above, of course there should be no underscore in RECURRENCE-ID
(capital letters according to the standard, but the icalendar library is case insensitive)
Is it possible to edit a single occurrence of a recurrent event ? I couldn't find a solution.
I guess this is linked to the issue #35.