on n'ajoute pas les événements similaires
This commit is contained in:
parent
edbbb4597f
commit
59b093340d
@ -145,18 +145,8 @@ class DuplicatedEvents(models.Model):
|
|||||||
g.merge_into(result)
|
g.merge_into(result)
|
||||||
return 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):
|
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):
|
class Place(models.Model):
|
||||||
name = models.CharField(verbose_name=_('Name'), help_text=_('Name of the place'))
|
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)
|
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):
|
def set_possibly_duplicated(self, events):
|
||||||
|
|
||||||
# get existing groups
|
# get existing groups
|
||||||
@ -696,7 +706,10 @@ class Event(models.Model):
|
|||||||
same_imported.prepare_save()
|
same_imported.prepare_save()
|
||||||
to_update.append(same_imported)
|
to_update.append(same_imported)
|
||||||
else:
|
else:
|
||||||
# otherwise, the new event possibly a duplication of the others.
|
# 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)
|
event.set_possibly_duplicated(same_events)
|
||||||
# it will be imported
|
# it will be imported
|
||||||
to_import.append(event)
|
to_import.append(event)
|
||||||
@ -1026,7 +1039,6 @@ class ModerationAnswer(models.Model):
|
|||||||
if not self.removes_tags:
|
if not self.removes_tags:
|
||||||
self.removes_tags = []
|
self.removes_tags = []
|
||||||
|
|
||||||
logger.info('on applique la réponse ' + self.answer)
|
|
||||||
if event.tags:
|
if event.tags:
|
||||||
event.tags = list((set(event.tags) | set(self.adds_tags)) - set(self.removes_tags))
|
event.tags = list((set(event.tags) | set(self.adds_tags)) - set(self.removes_tags))
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user