On affiche uniquement le dernier événement avec uuid semblable

This commit is contained in:
Jean-Marie Favreau 2024-02-18 12:52:19 +01:00
parent cb818e3081
commit f4416dd4e7
2 changed files with 22 additions and 10 deletions

View File

@ -38,16 +38,16 @@ class DayInCalendar:
def is_today(self):
return self.today
def is_generic_uuid_event_from_other(self, event):
def is_ancestor_uuid_event_from_other(self, event):
for e in self.events:
if event.is_generic_by_uuid(e):
if event.is_ancestor_by_uuid(e):
return True
return False
def remove_event_with_generic_uuid_if_exists(self, event):
def remove_event_with_ancestor_uuid_if_exists(self, event):
removed = False
for i, e in enumerate(self.events):
if e.is_generic_by_uuid(event):
if e.is_ancestor_by_uuid(event):
# remove e from events_by_category
for k, v in self.events_by_category.items():
if e in v:
@ -63,11 +63,11 @@ class DayInCalendar:
def add_event(self, event):
if event.contains_date(self.date):
if self.is_generic_uuid_event_from_other(event):
if self.is_ancestor_uuid_event_from_other(event):
# we do not add a generic event if a specific is already present
pass
else:
self.remove_event_with_generic_uuid_if_exists(event)
self.remove_event_with_ancestor_uuid_if_exists(event)
self._add_event_internal(event)

View File

@ -474,16 +474,28 @@ class Event(models.Model):
return None if self.uuids is None or len(self.uuids) == 0 else Event.objects.filter(uuids__contains=self.uuids)
def is_generic_uuid(uuid1, uuid2):
return uuid1 != "" and uuid2.startswith(uuid1)
def split_uuid(uuid):
els = uuid.split(':')
if len(els) == 1:
return ":".join(els[0:-1]), 0
else:
if els[-1].isdigit():
return ":".join(els[0:-1]), int(els[-1])
else:
return ":".join(els), 0
def is_generic_by_uuid(self, event):
def is_ancestor_uuid(uuid1, uuid2):
root1, version1 = Event.split_uuid(uuid1)
root2, version2 = Event.split_uuid(uuid2)
return root1 == root2 and version1 < version2
def is_ancestor_by_uuid(self, event):
if self.uuids is None or event.uuids is None:
return False
for s_uuid in self.uuids:
for e_uuid in event.uuids:
if Event.is_generic_uuid(s_uuid, e_uuid):
if Event.is_ancestor_uuid(s_uuid, e_uuid):
return True
return False