Amélioration de l'importation par url, on détecte les possibles doublons après import
This commit is contained in:
parent
772a0a5854
commit
ae6d73cfb0
@ -245,13 +245,19 @@ class Event(models.Model):
|
||||
self.local_image = File(name=basename, file=open(tmpfile, "rb"))
|
||||
|
||||
|
||||
def is_in_importation_process(self):
|
||||
return hasattr(self, "in_importation_process")
|
||||
|
||||
def set_in_importation_process(self):
|
||||
self.in_importation_process = True
|
||||
|
||||
def update_dates(self):
|
||||
now = timezone.now()
|
||||
if not self.id:
|
||||
self.created_date = now
|
||||
if hasattr(self, "require_imported_date"):
|
||||
if self.is_in_importation_process():
|
||||
self.imported_date = now
|
||||
if not hasattr(self, "require_imported_date") or self.modified_date is None:
|
||||
if self.is_in_importation_process() or self.modified_date is None:
|
||||
self.modified_date = now
|
||||
|
||||
|
||||
@ -267,8 +273,18 @@ class Event(models.Model):
|
||||
|
||||
self.prepare_save()
|
||||
|
||||
# check for similar events if no duplicated is known
|
||||
if self.possibly_duplicated is None:
|
||||
# and if this is not an importation process
|
||||
if not self.is_in_importation_process():
|
||||
similar_events = self.find_similar_events()
|
||||
|
||||
# if it exists similar events, add this relation to the event
|
||||
if len(similar_events) != 0:
|
||||
self.set_possibly_duplicated(similar_events)
|
||||
|
||||
elif self.possibly_duplicated is not None and self.possibly_duplicated.nb_duplicated() == 1:
|
||||
# delete duplicated group if it's only with one element
|
||||
if self.possibly_duplicated is not None and self.possibly_duplicated.nb_duplicated() == 1:
|
||||
self.possibly_duplicated.delete()
|
||||
self.possibly_duplicated = None
|
||||
|
||||
@ -408,7 +424,7 @@ class Event(models.Model):
|
||||
# for each event, check if it's a new one, or a one to be updated
|
||||
for event in events:
|
||||
# imported events should be updated
|
||||
event.require_imported_date = True
|
||||
event.set_in_importation_process()
|
||||
event.prepare_save()
|
||||
|
||||
# check if the event has already be imported (using uuid)
|
||||
@ -421,7 +437,7 @@ class Event(models.Model):
|
||||
if same_imported:
|
||||
# if this event exists, it will be updated with new data
|
||||
same_imported.update(event)
|
||||
same_imported.require_imported_date = True
|
||||
same_imported.set_in_importation_process()
|
||||
same_imported.prepare_save()
|
||||
to_update.append(same_imported)
|
||||
else:
|
||||
@ -441,7 +457,7 @@ class Event(models.Model):
|
||||
if same_events is not None and len(same_events) > 0:
|
||||
# merge with the first one
|
||||
same_events[0].update(event)
|
||||
same_events[0].require_imported_date = True
|
||||
same_events[0].set_in_importation_process()
|
||||
same_events[0].prepare_save()
|
||||
to_update.append(same_events[0])
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user