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
|
initial = None
|
||||||
for i, e in enumerate(events):
|
for i, e in enumerate(events):
|
||||||
if e.status != Event.STATUS.TRASH:
|
if e.status != Event.STATUS.TRASH:
|
||||||
il = auc[i]
|
|
||||||
msg = ""
|
msg = ""
|
||||||
if e.local_version():
|
if e.local_version():
|
||||||
msg = _(" (locally modified version)")
|
msg = _(" (locally modified version)")
|
||||||
initial = "Select" + il
|
initial = "Select-" + str(e.pk)
|
||||||
if e.pure_import():
|
if e.pure_import():
|
||||||
msg = _(" (synchronized on import version)")
|
msg = _(" (synchronized on import version)")
|
||||||
choices += [
|
choices += [
|
||||||
(
|
(
|
||||||
"Select" + il,
|
"Select-" + str(e.pk),
|
||||||
_("Select {} as representative version.").format(il + msg)
|
_("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 = ""
|
extra = ""
|
||||||
if edup.has_local_version():
|
if edup.has_local_version():
|
||||||
extra = _(" Warning: a version is already locally modified.")
|
extra = _(" Warning: a version is already locally modified.")
|
||||||
|
|
||||||
if initial is None:
|
if initial is None:
|
||||||
initial = "Merge"
|
initial = "Merge"
|
||||||
choices += [
|
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):
|
for i, e in enumerate(events):
|
||||||
if e.status != Event.STATUS.TRASH:
|
if e.status != Event.STATUS.TRASH:
|
||||||
il = auc[i]
|
|
||||||
choices += [
|
choices += [
|
||||||
(
|
(
|
||||||
"Remove" + il,
|
"Remove-" + str(e.pk),
|
||||||
_("Make {} independent.").format(il))
|
_("Make {} independent.").format(auc[i]))
|
||||||
]
|
]
|
||||||
choices += [("NotDuplicates", _("Make all versions independent."))]
|
choices += [("NotDuplicates", _("Make all versions independent."))]
|
||||||
|
|
||||||
@ -207,25 +217,24 @@ class FixDuplicates(Form):
|
|||||||
def is_action_select(self):
|
def is_action_select(self):
|
||||||
return self.cleaned_data["action"].startswith("Select")
|
return self.cleaned_data["action"].startswith("Select")
|
||||||
|
|
||||||
|
def is_action_update(self):
|
||||||
|
return self.cleaned_data["action"].startswith("Update")
|
||||||
|
|
||||||
def is_action_remove(self):
|
def is_action_remove(self):
|
||||||
return self.cleaned_data["action"].startswith("Remove")
|
return self.cleaned_data["action"].startswith("Remove")
|
||||||
|
|
||||||
def get_selected_event_code(self):
|
def get_selected_event_code(self):
|
||||||
if self.is_action_select() or self.is_action_remove():
|
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:
|
else:
|
||||||
return None
|
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):
|
def get_selected_event(self, edup):
|
||||||
selected = self.get_selected_event_id()
|
selected = self.get_selected_event_code()
|
||||||
return edup.get_duplicated()[selected]
|
for e in edup.get_duplicated():
|
||||||
|
if e.pk == selected:
|
||||||
|
return e
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class SelectEventInList(Form):
|
class SelectEventInList(Form):
|
||||||
|
@ -1470,15 +1470,6 @@ def merge_duplicate(request, pk):
|
|||||||
if f["key"] == "image" and "local_image" not in new_event_data:
|
if f["key"] == "image" and "local_image" not in new_event_data:
|
||||||
new_event_data["local_image"] = getattr(events[selected], "local_image")
|
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
|
# create a new event that merge the selected events
|
||||||
new_event = Event(**new_event_data)
|
new_event = Event(**new_event_data)
|
||||||
@ -1535,23 +1526,40 @@ def fix_duplicate(request, pk):
|
|||||||
elif form.is_action_select():
|
elif form.is_action_select():
|
||||||
# one element has been selected to be the representative
|
# one element has been selected to be the representative
|
||||||
selected = form.get_selected_event(edup)
|
selected = form.get_selected_event(edup)
|
||||||
edup.fix(selected)
|
if selected is None:
|
||||||
messages.success(request, _("The selected event has been set as representative"))
|
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())
|
return HttpResponseRedirect(edup.get_absolute_url())
|
||||||
elif form.is_action_remove():
|
elif form.is_action_remove():
|
||||||
# one element is removed from the set
|
# one element is removed from the set
|
||||||
event = form.get_selected_event(edup)
|
event = form.get_selected_event(edup)
|
||||||
event.other_versions = None
|
if selected is None:
|
||||||
if edup.representative == event:
|
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."))
|
||||||
edup.representative = None
|
|
||||||
event.set_no_modification_date_changed()
|
|
||||||
event.save()
|
|
||||||
edup.save()
|
|
||||||
messages.success(request, _("The event has been withdrawn from the group and made independent."))
|
|
||||||
if edup.nb_duplicated() == 1:
|
|
||||||
return HttpResponseRedirect(edup.get_absolute_url())
|
return HttpResponseRedirect(edup.get_absolute_url())
|
||||||
else:
|
else:
|
||||||
form = FixDuplicates(edup=edup)
|
event.other_versions = None
|
||||||
|
if edup.representative == event:
|
||||||
|
edup.representative = None
|
||||||
|
event.set_no_modification_date_changed()
|
||||||
|
event.save()
|
||||||
|
edup.save()
|
||||||
|
messages.success(request, _("The event has been withdrawn from the group and made independent."))
|
||||||
|
if edup.nb_duplicated() == 1:
|
||||||
|
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:
|
else:
|
||||||
# otherwise, a new event will be created using a merging process
|
# otherwise, a new event will be created using a merging process
|
||||||
return HttpResponseRedirect(
|
return HttpResponseRedirect(
|
||||||
|
Loading…
Reference in New Issue
Block a user