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

Edit a single occurence of a recurrent event #379

Open
julien4215 opened this issue Feb 5, 2024 · 8 comments
Open

Edit a single occurence of a recurrent event #379

julien4215 opened this issue Feb 5, 2024 · 8 comments

Comments

@julien4215
Copy link

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.

@tobixen
Copy link
Member

tobixen commented Feb 5, 2024

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.

@julien4215
Copy link
Author

julien4215 commented Feb 5, 2024

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()

@tobixen
Copy link
Member

tobixen commented Feb 5, 2024

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.

@julien4215
Copy link
Author

Sure, I understand. Thank you for your quick answer.

@tobixen
Copy link
Member

tobixen commented Feb 5, 2024

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:

  • Fetch the canonical event (i.e. e = calendar.event_by_uid(...)).
  • The event you get is actually a big icalendar object containing the recurring event (the "template" so to say) and then any special recurrences that have been edited.
  • Do not use 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.
  • Then 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.

@julien4215
Copy link
Author

Thanks a lot for the explanations ! I will try this solution.

@julien4215
Copy link
Author

julien4215 commented Feb 5, 2024

It worked !
Just to clarify if someone faces the same issue.

  1. There is a typo in the property, it is recurrence-id.

  2. 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.

@tobixen
Copy link
Member

tobixen commented Feb 5, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants