ajustement pour dupliqués

This commit is contained in:
Jean-Marie Favreau 2024-04-28 13:47:15 +02:00
parent f92d62127b
commit 526e2d8d49
2 changed files with 22 additions and 13 deletions

View File

@ -568,7 +568,7 @@ class Event(models.Model):
def get_comparison(events):
result = []
for attr in Event.data_fields(all=True):
for attr in Event.data_fields(all=True, local_img=False):
values = [getattr(e, attr) for e in events]
values = ["" if v is None else v for v in values]
@ -614,14 +614,14 @@ class Event(models.Model):
Event.objects.bulk_update(elist, fields=["possibly_duplicated"])
def data_fields(all=False):
def data_fields(all=False, local_img=True):
if all:
result = ["category"]
else:
result = []
result += ["title", "location", "exact_location", "start_day", "start_time", "end_day", "end_time", "description", "image"]
if all:
if all and local_img:
result += ["local_image"]
result += ["image_alt", "reference_urls", "recurrences"]
if all:
@ -638,6 +638,15 @@ class Event(models.Model):
return [e for e in events if self.same_event_by_data(e)]
def find_last_imported(events):
events = [e for e in events if e.imported_date is not None]
if len(events) == 0:
return None
else:
events.sort(key=lambda e: e.imported_date, reverse=True)
return events[0]
def find_last_imported_not_modified(events):
events = [e for e in events if e.imported_date is not None and (e.modified_date is None or e.modified_date <= e.imported_date)]
if len(events) == 0:
@ -704,8 +713,11 @@ class Event(models.Model):
if len(same_events) != 0:
# check if one event has been imported and not modified in this list
same_imported = Event.find_last_imported_not_modified(same_events)
same_events_not_similar = [e for e in same_events if not e.similar(event)]
if same_imported or len(same_events_not_similar) == 0:
if not same_imported:
same_imported = Event.find_last_imported(same_events)
if same_imported:
# if this event exists, it will be updated with new data only if the data is fresher
if same_imported.modified_date < event.modified_date:
same_imported.update(event)
@ -713,13 +725,10 @@ class Event(models.Model):
same_imported.prepare_save()
to_update.append(same_imported)
else:
# 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)
# otherwise, 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()

View File

@ -43,7 +43,7 @@
<span>
{% if paginator_filter.has_previous %}
<a href="?page=1" role="button">&laquo; premier</a>
<a href="?page={{ paginator_filter.previous_page_number }}" role="button">précédent</a>
<a href="?page={{ paginator_filter.previous_page_number }}" role="button">&lt; précédent</a>
{% endif %}
<span>
@ -51,7 +51,7 @@
</span>
{% if paginator_filter.has_next %}
<a href="?page={{ paginator_filter.next_page_number }}" role="button">suivant</a>
<a href="?page={{ paginator_filter.next_page_number }}" role="button">suivant &gt;</a>
<a href="?page={{ paginator_filter.paginator.num_pages }}" role="button">dernier &raquo;</a>
{% endif %}
</span>