diff --git a/README.md b/README.md index 0bf891a8..3ec4db49 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ tox ``` or, you can run them for a specific environment `tox -e python3.8-django3.2-wagtail4.1` or specific test -`tox -e python3.9-django3.2-wagtail4.1-sqlite wagtail_localize.tests.test_edit_translation.TestGetEditTranslationView` +`tox -e python3.9-django3.2-wagtail4.1-sqlite -- wagtail_localize.tests.test_edit_translation.TestGetEditTranslationView` To run the test app interactively, use `tox -e interactive`, visit `http://127.0.0.1:8020/admin/` and log in with `admin`/`changeme`. diff --git a/wagtail_localize/tests/test_translations_report.py b/wagtail_localize/tests/test_translations_report.py index edfd0c46..d423fa01 100644 --- a/wagtail_localize/tests/test_translations_report.py +++ b/wagtail_localize/tests/test_translations_report.py @@ -135,6 +135,17 @@ def test_filter_by_source_locale(self): self.assertNotIn(self.blog_index_translation, response.context["object_list"]) self.assertNotIn(self.blog_post_translation, response.context["object_list"]) + def test_filter_by_source_locale_all_options(self): + response = self.client.get( + reverse("wagtail_localize:translations_report") + "?source_locale=all" + ) + + self.assertIn(self.snippet_translation, response.context["object_list"]) + self.assertIn(self.homepage_translation, response.context["object_list"]) + self.assertIn(self.de_homepage_translation, response.context["object_list"]) + self.assertIn(self.blog_index_translation, response.context["object_list"]) + self.assertIn(self.blog_post_translation, response.context["object_list"]) + def test_filter_by_target_locale(self): response = self.client.get( reverse("wagtail_localize:translations_report") + "?target_locale=de" @@ -145,3 +156,39 @@ def test_filter_by_target_locale(self): self.assertIn(self.de_homepage_translation, response.context["object_list"]) self.assertNotIn(self.blog_index_translation, response.context["object_list"]) self.assertNotIn(self.blog_post_translation, response.context["object_list"]) + + def test_filter_by_target_locale_all_options(self): + response = self.client.get( + reverse("wagtail_localize:translations_report") + "?target_locale=all" + ) + + self.assertIn(self.snippet_translation, response.context["object_list"]) + self.assertIn(self.homepage_translation, response.context["object_list"]) + self.assertIn(self.de_homepage_translation, response.context["object_list"]) + self.assertIn(self.blog_index_translation, response.context["object_list"]) + self.assertIn(self.blog_post_translation, response.context["object_list"]) + + def test_locale_filters_get_proper_choices(self): + response = self.client.get(reverse("wagtail_localize:translations_report")) + + self.assertEqual( + list(response.context["filters"].form.fields["source_locale"].choices), + [ + ("all", "All"), + ("en", "English"), + ("fr", "French"), + ("de", "German"), + ("es", "Spanish"), + ], + ) + + self.assertEqual( + list(response.context["filters"].form.fields["target_locale"].choices), + [ + ("all", "All"), + ("en", "English"), + ("fr", "French"), + ("de", "German"), + ("es", "Spanish"), + ], + ) diff --git a/wagtail_localize/views/report.py b/wagtail_localize/views/report.py index 2dce4594..bcd7b508 100644 --- a/wagtail_localize/views/report.py +++ b/wagtail_localize/views/report.py @@ -8,6 +8,7 @@ from modelcluster.fields import ParentalKey from wagtail.admin.filters import WagtailFilterSet from wagtail.admin.views.reports import ReportView +from wagtail.coreutils import get_content_languages from wagtail.models import get_translatable_models from wagtail_localize.models import Translation @@ -98,9 +99,13 @@ def filter(self, qs, value): ) -class LocaleFilter(django_filters.CharFilter): +def _get_locale_choices(): + return list(get_content_languages().items()) + + +class LocaleFilter(django_filters.ChoiceFilter): def filter(self, qs, value): - if value in EMPTY_VALUES: + if not value or value == self.null_value: return qs return qs.filter(**{self.field_name + "__language_code": value}) @@ -111,8 +116,19 @@ class TranslationsReportFilterSet(WagtailFilterSet): field_name="source__specific_content_type", label=gettext_lazy("Content type") ) source_title = SourceTitleFilter(label=gettext_lazy("Source title")) - source_locale = LocaleFilter(field_name="source__locale") - target_locale = LocaleFilter() + source_locale = LocaleFilter( + field_name="source__locale", + choices=_get_locale_choices, + empty_label=None, + null_label=gettext_lazy("All"), + null_value="all", + ) + target_locale = LocaleFilter( + choices=_get_locale_choices, + empty_label=None, + null_label=gettext_lazy("All"), + null_value="all", + ) class Meta: model = Translation