diff --git a/wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/add.html b/wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/add.html
index dd9fa17a2a..5abc78f692 100644
--- a/wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/add.html
+++ b/wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/add.html
@@ -1,40 +1,30 @@
{% extends "wagtailadmin/generic/form.html" %}
{% load i18n wagtailadmin_tags %}
-{% block titletag %}{% trans "Add search promotion" %}{% endblock %}
-{% block content %}
- {% trans "Add search pick" as add_str %}
- {% include "wagtailadmin/shared/header.html" with title=add_str icon="pick" %}
-
-
- {% icon name='help' %}
- {% blocktrans trimmed %}
-
Promoted search results are a means of recommending specific pages or external links that might not organically come high up in search results. E.g recommending your primary donation page to a user searching with the less common term "giving".
- {% endblocktrans %}
+{% block before_form %}
+
-
+ {% blocktrans trimmed %}
+
The "Search term(s)/phrase" field below must contain the full and exact search for which you wish to provide recommended results, including any misspellings/user error. To help, you can choose from search terms that have been popular with users of your site.
+ {% endblocktrans %}
{% endblock %}
+{% block form_content %}
+
+ -
+ {% include "wagtailsearchpromotions/queries/chooser_field.html" with field=form.query_string only %}
+
+ -
+ {% include "wagtailsearchpromotions/includes/searchpromotions_formset.html" with formset=searchpicks_formset only %}
+
+
+{% endblock %}
+
{% block extra_js %}
{{ block.super }}
diff --git a/wagtail/contrib/search_promotions/tests.py b/wagtail/contrib/search_promotions/tests.py
index d5a2650383..7e5511558a 100644
--- a/wagtail/contrib/search_promotions/tests.py
+++ b/wagtail/contrib/search_promotions/tests.py
@@ -21,6 +21,7 @@ from wagtail.contrib.search_promotions.templatetags.wagtailsearchpromotions_tags
)
from wagtail.log_actions import registry as log_registry
from wagtail.test.utils import WagtailTestUtils
+from wagtail.test.utils.template_tests import AdminTemplateTestUtils
class TestSearchPromotions(TestCase):
@@ -175,7 +176,7 @@ class TestGetSearchPromotionsTemplateTag(TestCase):
self.assertEqual(search_picks, [])
-class TestSearchPromotionsIndexView(WagtailTestUtils, TestCase):
+class TestSearchPromotionsIndexView(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
def setUp(self):
self.user = self.login()
@@ -183,6 +184,10 @@ class TestSearchPromotionsIndexView(WagtailTestUtils, TestCase):
response = self.client.get(reverse("wagtailsearchpromotions:index"))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailsearchpromotions/index.html")
+ self.assertBreadcrumbsItemsRendered(
+ [{"url": "", "label": "Promoted search results"}],
+ response.content,
+ )
def test_search(self):
response = self.client.get(
@@ -463,7 +468,7 @@ class TestSearchPromotionsIndexView(WagtailTestUtils, TestCase):
self.assertIsNone(soup.select_one(f'a[href="{add_url}"]'))
-class TestSearchPromotionsAddView(WagtailTestUtils, TestCase):
+class TestSearchPromotionsAddView(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
def setUp(self):
self.user = self.login()
@@ -471,6 +476,16 @@ class TestSearchPromotionsAddView(WagtailTestUtils, TestCase):
response = self.client.get(reverse("wagtailsearchpromotions:add"))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailsearchpromotions/add.html")
+ self.assertBreadcrumbsItemsRendered(
+ [
+ {
+ "url": reverse("wagtailsearchpromotions:index"),
+ "label": "Promoted search results",
+ },
+ {"url": "", "label": "New: Promoted search result"},
+ ],
+ response.content,
+ )
def test_post(self):
# Submit
diff --git a/wagtail/contrib/search_promotions/views/settings.py b/wagtail/contrib/search_promotions/views/settings.py
index 654302b1dd..650b5807f1 100644
--- a/wagtail/contrib/search_promotions/views/settings.py
+++ b/wagtail/contrib/search_promotions/views/settings.py
@@ -126,6 +126,7 @@ def save_searchpicks(query, new_query, searchpicks_formset):
class CreateView(generic.CreateView):
+ model = Query
permission_policy = ModelPermissionPolicy(SearchPromotion)
index_url_name = "wagtailsearchpromotions:index"
edit_url_name = "wagtailsearchpromotions:edit"
@@ -134,6 +135,9 @@ class CreateView(generic.CreateView):
success_message = gettext_lazy("Editor's picks for '%(query)s' created.")
error_message = gettext_lazy("Recommendations have not been created due to errors")
template_name = "wagtailsearchpromotions/add.html"
+ header_icon = "pick"
+ page_subtitle = gettext_lazy("Promoted search result")
+ _show_breadcrumbs = True
def get_success_message(self, instance):
return self.success_message % {"query": instance}
@@ -144,6 +148,11 @@ class CreateView(generic.CreateView):
return " ".join(error for error in formset_errors)
return super().get_error_message()
+ def get_breadcrumbs_items(self):
+ breadcrumbs = super().get_breadcrumbs_items()
+ breadcrumbs[-2]["label"] = _("Promoted search results")
+ return breadcrumbs
+
def form_valid(self, form):
self.form = form
self.object = Query.get(form.cleaned_data["query_string"])