agendas: rewrite recurrence creation (#74105)

This commit is contained in:
Lauréline Guérin 2023-02-02 14:22:31 +01:00 committed by Gitea
parent c78147d283
commit d994258018
1 changed files with 5 additions and 5 deletions

View File

@ -1933,16 +1933,16 @@ class Event(models.Model):
@classmethod
def create_events_recurrences(cls, events):
recurrences = []
for event in events:
if event.recurrence_end_date:
max_datetime = datetime.datetime.combine(event.recurrence_end_date, datetime.time(0, 0))
else:
max_datetime = make_naive(now() + datetime.timedelta(days=365))
recurrences.extend(
event.get_recurrences(localtime(event.start_datetime), make_aware(max_datetime))
)
Event.objects.bulk_create(recurrences, ignore_conflicts=True)
existing_recurrences = event.recurrences.values_list('slug', flat=True)
all_recurrences = event.get_recurrences(localtime(event.start_datetime), make_aware(max_datetime))
recurrences_to_create = [r for r in all_recurrences if r.slug not in existing_recurrences]
if recurrences_to_create:
Event.objects.bulk_create(recurrences_to_create, ignore_conflicts=True)
@property
def datetime_slug(self):