diff --git a/src/agenda_culturel/calendar.py b/src/agenda_culturel/calendar.py index 809d75c..f508eb0 100644 --- a/src/agenda_culturel/calendar.py +++ b/src/agenda_culturel/calendar.py @@ -58,14 +58,14 @@ class DayInCalendar: def is_ancestor_uuid_event_from_other(self, event): for e in self.events: - if event.is_ancestor_by_uuid(e): + if event.is_ancestor_by_uuid_and_rules(e): return True return False def remove_event_with_ancestor_uuid_if_exists(self, event): removed = False for i, e in enumerate(self.events): - if e.is_ancestor_by_uuid(event): + if e.is_ancestor_by_uuid_and_rules(event): # remove e from events_by_category for k, v in self.events_by_category.items(): if e in v: diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index 9a9338b..44abc0d 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -2066,18 +2066,22 @@ class Event(models.Model): else: return ":".join(els), 0 - def is_ancestor_uuid(uuid1, uuid2): + def is_ancestor_uuid_and_rules(uuid1, uuid2, r1, r2): root1, version1 = Event.split_uuid(uuid1) root2, version2 = Event.split_uuid(uuid2) - return root1 == root2 and version1 < version2 + return root1 == root2 and ((r1 and not r2) or (version1 < version2)) - def is_ancestor_by_uuid(self, event): + def is_ancestor_by_uuid_and_rules(self, event): if self.uuids is None or event.uuids is None: return False + if (not self.recurrences) and event.recurrences: + return False for s_uuid in self.uuids: for e_uuid in event.uuids: - if Event.is_ancestor_uuid(s_uuid, e_uuid): + if Event.is_ancestor_uuid_and_rules( + s_uuid, e_uuid, self.recurrences, event.recurrences + ): return True return False