On ne met à jour que si la date de l'import est plus récente
This commit is contained in:
		@@ -15,7 +15,10 @@ from django.db.models import Q
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
@@ -257,7 +260,7 @@ class Event(models.Model):
 | 
			
		||||
            self.created_date = now
 | 
			
		||||
        if self.is_in_importation_process():
 | 
			
		||||
            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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -311,10 +314,13 @@ class Event(models.Model):
 | 
			
		||||
            del event_structure["url_human"]
 | 
			
		||||
 | 
			
		||||
        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"]
 | 
			
		||||
        else:
 | 
			
		||||
            event_structure["created_date"] = None
 | 
			
		||||
            event_structure["modified_date"] = None
 | 
			
		||||
 | 
			
		||||
        if "start_time" in event_structure:
 | 
			
		||||
            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)
 | 
			
		||||
 | 
			
		||||
                if same_imported:
 | 
			
		||||
                    # if this event exists, it will be updated with new data
 | 
			
		||||
                    same_imported.update(event)
 | 
			
		||||
                    same_imported.set_in_importation_process()
 | 
			
		||||
                    same_imported.prepare_save()
 | 
			
		||||
                    to_update.append(same_imported)
 | 
			
		||||
                    # if this event exists, it will be updated with new data only if the data is fresher
 | 
			
		||||
                    logger.warning("{} vs {}".format(same_imported.modified_date, event.modified_date))
 | 
			
		||||
                    if same_imported.modified_date < event.modified_date:
 | 
			
		||||
                        same_imported.update(event)
 | 
			
		||||
                        same_imported.set_in_importation_process()
 | 
			
		||||
                        same_imported.prepare_save()
 | 
			
		||||
                        to_update.append(same_imported)
 | 
			
		||||
                else:
 | 
			
		||||
                    # otherwise, the new event possibly a duplication of the others.
 | 
			
		||||
                    event.set_possibly_duplicated(same_events)
 | 
			
		||||
@@ -475,6 +483,7 @@ class Event(models.Model):
 | 
			
		||||
        nb_removed = 0
 | 
			
		||||
        if remove_missing:
 | 
			
		||||
            # events that are missing from the import but in database are turned into drafts
 | 
			
		||||
            # only if they are in the future
 | 
			
		||||
            # TODO
 | 
			
		||||
            # TODO: ajouter self.source, ou faire référence à l'objet BatchImportation
 | 
			
		||||
            pass
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user