Only reopen a duplicatedevent if data is different (not tags or categories)
This commit is contained in:
parent
305136d963
commit
45ed0d8828
@ -1078,9 +1078,9 @@ class Event(models.Model):
|
|||||||
def masked(self):
|
def masked(self):
|
||||||
return self.other_versions and self.other_versions.representative != self
|
return self.other_versions and self.other_versions.representative != self
|
||||||
|
|
||||||
def get_comparison(events):
|
def get_comparison(events, all=True):
|
||||||
result = []
|
result = []
|
||||||
for attr in Event.data_fields(local_img=False, exact_location=False):
|
for attr in Event.data_fields(all=all, local_img=False, exact_location=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]
|
||||||
values = [[] if attr == "tags" and v == "" else v for v in values]
|
values = [[] if attr == "tags" and v == "" else v for v in values]
|
||||||
@ -1096,8 +1096,8 @@ class Event(models.Model):
|
|||||||
result.append({"similar": False, "key": attr, "values": values})
|
result.append({"similar": False, "key": attr, "values": values})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def similar(self, event):
|
def similar(self, event, all=True):
|
||||||
res = Event.get_comparison([self, event])
|
res = Event.get_comparison([self, event], all)
|
||||||
for r in res:
|
for r in res:
|
||||||
if not r["similar"]:
|
if not r["similar"]:
|
||||||
return False
|
return False
|
||||||
@ -1132,10 +1132,16 @@ class Event(models.Model):
|
|||||||
elist = list(events) + ([self] if self.pk is not None else [])
|
elist = list(events) + ([self] if self.pk is not None else [])
|
||||||
Event.objects.bulk_update(elist, fields=["other_versions"])
|
Event.objects.bulk_update(elist, fields=["other_versions"])
|
||||||
|
|
||||||
def data_fields(local_img=True, exact_location=True):
|
def data_fields(local_img=True, exact_location=True, all=True):
|
||||||
result = [
|
result = []
|
||||||
"category",
|
|
||||||
"tags",
|
if all:
|
||||||
|
result += [
|
||||||
|
"category",
|
||||||
|
"tags",
|
||||||
|
]
|
||||||
|
|
||||||
|
result += [
|
||||||
"title",
|
"title",
|
||||||
"location",
|
"location",
|
||||||
"start_day",
|
"start_day",
|
||||||
@ -1226,13 +1232,13 @@ class Event(models.Model):
|
|||||||
# if not, we check if it does not match exactly with another
|
# if not, we check if it does not match exactly with another
|
||||||
if not same_imported:
|
if not same_imported:
|
||||||
for e in same_events:
|
for e in same_events:
|
||||||
if event.similar(e):
|
if event.similar(e, False):
|
||||||
same_imported = e
|
same_imported = e
|
||||||
break
|
break
|
||||||
|
|
||||||
if same_imported:
|
if same_imported:
|
||||||
# reopen DuplicatedEvents if required
|
# reopen DuplicatedEvents if required
|
||||||
if not event.similar(same_imported) and same_imported.other_versions:
|
if not event.similar(same_imported, False) and same_imported.other_versions:
|
||||||
if same_imported.status != Event.STATUS.TRASH:
|
if same_imported.status != Event.STATUS.TRASH:
|
||||||
if same_imported.other_versions.is_published():
|
if same_imported.other_versions.is_published():
|
||||||
if same_imported.other_versions.representative != same_imported:
|
if same_imported.other_versions.representative != same_imported:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user