Fix combining locale/translation_of API filters with search (#6627)

Fixes #6626
pull/7887/head
Matt Westcott 2020-12-10 00:18:47 +00:00
rodzic d249e60152
commit 7fd9a49e9c
4 zmienionych plików z 34 dodań i 1 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ Changelog
* Fix: Updated project template migrations to ensure that initial homepage creation runs before addition of locale field (Dan Braghis)
* Fix: Restore ability to use translatable strings in `LANGUAGES` / `WAGTAIL_CONTENT_LANGUAGES` settings (Andreas Morgenstern)
* Fix: Allow `locale` / `translation_of` API filters to be used in combination with search (Matt Westcott)
2.11.2 (17.11.2020)

Wyświetl plik

@ -15,6 +15,7 @@ Bug fixes
* Updated project template migrations to ensure that initial homepage creation runs before addition of locale field (Dan Braghis)
* Restore ability to use translatable strings in ``LANGUAGES`` / ``WAGTAIL_CONTENT_LANGUAGES`` settings (Andreas Morgenstern)
* Allow ``locale`` / ``translation_of`` API filters to be used in combination with search (Matt Westcott)
Upgrade considerations

Wyświetl plik

@ -161,6 +161,22 @@ class TestPageListing(TestCase):
self.assertEqual(len(content['items']), 1)
self.assertEqual(content['items'][0]['id'], french_homepage.id)
@override_settings(WAGTAIL_I18N_ENABLED=True)
def test_locale_filter_with_search(self):
french = Locale.objects.create(language_code='fr')
homepage = Page.objects.get(depth=2)
french_homepage = homepage.copy_for_translation(french)
french_homepage.get_latest_revision().publish()
events_index = Page.objects.get(url_path='/home-page/events-index/')
french_events_index = events_index.copy_for_translation(french)
french_events_index.get_latest_revision().publish()
response = self.get_response(locale='fr', search='events')
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(len(content['items']), 1)
self.assertEqual(content['items'][0]['id'], french_events_index.id)
# TRANSLATION OF FILTER
@override_settings(WAGTAIL_I18N_ENABLED=True)
@ -176,6 +192,21 @@ class TestPageListing(TestCase):
self.assertEqual(len(content['items']), 1)
self.assertEqual(content['items'][0]['id'], french_homepage.id)
@override_settings(WAGTAIL_I18N_ENABLED=True)
def test_translation_of_filter_with_search(self):
french = Locale.objects.create(language_code='fr')
homepage = Page.objects.get(depth=2)
french_homepage = homepage.copy_for_translation(french)
french_homepage.get_latest_revision().publish()
response = self.get_response(translation_of=homepage.id, search='home')
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(len(content['items']), 1)
self.assertEqual(content['items'][0]['id'], french_homepage.id)
response = self.get_response(translation_of=homepage.id, search='gnome')
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(len(content['items']), 0)
# FIELDS
def test_fields_default(self):

Wyświetl plik

@ -369,9 +369,9 @@ class PagesAPIViewSet(BaseAPIViewSet):
ChildOfFilter,
DescendantOfFilter,
OrderingFilter,
SearchFilter,
TranslationOfFilter,
LocaleFilter,
SearchFilter, # needs to be last, as SearchResults querysets cannot be filtered further
]
known_query_parameters = BaseAPIViewSet.known_query_parameters.union([
'type',