diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index 369e351..3b43a58 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -1663,13 +1663,26 @@ class Event(models.Model): break if same_imported: - # reopen DuplicatedEvents if required - if not event.similar(same_imported, False) and same_imported.other_versions: - if same_imported.status != Event.STATUS.TRASH: - if same_imported.other_versions.is_published(): - if same_imported.other_versions.representative != same_imported: - same_imported.other_versions.representative = None - same_imported.other_versions.save() + if not event.similar(same_imported, False): + # reopen DuplicatedEvents if required + if same_imported.other_versions: + if same_imported.status != Event.STATUS.TRASH: + if same_imported.other_versions.is_published(): + if same_imported.other_versions.representative != same_imported: + same_imported.other_versions.representative = None + same_imported.other_versions.save() + # add a message to explain the update + res = [r for r in Event.get_comparison([event, same_imported], all) if not r["similar"]] + if len(res) > 0: + txt = _("Updated field(s): ") + ", ".join([r["key"] for r in res]) + msg = Message(subject=_('Update'), + name=_('update process'), + related_event=same_imported, + message=txt, + message_type=Message.TYPE.UPDATE_PROCESS) + msg.save() + + # we only update local information if it's a pure import and has no moderated_date new_image = same_imported.image != event.image same_imported.update(event, pure and same_imported.moderated_date is None) @@ -1911,6 +1924,7 @@ class Message(models.Model): class TYPE(models.TextChoices): FROM_CONTRIBUTOR = "from_contributor", _("From contributor") IMPORT_PROCESS = "import_process", _("Import process") + UPDATE_PROCESS = "update_process", _("Update process") CONTACT_FORM = "contact_form", _("Contact form") EVENT_REPORT = "event_report", _("Event report") FROM_CONTRIBUTOR_NO_MSG = "from_contrib_no_msg", _("From contributor (without message)")