Factorisation

This commit is contained in:
Jean-Marie Favreau 2024-11-09 14:32:21 +01:00
parent b66f428a0e
commit 4733bb3eec
2 changed files with 16 additions and 10 deletions

View File

@ -177,7 +177,7 @@ class FixDuplicates(Form):
)
]
extra = ""
if len([e for e in events if e.modified()]) != 0:
if edup.has_modified():
extra = _(" Warning: a version is already locally modified.")
choices += [
("Merge", _("Create a new version by merging.") + extra)

View File

@ -237,6 +237,20 @@ class DuplicatedEvents(models.Model):
def fixed(self):
return not self.representative is None
def has_modified(self):
return len([e for e in self.get_duplicated() if e.modified()]) > 0
def get_local_version(self):
if self.representative and self.representative.modified():
return self.representative
l = [e for e in self.get_duplicated() if e.modified()]
if len(l) == 0:
return None
else:
l.sort(key=lambda x: -x.modified_date)
return l[0]
def merge_into(self, other):
# for all objects associated to this group
for e in self.get_duplicated():
@ -668,15 +682,7 @@ class Event(models.Model):
if self.other_versions is None:
return None
# otherwise check the representative version
if not self.other_versions.representative is None:
if self.other_versions.representative.modified():
return self.other_versions.representative
# finally, get the last modified version within the other versions
e = [e for e in self.other_versions.event_set.order_by("-modified_date") if e.modified]
return None if len(e) == 0 else e[0]
return self.other_versions.get_local_version()
def nb_draft_events():
return Event.objects.filter(status=Event.STATUS.DRAFT).count()