ajustement pour dupliqués
This commit is contained in:
parent
f92d62127b
commit
526e2d8d49
@ -568,7 +568,7 @@ class Event(models.Model):
|
|||||||
|
|
||||||
def get_comparison(events):
|
def get_comparison(events):
|
||||||
result = []
|
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 = [getattr(e, attr) for e in events]
|
||||||
values = ["" if v is None else v for v in values]
|
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"])
|
Event.objects.bulk_update(elist, fields=["possibly_duplicated"])
|
||||||
|
|
||||||
|
|
||||||
def data_fields(all=False):
|
def data_fields(all=False, local_img=True):
|
||||||
if all:
|
if all:
|
||||||
result = ["category"]
|
result = ["category"]
|
||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
result += ["title", "location", "exact_location", "start_day", "start_time", "end_day", "end_time", "description", "image"]
|
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 += ["local_image"]
|
||||||
result += ["image_alt", "reference_urls", "recurrences"]
|
result += ["image_alt", "reference_urls", "recurrences"]
|
||||||
if all:
|
if all:
|
||||||
@ -638,6 +638,15 @@ class Event(models.Model):
|
|||||||
return [e for e in events if self.same_event_by_data(e)]
|
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):
|
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)]
|
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:
|
if len(events) == 0:
|
||||||
@ -704,8 +713,11 @@ class Event(models.Model):
|
|||||||
if len(same_events) != 0:
|
if len(same_events) != 0:
|
||||||
# check if one event has been imported and not modified in this list
|
# check if one event has been imported and not modified in this list
|
||||||
same_imported = Event.find_last_imported_not_modified(same_events)
|
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 this event exists, it will be updated with new data only if the data is fresher
|
||||||
if same_imported.modified_date < event.modified_date:
|
if same_imported.modified_date < event.modified_date:
|
||||||
same_imported.update(event)
|
same_imported.update(event)
|
||||||
@ -713,13 +725,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, we remove all same event similar to the current one
|
# otherwise, the new event possibly a duplication of the remaining others.
|
||||||
same_events = [e for e in same_events if not e.similar(event)]
|
event.set_possibly_duplicated(same_events)
|
||||||
if len(same_events) > 0:
|
# it will be imported
|
||||||
# the new event possibly a duplication of the remaining others.
|
to_import.append(event)
|
||||||
event.set_possibly_duplicated(same_events)
|
|
||||||
# it will be imported
|
|
||||||
to_import.append(event)
|
|
||||||
else:
|
else:
|
||||||
# if uuid is unique (or not available), check for similar events
|
# if uuid is unique (or not available), check for similar events
|
||||||
similar_events = event.find_similar_events()
|
similar_events = event.find_similar_events()
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<span>
|
<span>
|
||||||
{% if paginator_filter.has_previous %}
|
{% if paginator_filter.has_previous %}
|
||||||
<a href="?page=1" role="button">« premier</a>
|
<a href="?page=1" role="button">« 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">< précédent</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<span>
|
<span>
|
||||||
@ -51,7 +51,7 @@
|
|||||||
</span>
|
</span>
|
||||||
|
|
||||||
{% if paginator_filter.has_next %}
|
{% 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 ></a>
|
||||||
<a href="?page={{ paginator_filter.paginator.num_pages }}" role="button">dernier »</a>
|
<a href="?page={{ paginator_filter.paginator.num_pages }}" role="button">dernier »</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user