diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f772ce2..50df05be 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,22 +33,13 @@ jobs: strategy: matrix: python: ['3.7', '3.8', '3.9'] - django: ['2.2'] - wagtail: ['2.11', '2.12', '2.13'] + django: ['3.2'] + wagtail: ['2.15', '2.16', '3.0', '4.0'] include: - # Add test for Django 3.2 that is only suported on Wagtail 2.13+ - python: '3.9' - django: '3.2' - wagtail: '2.15' - - python: '3.9' - django: '3.2' - wagtail: '2.16' - - python: '3.9' - django: '3.2' - wagtail: '3.0' - - python: '3.9' - django: '3.2' + django: '4.1' wagtail: '4.0' + experimental: false steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python }} @@ -77,31 +68,14 @@ jobs: strategy: matrix: python: ['3.7', '3.8', '3.9'] - django: ['2.2'] - wagtail: ['2.11', '2.12', '2.13'] + django: ['3.2'] + wagtail: ['2.15', '2.16', '3.0'] experimental: [false] include: - # Add test for Django 3.2 that is only suported on Wagtail 2.13+ - - python: '3.9' - django: '3.2' - wagtail: '2.14' - experimental: false - - python: '3.9' - django: '3.2' - wagtail: '2.15' - experimental: false - - python: '3.9' - django: '3.2' - wagtail: '2.16' - experimental: false - python: '3.9' django: '4.0' wagtail: '2.16' experimental: false - - python: '3.9' - django: '3.2' - wagtail: '3.0' - experimental: false - python: '3.9' django: '4.0' wagtail: '3.0' diff --git a/README.md b/README.md index 410d6e31..1d8d74c5 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ Wagtail Localize is a translation plugin for the [Wagtail CMS](https://wagtail.o Wagtail Localize requires the following: - Python (3.7, 3.8, 3.9, 3.10) -- Django (2.2, 3.0, 3.1, 3.2, 4.0, 4.1) -- Wagtail (2.11, 2.12, 2.13, 2.14, 2.15, 2.16, 3.0, 4.0) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration) +- Django (3.2, 4.0, 4.1) +- Wagtail (2.15, 2.16, 3.0, 4.0) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration) ## Installation diff --git a/pyproject.toml b/pyproject.toml index 3edd4120..10148c70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,8 +31,8 @@ classifiers = [ dynamic = ["version"] requires-python = ">=3.7" dependencies = [ - "Django>=2.2,<4.2", - "Wagtail>=2.11,<5.0", + "Django>=3.2,<4.2", + "Wagtail>=2.15,<5.0", "polib>=1.1,<2.0", "typing_extensions>=4.0" ] diff --git a/tox.ini b/tox.ini index 6806104d..45831f82 100644 --- a/tox.ini +++ b/tox.ini @@ -3,10 +3,9 @@ skipsdist = True usedevelop = True envlist = - python{3.7,3.8,3.9}-django{2.2}-wagtail{2.11,2.12,2.13}-{sqlite,postgres} - python{3.7,3.8,3.9}-django{3.2}-wagtail{2.14,2.15,2.16,3.0,4.0}-{sqlite,postgres} - python{3.7,3.8,3.9,3.10}-django{4.0}-wagtail{2.16,3.0,4.0,main}-{sqlite,postgres} + python{3.7,3.8,3.9}-django{3.2}-wagtail{2.15,2.16,3.0,4.0}-{sqlite,postgres} python{3.10}-django{3.2}-wagtail{2.15,2.16,3.0,4.0,main}-{sqlite,postgres} + python{3.7,3.8,3.9,3.10}-django{4.0}-wagtail{2.16,3.0,4.0,main}-{sqlite,postgres} python{3.8, 3.9, 3.10}-django{4.1,main}-wagtail{4.0,main}-{sqlite,postgres} [flake8] @@ -29,16 +28,11 @@ deps = coverage typing_extensions>=4.0 - django2.2: Django~=2.2 django3.2: Django~=3.2 django4.0: Django~=4.0 django4.1: Django~=4.1 djangomain: git+https://github.com/django/django.git@main#egg=Django - wagtail2.11: wagtail>=2.11,<2.12 - wagtail2.12: wagtail>=2.12,<2.13 - wagtail2.13: wagtail>=2.13,<2.14 - wagtail2.14: wagtail>=2.14,<2.15 wagtail2.15: wagtail>=2.15,<2.16 wagtail2.16: wagtail>=2.16,<2.17 wagtail3.0: wagtail>=3.0,<4.0 diff --git a/wagtail_localize/__init__.py b/wagtail_localize/__init__.py index 91c52a54..ddb3bff3 100644 --- a/wagtail_localize/__init__.py +++ b/wagtail_localize/__init__.py @@ -1,10 +1,7 @@ -from django import VERSION as DJANGO_VERSION +from .version import get_version -from .version import VERSION, __version__ # noqa +# release must be one of alpha, beta, rc, or final +VERSION = (1, 3, 0, "alpha", 3) -if DJANGO_VERSION >= (3, 2): - # The declaration is only needed for older Django versions - pass -else: - default_app_config = "wagtail_localize.apps.WagtailLocalizeAppConfig" +__version__ = get_version(VERSION) diff --git a/wagtail_localize/locales/__init__.py b/wagtail_localize/locales/__init__.py index b85d932e..e69de29b 100644 --- a/wagtail_localize/locales/__init__.py +++ b/wagtail_localize/locales/__init__.py @@ -1,8 +0,0 @@ -from django import VERSION as DJANGO_VERSION - - -if DJANGO_VERSION >= (3, 2): - # The declaration is only needed for older Django versions - pass -else: - default_app_config = "wagtail_localize.locales.apps.WagtailLocalesAppConfig" diff --git a/wagtail_localize/modeladmin/__init__.py b/wagtail_localize/modeladmin/__init__.py index 77d021fe..e69de29b 100644 --- a/wagtail_localize/modeladmin/__init__.py +++ b/wagtail_localize/modeladmin/__init__.py @@ -1,10 +0,0 @@ -from django import VERSION as DJANGO_VERSION - - -if DJANGO_VERSION >= (3, 2): - # The declaration is only needed for older Django versions - pass -else: - default_app_config = ( - "wagtail_localize.modeladmin.apps.WagtailLocalizeModelAdminAppConfig" - ) diff --git a/wagtail_localize/modeladmin/templates/wagtail_localize/modeladmin/translatable_edit.html b/wagtail_localize/modeladmin/templates/wagtail_localize/modeladmin/translatable_edit.html index e6112ce7..dd6042d1 100644 --- a/wagtail_localize/modeladmin/templates/wagtail_localize/modeladmin/translatable_edit.html +++ b/wagtail_localize/modeladmin/templates/wagtail_localize/modeladmin/translatable_edit.html @@ -2,11 +2,7 @@ {% load i18n wagtailadmin_tags %} {% block header %} - {% if wagtail_version >= "2.15" %} {% include "modeladmin/includes/header_with_history.html" with title=view.get_page_title subtitle=view.get_page_subtitle icon=view.header_icon tabbed=1 merged=1 latest_log_entry=latest_log_entry history_url=history_url %} - {% else %} - {% include "wagtailadmin/shared/header_with_locale_selector.html" with title=view.get_page_title subtitle=view.get_page_subtitle icon=view.header_icon tabbed=1 merged=1 %} - {% endif %} {% endblock %} {% block form_actions %} diff --git a/wagtail_localize/modeladmin/views.py b/wagtail_localize/modeladmin/views.py index 3a4ea201..989da091 100644 --- a/wagtail_localize/modeladmin/views.py +++ b/wagtail_localize/modeladmin/views.py @@ -8,12 +8,12 @@ from django.urls import NoReverseMatch, reverse from django.utils.decorators import method_decorator from django.utils.translation import gettext as _ -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.contrib.modeladmin.views import ( ChooseParentView, CreateView, DeleteView, EditView, + HistoryView, IndexView, InspectView, ) @@ -25,12 +25,6 @@ from wagtail_localize.views.submit_translations import SubmitTranslationView -if WAGTAIL_VERSION >= (2, 15): - from wagtail.contrib.modeladmin.views import HistoryView -else: - HistoryView = object - - class TranslatableViewMixin: def __init__(self, *args, **kwargs): self.locale = None diff --git a/wagtail_localize/models.py b/wagtail_localize/models.py index dbae9e7a..131d1dc3 100644 --- a/wagtail_localize/models.py +++ b/wagtail_localize/models.py @@ -527,7 +527,7 @@ def as_instance(self): if isinstance(instance, Page): content_json = self.content_json - if WAGTAIL_VERSION >= (2, 17): + if WAGTAIL_VERSION >= (3, 0): # see https://github.com/wagtail/wagtail/pull/8024 content_json = json.loads(content_json) return instance.with_content_json(content_json) diff --git a/wagtail_localize/segments/tests/test_segment_ingestion.py b/wagtail_localize/segments/tests/test_segment_ingestion.py index ce12eebe..534d5fbf 100644 --- a/wagtail_localize/segments/tests/test_segment_ingestion.py +++ b/wagtail_localize/segments/tests/test_segment_ingestion.py @@ -18,16 +18,6 @@ from wagtail_localize.test.models import TestChildObject, TestPage, TestSnippet -def streamfield_raw_data(stream_data): - """ - Extracts raw_data from streamfields. The attribute for doing this changed in Wagtail 2.12 - """ - if WAGTAIL_VERSION >= (2, 12): - return stream_data.raw_data - else: - return stream_data.stream_data - - def make_test_page(**kwargs): root_page = Page.objects.get(id=1) kwargs.setdefault("title", "Test page") @@ -287,7 +277,7 @@ def test_charblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -317,7 +307,7 @@ def test_textblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -347,7 +337,7 @@ def test_emailblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -381,7 +371,7 @@ def test_urlblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -418,7 +408,7 @@ def test_embedblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -451,7 +441,7 @@ def test_richtextblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -485,7 +475,7 @@ def test_rawhtmlblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -515,7 +505,7 @@ def test_blockquoteblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -554,7 +544,7 @@ def test_structblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -598,7 +588,7 @@ def test_listblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -647,7 +637,7 @@ def test_nestedstreamblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), @@ -690,7 +680,7 @@ def test_customstructblock(self): translated_page.refresh_from_db() self.assertEqual( - list(streamfield_raw_data(translated_page.test_streamfield)), + list(translated_page.test_streamfield.raw_data), [ { "id": str(block_id), diff --git a/wagtail_localize/static_src/editor/components/TranslationEditor/footer.tsx b/wagtail_localize/static_src/editor/components/TranslationEditor/footer.tsx index 691d92dc..d83fa47a 100644 --- a/wagtail_localize/static_src/editor/components/TranslationEditor/footer.tsx +++ b/wagtail_localize/static_src/editor/components/TranslationEditor/footer.tsx @@ -140,33 +140,19 @@ const EditorFooter: FunctionComponent = ({ // Make last action the default const defaultAction = actions.pop(); - // The markup for footers is slightly different when running Wagtail 2.13+ - if ((window as any).comments) { - // Running Wagtail 2.13 - return ( - - ); - } else { - return ( - - ); - } + return ( + + ); }; export default EditorFooter; diff --git a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/footer.tsx b/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/footer.tsx index 691d92dc..d83fa47a 100644 --- a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/footer.tsx +++ b/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/footer.tsx @@ -140,33 +140,19 @@ const EditorFooter: FunctionComponent = ({ // Make last action the default const defaultAction = actions.pop(); - // The markup for footers is slightly different when running Wagtail 2.13+ - if ((window as any).comments) { - // Running Wagtail 2.13 - return ( -
-
    -
  • - -
  • -
-
- ); - } else { - return ( -
- -
- ); - } + return ( +
+
    +
  • + +
  • +
+
+ ); }; export default EditorFooter; diff --git a/wagtail_localize/templates/wagtail_localize/admin/edit_translation.html b/wagtail_localize/templates/wagtail_localize/admin/edit_translation.html index 1386318a..1b2a71d1 100644 --- a/wagtail_localize/templates/wagtail_localize/admin/edit_translation.html +++ b/wagtail_localize/templates/wagtail_localize/admin/edit_translation.html @@ -35,10 +35,22 @@ {% block extra_js %} {% include "wagtailadmin/pages/_editor_js.html" %} - - - - - - + + + {% if has_legacy_styling %} + + + + + {% else %} + + + + + + + + + {% endif %} + {% endblock %} diff --git a/wagtail_localize/test/__init__.py b/wagtail_localize/test/__init__.py index edf20365..e69de29b 100644 --- a/wagtail_localize/test/__init__.py +++ b/wagtail_localize/test/__init__.py @@ -1,8 +0,0 @@ -from django import VERSION as DJANGO_VERSION - - -if DJANGO_VERSION >= (3, 2): - # The declaration is only needed for older Django versions - pass -else: - default_app_config = "wagtail_localize.test.apps.WagtailLocalizeTestAppConfig" diff --git a/wagtail_localize/test/models.py b/wagtail_localize/test/models.py index c45dce43..195f0be5 100644 --- a/wagtail_localize/test/models.py +++ b/wagtail_localize/test/models.py @@ -13,7 +13,7 @@ StreamFieldPanel, TabbedInterface, ) -from wagtail.core import blocks +from wagtail.core import blocks, telepath from wagtail.core.fields import RichTextField, StreamField from wagtail.core.models import Orderable, Page, TranslatableMixin from wagtail.documents.blocks import DocumentChooserBlock @@ -28,13 +28,6 @@ from wagtail_localize.segments import StringSegmentValue -# Telepath added in Wagtail 2.13 -try: - from wagtail.core import telepath -except ImportError: - telepath = False - - @register_snippet class TestSnippet(TranslatableMixin, ClusterableModel): field = models.TextField(gettext_lazy("field")) @@ -160,17 +153,16 @@ class ListStructBlock(blocks.StructBlock): links_list = blocks.ListBlock(LinksList()) -if telepath: +class CustomBlockWithoutExtractMethodAdapter(telepath.Adapter): + js_constructor = "CustomBlockWithoutExtractMethod" - class CustomBlockWithoutExtractMethodAdapter(telepath.Adapter): - js_constructor = "CustomBlockWithoutExtractMethod" + def js_args(self, block): + return [] - def js_args(self, block): - return [] - telepath.register( - CustomBlockWithoutExtractMethodAdapter(), CustomBlockWithoutExtractMethod - ) +telepath.register( + CustomBlockWithoutExtractMethodAdapter(), CustomBlockWithoutExtractMethod +) class TestStreamBlock(blocks.StreamBlock): diff --git a/wagtail_localize/test/settings.py b/wagtail_localize/test/settings.py index 03ef85ad..bbe55580 100644 --- a/wagtail_localize/test/settings.py +++ b/wagtail_localize/test/settings.py @@ -14,8 +14,6 @@ import dj_database_url -from wagtail import VERSION as WAGTAIL_VERSION - # Build paths inside the project like this: os.path.join(PROJECT_DIR, ...) PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -183,12 +181,10 @@ }, } - DEFAULT_AUTO_FIELD = "django.db.models.AutoField" -if WAGTAIL_VERSION >= (2, 15): - WAGTAILSEARCH_BACKENDS = { - "default": { - "BACKEND": "wagtail.search.backends.database", - } +WAGTAILSEARCH_BACKENDS = { + "default": { + "BACKEND": "wagtail.search.backends.database", } +} diff --git a/wagtail_localize/tests/test_convert_to_alias.py b/wagtail_localize/tests/test_convert_to_alias.py index 0e173283..7d782e6e 100644 --- a/wagtail_localize/tests/test_convert_to_alias.py +++ b/wagtail_localize/tests/test_convert_to_alias.py @@ -35,7 +35,7 @@ def _page_action_is_shown(self, page, view="edit"): menu_item = ConvertToAliasPageActionMenuItem() context = {"view": view, "page": page} - return menu_item._is_shown(context) + return menu_item.is_shown(context) def test_page_action_not_available_on_non_translation_pages(self): self.assertFalse(self._page_action_is_shown(self.page)) diff --git a/wagtail_localize/tests/test_edit_translation.py b/wagtail_localize/tests/test_edit_translation.py index b0bc1d58..4100cc95 100644 --- a/wagtail_localize/tests/test_edit_translation.py +++ b/wagtail_localize/tests/test_edit_translation.py @@ -5,7 +5,6 @@ import polib -from django import VERSION as DJANGO_VERSION from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission from django.contrib.contenttypes.models import ContentType @@ -56,7 +55,6 @@ edit_override, edit_string_translation, ) -from wagtail_localize.wagtail_hooks import SNIPPET_RESTART_TRANSLATION_ENABLED from .utils import assert_permission_denied, get_snippet_add_url_from_args @@ -1376,18 +1374,11 @@ def test_edit_page_from_outdated_translation_source(self): reverse("wagtailadmin_pages:edit", args=[self.fr_page.id]) ) - if DJANGO_VERSION >= (3, 0): - self.assertContains( - response, - "The data model for 'Test page' has been changed since the last translation sync. " - "If any new fields have been added recently, these may not be visible until the next translation sync.", - ) - else: - self.assertContains( - response, - "The data model for 'Test page' has been changed since the last translation sync. " - "If any new fields have been added recently, these may not be visible until the next translation sync.", - ) + self.assertContains( + response, + "The data model for 'Test page' has been changed since the last translation sync. " + "If any new fields have been added recently, these may not be visible until the next translation sync.", + ) def test_edit_snippet_translation(self): response = self.client.get(get_snippet_edit_url(self.fr_snippet)) @@ -1571,16 +1562,10 @@ def test_publish_page_translation(self): messages = list(get_messages(response.wsgi_request)) self.assertEqual(messages[0].level_tag, "success") - if DJANGO_VERSION >= (3, 0): - self.assertEqual( - messages[0].message, - "Published 'The title' in French.\n\n\n\n\n", - ) - else: - self.assertEqual( - messages[0].message, - "Published 'The title' in French.\n\n\n\n\n", - ) + self.assertEqual( + messages[0].message, + "Published 'The title' in French.\n\n\n\n\n", + ) # Check the page was published self.fr_page.refresh_from_db() @@ -1619,16 +1604,10 @@ def test_publish_page_translation_with_missing_translations(self): messages = list(get_messages(response.wsgi_request)) self.assertEqual(messages[0].level_tag, "warning") - if DJANGO_VERSION >= (3, 0): - self.assertEqual( - messages[0].message, - "Published 'The title' in French with missing translations - see below.\n\n\n\n\n", - ) - else: - self.assertEqual( - messages[0].message, - "Published 'The title' in French with missing translations - see below.\n\n\n\n\n", - ) + self.assertEqual( + messages[0].message, + "Published 'The title' in French with missing translations - see below.\n\n\n\n\n", + ) # Check the page was published self.fr_page.refresh_from_db() @@ -1670,16 +1649,10 @@ def test_publish_page_translation_with_new_field_error(self): messages = list(get_messages(response.wsgi_request)) self.assertEqual(messages[0].level_tag, "error") - if DJANGO_VERSION >= (3, 0): - self.assertEqual( - messages[0].message, - "New validation errors were found when publishing 'The title' in French. Please fix them or click publish again to ignore these translations for now.\n\n\n\n\n", - ) - else: - self.assertEqual( - messages[0].message, - "New validation errors were found when publishing 'The title' in French. Please fix them or click publish again to ignore these translations for now.\n\n\n\n\n", - ) + self.assertEqual( + messages[0].message, + "New validation errors were found when publishing 'The title' in French. Please fix them or click publish again to ignore these translations for now.\n\n\n\n\n", + ) # Check that the test_charfield was not changed self.fr_page.refresh_from_db() @@ -1728,16 +1701,10 @@ def test_publish_page_translation_with_known_field_error(self): messages = list(get_messages(response.wsgi_request)) self.assertEqual(messages[0].level_tag, "warning") - if DJANGO_VERSION >= (3, 0): - self.assertEqual( - messages[0].message, - "Published 'The title' in French with missing translations - see below.\n\n\n\n\n", - ) - else: - self.assertEqual( - messages[0].message, - "Published 'The title' in French with missing translations - see below.\n\n\n\n\n", - ) + self.assertEqual( + messages[0].message, + "Published 'The title' in French with missing translations - see below.\n\n\n\n\n", + ) # Check that the test_charfield was not changed self.fr_page.refresh_from_db() @@ -1769,16 +1736,10 @@ def test_publish_page_translation_with_invalid_segment_override(self): messages = list(get_messages(response.wsgi_request)) self.assertEqual(messages[0].level_tag, "error") - if DJANGO_VERSION >= (3, 0): - self.assertEqual( - messages[0].message, - "New validation errors were found when publishing 'The title' in French. Please fix them or click publish again to ignore these translations for now.\n\n\n\n\n", - ) - else: - self.assertEqual( - messages[0].message, - "New validation errors were found when publishing 'The title' in French. Please fix them or click publish again to ignore these translations for now.\n\n\n\n\n", - ) + self.assertEqual( + messages[0].message, + "New validation errors were found when publishing 'The title' in French. Please fix them or click publish again to ignore these translations for now.\n\n\n\n\n", + ) # Check that the test_synchronized_emailfield was not changed self.fr_page.refresh_from_db() @@ -1830,16 +1791,10 @@ def test_publish_snippet_translation(self): messages = list(get_messages(response.wsgi_request)) self.assertEqual(messages[0].level_tag, "success") - if DJANGO_VERSION >= (3, 0): - self.assertEqual( - messages[0].message, - f"Published 'TestSnippet object ({self.fr_snippet.id})' in French.\n\n\n\n\n", - ) - else: - self.assertEqual( - messages[0].message, - f"Published 'TestSnippet object ({self.fr_snippet.id})' in French.\n\n\n\n\n", - ) + self.assertEqual( + messages[0].message, + f"Published 'TestSnippet object ({self.fr_snippet.id})' in French.\n\n\n\n\n", + ) # Check the snippet was published self.fr_snippet.refresh_from_db() @@ -2004,10 +1959,6 @@ def test_doesnt_show_when_no_translation_for_page(self): self.assertNotContains(response, "Start Synced translation") - @unittest.skipUnless( - SNIPPET_RESTART_TRANSLATION_ENABLED, - "wagtail.snippets.action_menu module doesn't exist. See: https://github.com/wagtail/wagtail/pull/6384", - ) def test_snippet(self): self.snippet_translation.enabled = False self.snippet_translation.save() @@ -2016,10 +1967,6 @@ def test_snippet(self): self.assertContains(response, "Start Synced translation") - @unittest.skipUnless( - SNIPPET_RESTART_TRANSLATION_ENABLED, - "wagtail.snippets.action_menu module doesn't exist. See: https://github.com/wagtail/wagtail/pull/6384", - ) def test_doesnt_show_when_no_translation_for_snippet(self): self.snippet_translation.delete() @@ -2027,10 +1974,6 @@ def test_doesnt_show_when_no_translation_for_snippet(self): self.assertNotContains(response, "Start Synced translation") - @unittest.skipUnless( - SNIPPET_RESTART_TRANSLATION_ENABLED, - "wagtail.snippets.action_menu module doesn't exist. See: https://github.com/wagtail/wagtail/pull/6384", - ) def test_doesnt_show_on_create_for_snippet(self): response = self.client.get( get_snippet_add_url_from_args( @@ -2039,10 +1982,6 @@ def test_doesnt_show_on_create_for_snippet(self): ) self.assertNotContains(response, "Start Synced translation") - @unittest.skipUnless( - SNIPPET_RESTART_TRANSLATION_ENABLED, - "wagtail.snippets.action_menu module doesn't exist. See: https://github.com/wagtail/wagtail/pull/6384", - ) def test_doesnt_show_for_untranslatable_snippet(self): snippet = NonTranslatableSnippet.objects.create(field="Test") response = self.client.get(get_snippet_edit_url(snippet)) @@ -3288,16 +3227,10 @@ def test_machine_translate_snippet_when_already_translated(self): messages = list(get_messages(response.wsgi_request)) self.assertEqual(messages[0].level_tag, "warning") - if DJANGO_VERSION >= (3, 0): - self.assertEqual( - messages[0].message, - "There isn't anything left to translate.\n\n\n\n\n", - ) - else: - self.assertEqual( - messages[0].message, - "There isn't anything left to translate.\n\n\n\n\n", - ) + self.assertEqual( + messages[0].message, + "There isn't anything left to translate.\n\n\n\n\n", + ) translation = StringTranslation.objects.get( translation_of__data="Test snippet", diff --git a/wagtail_localize/tests/test_submit_translations.py b/wagtail_localize/tests/test_submit_translations.py index c42f26eb..981bce88 100644 --- a/wagtail_localize/tests/test_submit_translations.py +++ b/wagtail_localize/tests/test_submit_translations.py @@ -3,7 +3,6 @@ from django.contrib.contenttypes.models import ContentType from django.test import TestCase, override_settings from django.urls import reverse -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.core.models import Locale, Page, PageViewRestriction from wagtail.tests.utils import WagtailTestUtils @@ -646,11 +645,10 @@ def test(self): get_snippet_list_url_from_args("wagtail_localize_test", "testsnippet") ) - extra = ' title="Translate"' if WAGTAIL_VERSION >= (2, 15) else "" self.assertContains( response, ( - f'href="/admin/localize/submit/snippet/wagtail_localize_test/testsnippet/{self.en_snippet.id}/"{extra}>Translate' + f'href="/admin/localize/submit/snippet/wagtail_localize_test/testsnippet/{self.en_snippet.id}/" title="Translate">Translate' ), ) diff --git a/wagtail_localize/tests/test_update_translations.py b/wagtail_localize/tests/test_update_translations.py index f106bff1..38a4e3d7 100644 --- a/wagtail_localize/tests/test_update_translations.py +++ b/wagtail_localize/tests/test_update_translations.py @@ -6,7 +6,6 @@ from django.core.exceptions import ValidationError from django.test import TestCase, override_settings from django.urls import reverse -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.core.models import Locale, Page, PageViewRestriction from wagtail.tests.utils import WagtailTestUtils @@ -150,11 +149,10 @@ def test(self): get_snippet_list_url_from_args("wagtail_localize_test", "testsnippet") ) - extra = ' title="Sync translated snippets"' if WAGTAIL_VERSION > (2, 15) else "" self.assertContains( response, ( - f'href="/admin/localize/update/{self.source.id}/?next=%2Fadmin%2Fsnippets%2Fwagtail_localize_test%2Ftestsnippet%2F"{extra}>Sync translated snippets' + f'href="/admin/localize/update/{self.source.id}/?next=%2Fadmin%2Fsnippets%2Fwagtail_localize_test%2Ftestsnippet%2F" title="Sync translated snippets">Sync translated snippets' ), ) diff --git a/wagtail_localize/version.py b/wagtail_localize/version.py index 4d38f8f0..1a13daa0 100644 --- a/wagtail_localize/version.py +++ b/wagtail_localize/version.py @@ -39,9 +39,3 @@ def get_complete_version(version=None): assert version[3] in ("dev", "alpha", "beta", "rc", "final") return version - - -# release must be one of alpha, beta, rc, or final -VERSION = (1, 3, 0, "alpha", 3) - -__version__ = get_version(VERSION) diff --git a/wagtail_localize/views/convert.py b/wagtail_localize/views/convert.py index a72003a6..63969a31 100644 --- a/wagtail_localize/views/convert.py +++ b/wagtail_localize/views/convert.py @@ -117,7 +117,7 @@ def sync_alias(source_page, alias_page, revision=None, _content_json=None): if _content_json is None: _content_json = source_page.to_json() - if WAGTAIL_VERSION >= (2, 17): + if WAGTAIL_VERSION >= (3, 0): # see https://github.com/wagtail/wagtail/pull/8024 _content_json = json.loads(_content_json) @@ -185,7 +185,7 @@ def process_child_object(child_object): ) # Update any aliases of that alias - if WAGTAIL_VERSION >= (2, 17): + if WAGTAIL_VERSION >= (3, 0): alias_page.update_aliases(revision=revision, _content=_content_json) else: alias_page.update_aliases(revision=revision, _content_json=_content_json) diff --git a/wagtail_localize/wagtail_hooks.py b/wagtail_localize/wagtail_hooks.py index edda37d4..fc276b1e 100644 --- a/wagtail_localize/wagtail_hooks.py +++ b/wagtail_localize/wagtail_hooks.py @@ -13,21 +13,9 @@ from wagtail.admin.action_menu import ActionMenuItem as PageActionMenuItem from wagtail.admin.menu import MenuItem from wagtail.core import hooks +from wagtail.core.log_actions import LogFormatter from wagtail.core.models import Locale, Page, TranslatableMixin - - -if WAGTAIL_VERSION >= (2, 15): - from wagtail.core.log_actions import LogFormatter - -# The `wagtail.snippets.action_menu` module is introduced in https://github.com/wagtail/wagtail/pull/6384 -# FIXME: Remove this check when this module is merged into master -try: - from wagtail.snippets.action_menu import ActionMenuItem as SnippetActionMenuItem - - SNIPPET_RESTART_TRANSLATION_ENABLED = True -except ImportError: - SNIPPET_RESTART_TRANSLATION_ENABLED = False - +from wagtail.snippets.action_menu import ActionMenuItem as SnippetActionMenuItem from wagtail.snippets.widgets import SnippetListingButton # Import synctree so it can register its signal handler @@ -283,7 +271,7 @@ class RestartTranslationPageActionMenuItem(PageActionMenuItem): icon_name = "undo" classname = "action-secondary" - def _is_shown(self, context): + def is_shown(self, context): # Only show this menu item on the edit view where there was a previous translation record if context["view"] != "edit": return False @@ -294,16 +282,6 @@ def _is_shown(self, context): enabled=False, ).exists() - if WAGTAIL_VERSION >= (2, 15): - - def is_shown(self, context): - return self._is_shown(context) - - else: - - def is_shown(self, request, context): - return self._is_shown(context) - @hooks.register("register_page_action_menu_item") def register_restart_translation_page_action_menu_item(): @@ -316,7 +294,7 @@ class ConvertToAliasPageActionMenuItem(PageActionMenuItem): icon_name = "wagtail-localize-convert" classname = "action-secondary" - def _is_shown(self, context): + def is_shown(self, context): # Only show this menu item on the edit view where there was a previous translation record if context["view"] != "edit": return False @@ -337,16 +315,6 @@ def _is_shown(self, context): except TranslationSource.DoesNotExist: return False - if WAGTAIL_VERSION >= (2, 15): - - def is_shown(self, context): - return self._is_shown(context) - - else: - - def is_shown(self, request, context): - return self._is_shown(context) - @hooks.register("register_page_action_menu_item") def register_convert_back_to_alias_page_action_menu_item(): @@ -384,41 +352,30 @@ def before_edit_snippet(request, instance): pass -if SNIPPET_RESTART_TRANSLATION_ENABLED: - - class RestartTranslationSnippetActionMenuItem(SnippetActionMenuItem): - label = gettext_lazy("Start Synced translation") - name = "localize-restart-translation" - icon_name = "undo" - classname = "action-secondary" - - def _is_shown(self, context): - # Only show this menu item on the edit view where there was a previous translation record - if context["view"] != "edit": - return False - - if not issubclass(context["model"], TranslatableMixin): - return False - - return Translation.objects.filter( - source__object_id=context["instance"].translation_key, - target_locale_id=context["instance"].locale_id, - enabled=False, - ).exists() +class RestartTranslationSnippetActionMenuItem(SnippetActionMenuItem): + label = gettext_lazy("Start Synced translation") + name = "localize-restart-translation" + icon_name = "undo" + classname = "action-secondary" - if WAGTAIL_VERSION >= (2, 15): + def is_shown(self, context): + # Only show this menu item on the edit view where there was a previous translation record + if context["view"] != "edit": + return False - def is_shown(self, context): - return self._is_shown(context) + if not issubclass(context["model"], TranslatableMixin): + return False - else: + return Translation.objects.filter( + source__object_id=context["instance"].translation_key, + target_locale_id=context["instance"].locale_id, + enabled=False, + ).exists() - def is_shown(self, request, context): - return self._is_shown(context) - @hooks.register("register_snippet_action_menu_item") - def register_restart_translation_snippet_action_menu_item(model): - return RestartTranslationSnippetActionMenuItem(order=0) +@hooks.register("register_snippet_action_menu_item") +def register_restart_translation_snippet_action_menu_item(model): + return RestartTranslationSnippetActionMenuItem(order=0) class TranslationsReportMenuItem(MenuItem): @@ -438,45 +395,21 @@ def register_wagtail_localize2_report_menu_item(): @hooks.register("register_log_actions") def wagtail_localize_log_actions(actions): + @actions.register_action("wagtail_localize.convert_to_alias") + class ConvertToAliasActionFormatter(LogFormatter): + label = gettext_lazy("Convert page to alias") - if WAGTAIL_VERSION >= (2, 15): - - @actions.register_action("wagtail_localize.convert_to_alias") - class ConvertToAliasActionFormatter(LogFormatter): - label = gettext_lazy("Convert page to alias") - - def format_message(self, log_entry): - try: - return _( - "Converted page '%(title)s' to an alias of the translation source page '%(source_title)s'" - ) % { - "title": log_entry.data["page"]["title"], - "source_title": log_entry.data["source"]["title"], - } - except KeyError: - return _( - "Converted page to an alias of the translation source page" - ) - - else: - - def convert_to_alias_message(data): + def format_message(self, log_entry): try: return _( "Converted page '%(title)s' to an alias of the translation source page '%(source_title)s'" ) % { - "title": data["page"]["title"], - "source_title": data["source"]["title"], + "title": log_entry.data["page"]["title"], + "source_title": log_entry.data["source"]["title"], } except KeyError: return _("Converted page to an alias of the translation source page") - actions.register_action( - "wagtail_localize.convert_to_alias", - _("Convert page to alias"), - convert_to_alias_message, - ) - @hooks.register("register_icons") def register_icons(icons):