From 8736f547846111bd7ad90640779dc6442dd41313 Mon Sep 17 00:00:00 2001 From: Dennis McGregor Date: Fri, 6 Sep 2024 07:52:09 +1200 Subject: [PATCH] Add sync translations from latest revision support --- wagtail_localize/models.py | 4 ++- .../admin/update_translations.html | 2 +- wagtail_localize/views/update_translations.py | 25 ++++++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/wagtail_localize/models.py b/wagtail_localize/models.py index 5aa196ea..dc8c9e65 100644 --- a/wagtail_localize/models.py +++ b/wagtail_localize/models.py @@ -448,7 +448,7 @@ def update_or_create_from_instance(cls, instance): return source, created @transaction.atomic - def update_from_db(self): + def update_from_db(self, from_latest_revision=False): """ Retrieves the source instance from the database and updates this TranslationSource with its current contents. @@ -457,6 +457,8 @@ def update_from_db(self): Model.DoesNotExist: If the source instance has been deleted. """ instance = self.get_source_instance() + if from_latest_revision and isinstance(instance, RevisionMixin): + instance = instance.get_latest_revision_as_object() if isinstance(instance, ClusterableModel): self.content_json = instance.to_json() diff --git a/wagtail_localize/templates/wagtail_localize/admin/update_translations.html b/wagtail_localize/templates/wagtail_localize/admin/update_translations.html index 19149490..ad8076ef 100644 --- a/wagtail_localize/templates/wagtail_localize/admin/update_translations.html +++ b/wagtail_localize/templates/wagtail_localize/admin/update_translations.html @@ -37,7 +37,7 @@