mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-19 22:41:00 +00:00
Merge pull request #1662 from kaedroho/fix-get_search_promotions
Fix crash in get_search_promotions templatetag
This commit is contained in:
commit
d317a91e05
2 changed files with 9 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from django import template
|
||||
|
||||
from wagtail.wagtailsearch.models import Query
|
||||
from wagtail.contrib.wagtailsearchpromotions.models import SearchPromotion
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
|
@ -8,4 +9,7 @@ register = template.Library()
|
|||
|
||||
@register.assignment_tag()
|
||||
def get_search_promotions(search_query):
|
||||
return Query.get(search_query).editors_picks.all()
|
||||
if search_query:
|
||||
return Query.get(search_query).editors_picks.all()
|
||||
else:
|
||||
return SearchPromotion.objects.none()
|
||||
|
|
|
|||
|
|
@ -71,6 +71,10 @@ class TestGetSearchPromotionsTemplateTag(TestCase):
|
|||
search_picks = list(get_search_promotions("root page"))
|
||||
self.assertEqual(search_picks, [pick])
|
||||
|
||||
def test_get_search_promotions_with_none_query_string(self):
|
||||
search_picks = list(get_search_promotions(None))
|
||||
self.assertEqual(search_picks, [])
|
||||
|
||||
|
||||
class TestSearchPromotionsIndexView(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue