diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index 96bb067..6a77e61 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -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() diff --git a/src/agenda_culturel/templates/agenda_culturel/duplicates.html b/src/agenda_culturel/templates/agenda_culturel/duplicates.html index 0b2f16c..d561a01 100644 --- a/src/agenda_culturel/templates/agenda_culturel/duplicates.html +++ b/src/agenda_culturel/templates/agenda_culturel/duplicates.html @@ -43,7 +43,7 @@ {% if paginator_filter.has_previous %} « premier - précédent + < précédent {% endif %} @@ -51,7 +51,7 @@ {% if paginator_filter.has_next %} - suivant + suivant > dernier » {% endif %}