On ne met à jour que si la date de l'import est plus récente
This commit is contained in:
parent
5b64d06db1
commit
7d48d74ba3
@ -15,7 +15,10 @@ from django.db.models import Q
|
|||||||
|
|
||||||
|
|
||||||
from django.template.defaultfilters import date as _date
|
from django.template.defaultfilters import date as _date
|
||||||
from datetime import datetime, time, timedelta
|
from datetime import time, timedelta
|
||||||
|
from django.utils.timezone import datetime
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
from .calendar import CalendarList
|
from .calendar import CalendarList
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -257,7 +260,7 @@ class Event(models.Model):
|
|||||||
self.created_date = now
|
self.created_date = now
|
||||||
if self.is_in_importation_process():
|
if self.is_in_importation_process():
|
||||||
self.imported_date = now
|
self.imported_date = now
|
||||||
if self.is_in_importation_process() or self.modified_date is None:
|
if self.modified_date is None:
|
||||||
self.modified_date = now
|
self.modified_date = now
|
||||||
|
|
||||||
|
|
||||||
@ -311,10 +314,13 @@ class Event(models.Model):
|
|||||||
del event_structure["url_human"]
|
del event_structure["url_human"]
|
||||||
|
|
||||||
if "last_modified" in event_structure and event_structure["last_modified"] is not None:
|
if "last_modified" in event_structure and event_structure["last_modified"] is not None:
|
||||||
event_structure["modified_date"] = event_structure["last_modified"]
|
d = datetime.fromisoformat(event_structure["last_modified"])
|
||||||
|
if d.tzinfo is None or d.tzinfo.utcoffset(d) is None:
|
||||||
|
d = timezone.make_aware(d, timezone.get_default_timezone())
|
||||||
|
event_structure["modified_date"] = d
|
||||||
del event_structure["last_modified"]
|
del event_structure["last_modified"]
|
||||||
else:
|
else:
|
||||||
event_structure["created_date"] = None
|
event_structure["modified_date"] = None
|
||||||
|
|
||||||
if "start_time" in event_structure:
|
if "start_time" in event_structure:
|
||||||
event_structure["start_time"] = time.fromisoformat(event_structure["start_time"])
|
event_structure["start_time"] = time.fromisoformat(event_structure["start_time"])
|
||||||
@ -435,11 +441,13 @@ class Event(models.Model):
|
|||||||
same_imported = Event.find_last_imported_not_modified(same_events)
|
same_imported = Event.find_last_imported_not_modified(same_events)
|
||||||
|
|
||||||
if same_imported:
|
if same_imported:
|
||||||
# if this event exists, it will be updated with new data
|
# if this event exists, it will be updated with new data only if the data is fresher
|
||||||
same_imported.update(event)
|
logger.warning("{} vs {}".format(same_imported.modified_date, event.modified_date))
|
||||||
same_imported.set_in_importation_process()
|
if same_imported.modified_date < event.modified_date:
|
||||||
same_imported.prepare_save()
|
same_imported.update(event)
|
||||||
to_update.append(same_imported)
|
same_imported.set_in_importation_process()
|
||||||
|
same_imported.prepare_save()
|
||||||
|
to_update.append(same_imported)
|
||||||
else:
|
else:
|
||||||
# otherwise, the new event possibly a duplication of the others.
|
# otherwise, the new event possibly a duplication of the others.
|
||||||
event.set_possibly_duplicated(same_events)
|
event.set_possibly_duplicated(same_events)
|
||||||
@ -475,6 +483,7 @@ class Event(models.Model):
|
|||||||
nb_removed = 0
|
nb_removed = 0
|
||||||
if remove_missing:
|
if remove_missing:
|
||||||
# events that are missing from the import but in database are turned into drafts
|
# events that are missing from the import but in database are turned into drafts
|
||||||
|
# only if they are in the future
|
||||||
# TODO
|
# TODO
|
||||||
# TODO: ajouter self.source, ou faire référence à l'objet BatchImportation
|
# TODO: ajouter self.source, ou faire référence à l'objet BatchImportation
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user