Amélioration de la gestion des doublons
- gestion d'erreur si le DuplicatedEvents a été modifié entre temps - quand on créé un nouveau, pas besoin d'importer la source
This commit is contained in:
parent
ce140764cc
commit
0a66a858c5
@ -167,34 +167,44 @@ class FixDuplicates(Form):
|
||||
initial = None
|
||||
for i, e in enumerate(events):
|
||||
if e.status != Event.STATUS.TRASH:
|
||||
il = auc[i]
|
||||
msg = ""
|
||||
if e.local_version():
|
||||
msg = _(" (locally modified version)")
|
||||
initial = "Select" + il
|
||||
initial = "Select-" + str(e.pk)
|
||||
if e.pure_import():
|
||||
msg = _(" (synchronized on import version)")
|
||||
choices += [
|
||||
(
|
||||
"Select" + il,
|
||||
_("Select {} as representative version.").format(il + msg)
|
||||
"Select-" + str(e.pk),
|
||||
_("Select {} as representative version.").format(auc[i] + msg)
|
||||
)
|
||||
]
|
||||
|
||||
for i, e in enumerate(events):
|
||||
if e.status != Event.STATUS.TRASH and e.local_version():
|
||||
choices += [
|
||||
(
|
||||
"Update-" + str(e.pk),
|
||||
_("Update {} using some fields from other versions (interactive mode).").format(auc[i])
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
extra = ""
|
||||
if edup.has_local_version():
|
||||
extra = _(" Warning: a version is already locally modified.")
|
||||
|
||||
if initial is None:
|
||||
initial = "Merge"
|
||||
choices += [
|
||||
("Merge", _("Create a new version by merging.") + extra)
|
||||
("Merge", _("Create a new version by merging (interactive mode).") + extra)
|
||||
]
|
||||
for i, e in enumerate(events):
|
||||
if e.status != Event.STATUS.TRASH:
|
||||
il = auc[i]
|
||||
choices += [
|
||||
(
|
||||
"Remove" + il,
|
||||
_("Make {} independent.").format(il))
|
||||
"Remove-" + str(e.pk),
|
||||
_("Make {} independent.").format(auc[i]))
|
||||
]
|
||||
choices += [("NotDuplicates", _("Make all versions independent."))]
|
||||
|
||||
@ -207,25 +217,24 @@ class FixDuplicates(Form):
|
||||
def is_action_select(self):
|
||||
return self.cleaned_data["action"].startswith("Select")
|
||||
|
||||
def is_action_update(self):
|
||||
return self.cleaned_data["action"].startswith("Update")
|
||||
|
||||
def is_action_remove(self):
|
||||
return self.cleaned_data["action"].startswith("Remove")
|
||||
|
||||
def get_selected_event_code(self):
|
||||
if self.is_action_select() or self.is_action_remove():
|
||||
return self.cleaned_data["action"][-1]
|
||||
return int(self.cleaned_data["action"].split("-")[-1])
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_selected_event_id(self):
|
||||
selected = self.get_selected_event_code()
|
||||
if selected is None:
|
||||
return None
|
||||
else:
|
||||
return auc.rfind(selected)
|
||||
|
||||
def get_selected_event(self, edup):
|
||||
selected = self.get_selected_event_id()
|
||||
return edup.get_duplicated()[selected]
|
||||
selected = self.get_selected_event_code()
|
||||
for e in edup.get_duplicated():
|
||||
if e.pk == selected:
|
||||
return e
|
||||
return None
|
||||
|
||||
|
||||
class SelectEventInList(Form):
|
||||
|
@ -1470,15 +1470,6 @@ def merge_duplicate(request, pk):
|
||||
if f["key"] == "image" and "local_image" not in new_event_data:
|
||||
new_event_data["local_image"] = getattr(events[selected], "local_image")
|
||||
|
||||
for specific_tag in ["uuids", "import_sources"]:
|
||||
new_event_data[specific_tag] = sum(
|
||||
[
|
||||
x
|
||||
for x in [getattr(e, specific_tag) for e in events]
|
||||
if x is not None
|
||||
],
|
||||
[],
|
||||
)
|
||||
|
||||
# create a new event that merge the selected events
|
||||
new_event = Event(**new_event_data)
|
||||
@ -1535,12 +1526,19 @@ def fix_duplicate(request, pk):
|
||||
elif form.is_action_select():
|
||||
# one element has been selected to be the representative
|
||||
selected = form.get_selected_event(edup)
|
||||
if selected is None:
|
||||
messages.error(request, _("The selected item is no longer included in the list of duplicates. Someone else has probably modified the list in the meantime."))
|
||||
else:
|
||||
edup.fix(selected)
|
||||
messages.success(request, _("The selected event has been set as representative"))
|
||||
return HttpResponseRedirect(edup.get_absolute_url())
|
||||
elif form.is_action_remove():
|
||||
# one element is removed from the set
|
||||
event = form.get_selected_event(edup)
|
||||
if selected is None:
|
||||
messages.error(request, _("The selected item is no longer included in the list of duplicates. Someone else has probably modified the list in the meantime."))
|
||||
return HttpResponseRedirect(edup.get_absolute_url())
|
||||
else:
|
||||
event.other_versions = None
|
||||
if edup.representative == event:
|
||||
edup.representative = None
|
||||
@ -1552,6 +1550,16 @@ def fix_duplicate(request, pk):
|
||||
return HttpResponseRedirect(edup.get_absolute_url())
|
||||
else:
|
||||
form = FixDuplicates(edup=edup)
|
||||
elif form.is_action_update():
|
||||
# otherwise, a new event will be created using a merging process
|
||||
event = form.get_selected_event(edup)
|
||||
if selected is None:
|
||||
messages.error(request, _("The selected item is no longer included in the list of duplicates. Someone else has probably modified the list in the meantime."))
|
||||
return HttpResponseRedirect(edup.get_absolute_url())
|
||||
else:
|
||||
return HttpResponseRedirect(
|
||||
reverse_lazy("update_event", args=[edup.ok, event.pk])
|
||||
)
|
||||
else:
|
||||
# otherwise, a new event will be created using a merging process
|
||||
return HttpResponseRedirect(
|
||||
|
Loading…
Reference in New Issue
Block a user