0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Added {% get_search_picks %} template tag

This commit is contained in:
Karl Hobley 2015-07-06 10:36:51 +01:00
parent 049efc8281
commit dfebe2087d
3 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,11 @@
from django import template
from wagtail.wagtailsearch.models import Query
register = template.Library()
@register.assignment_tag()
def get_search_picks(search_query):
return Query.get(search_query).editors_picks.all()

View File

@ -4,6 +4,7 @@ from django.core.urlresolvers import reverse
from wagtail.tests.utils import WagtailTestUtils
from wagtail.wagtailsearch.models import Query
from wagtail.contrib.wagtailsearchpicks.models import SearchPick
from wagtail.contrib.wagtailsearchpicks.templatetags.wagtailsearchpicks_tags import get_search_picks
class TestSearchPicks(TestCase):
@ -48,6 +49,29 @@ class TestSearchPicks(TestCase):
self.assertEqual(Query.get("root page").editors_picks.last().description, "Last search pick")
class TestGetSearchPicksTemplateTag(TestCase):
def test_get_search_picks_template_tag(self):
# Create a search pick to the root page
pick = SearchPick.objects.create(
query=Query.get("root page"),
page_id=1,
sort_order=0,
description="First search pick",
)
# Create another search pick against a different query
SearchPick.objects.create(
query=Query.get("root page again"),
page_id=1,
sort_order=0,
description="Second search pick",
)
# Check
search_picks = list(get_search_picks("root page"))
self.assertEqual(search_picks, [pick])
class TestSearchPicksIndexView(TestCase, WagtailTestUtils):
def setUp(self):
self.login()