on n'ajoute pas les événements similaires

This commit is contained in:
Jean-Marie Favreau 2024-04-28 11:55:34 +02:00
parent edbbb4597f
commit 59b093340d

View File

@ -145,18 +145,8 @@ class DuplicatedEvents(models.Model):
g.merge_into(result)
return result
def get_item_comparison(self, attr):
values = [getattr(e, attr) for e in self.get_duplicated()]
values = ["" if v is None else v for v in values]
if len(set([str(v) for v in values])) == 1:
return { "similar": True, "key": attr, "values": values[0] }
else:
return { "similar": False, "key": attr, "values": values }
def get_items_comparison(self):
return [self.get_item_comparison(e) for e in Event.data_fields(all=True)]
return Event.get_comparison(self.get_duplicated())
class Place(models.Model):
name = models.CharField(verbose_name=_('Name'), help_text=_('Name of the place'))
@ -569,6 +559,26 @@ class Event(models.Model):
return Event.objects.filter(possibly_duplicated=self.possibly_duplicated).exclude(pk=self.pk)
def get_comparison(events):
result = []
for attr in Event.data_fields(all=True):
values = [getattr(e, attr) for e in events]
values = ["" if v is None else v for v in values]
if len(set([str(v) for v in values])) == 1:
result.append({"similar": True, "key": attr, "values": values[0]})
else:
result.append({"similar": False, "key": attr, "values": values})
return result
def similar(self, event):
res = Event.get_comparison([self, event])
for r in res:
if not r["similar"]:
return False
return True
def set_possibly_duplicated(self, events):
# get existing groups
@ -696,10 +706,13 @@ class Event(models.Model):
same_imported.prepare_save()
to_update.append(same_imported)
else:
# otherwise, the new event possibly a duplication of the others.
event.set_possibly_duplicated(same_events)
# it will be imported
to_import.append(event)
# otherwise, we remove all same event similar to the current one
same_events = [e for e in same_events if not e.similar(event)]
if len(same_events) > 0:
# the new event possibly a duplication of the remaining others.
event.set_possibly_duplicated(same_events)
# it will be imported
to_import.append(event)
else:
# if uuid is unique (or not available), check for similar events
similar_events = event.find_similar_events()
@ -1026,7 +1039,6 @@ class ModerationAnswer(models.Model):
if not self.removes_tags:
self.removes_tags = []
logger.info('on applique la réponse ' + self.answer)
if event.tags:
event.tags = list((set(event.tags) | set(self.adds_tags)) - set(self.removes_tags))
else: