From 95333ba8ec5c19a039fa0328bb855d8fa95f1eec Mon Sep 17 00:00:00 2001 From: Brady Moe Date: Tue, 16 Oct 2018 14:22:23 -0500 Subject: [PATCH] returns content_types as a list instead of dict_values --- CHANGELOG.txt | 1 + CONTRIBUTORS.rst | 1 + docs/releases/2.4.rst | 2 ++ wagtail/core/query.py | 2 +- wagtail/core/tests/test_page_queryset.py | 9 +++++++++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index a58c03d98..00f919cc9 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -5,6 +5,7 @@ Changelog ~~~~~~~~~~~~~~~~ * Added support for Python 3.7 (Matt Westcott) + * Fix: Query objects returned from `PageQuerySet.type_q` can now be merged with `|` (Brady Moe) 2.3 LTS (23.10.2018) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index ae8e7f031..7b7423ab4 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -322,6 +322,7 @@ Contributors * Meteor0id * Naa Marteki Reed * Jorge Barata +* Brady Moe Translators =========== diff --git a/docs/releases/2.4.rst b/docs/releases/2.4.rst index 1c287acc5..6ddea4594 100644 --- a/docs/releases/2.4.rst +++ b/docs/releases/2.4.rst @@ -20,6 +20,8 @@ Other features Bug fixes ~~~~~~~~~ + * Query objects returned from ``PageQuerySet.type_q`` can now be merged with ``|`` (Brady Moe) + Upgrade considerations ====================== diff --git a/wagtail/core/query.py b/wagtail/core/query.py index 6e984cb01..add03e9e1 100644 --- a/wagtail/core/query.py +++ b/wagtail/core/query.py @@ -178,7 +178,7 @@ class PageQuerySet(SearchableQuerySetMixin, TreeQuerySet): if issubclass(model, klass) ]).values() - return Q(content_type__in=content_types) + return Q(content_type__in=list(content_types)) def type(self, model): """ diff --git a/wagtail/core/tests/test_page_queryset.py b/wagtail/core/tests/test_page_queryset.py index c4f92e87a..019fc3440 100644 --- a/wagtail/core/tests/test_page_queryset.py +++ b/wagtail/core/tests/test_page_queryset.py @@ -1,4 +1,5 @@ from django.contrib.contenttypes.models import ContentType +from django.db.models import Q from django.test import TestCase from wagtail.core.models import Page, PageViewRestriction, Site @@ -397,6 +398,14 @@ class TestPageQuerySet(TestCase): # Check that the event is in the results self.assertTrue(pages.filter(id=event.id).exists()) + def test_merge_queries(self): + type_q = Page.objects.type_q(EventPage) + query = Q() + + query |= type_q + + self.assertTrue(Page.objects.filter(query).exists()) + class TestPageQueryInSite(TestCase): fixtures = ['test.json']