kopia lustrzana https://github.com/wagtail/wagtail
Use breadcrumbs and simplify template overrides in search promotions CreateView
rodzic
c498be3234
commit
6db13fb704
|
@ -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" %}
|
||||
|
||||
<div class="nice-padding">
|
||||
<div class="help-block help-info">
|
||||
{% icon name='help' %}
|
||||
{% blocktrans trimmed %}
|
||||
<p>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 "<em>giving</em>".</p>
|
||||
{% endblocktrans %}
|
||||
{% block before_form %}
|
||||
<div class="help-block help-info w-form-width">
|
||||
{% icon name='help' %}
|
||||
{% blocktrans trimmed %}
|
||||
<p>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 "<em>giving</em>".</p>
|
||||
{% endblocktrans %}
|
||||
|
||||
{% blocktrans trimmed %}
|
||||
<p>The "Search term(s)/phrase" field below must contain the full and exact search for which you wish to provide recommended results, <em>including</em> any misspellings/user error. To help, you can choose from search terms that have been popular with users of your site.</p>
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
<form action="{% url 'wagtailsearchpromotions:add' %}" method="POST" novalidate>
|
||||
{% csrf_token %}
|
||||
|
||||
<ul class="fields">
|
||||
<li>
|
||||
{% include "wagtailsearchpromotions/queries/chooser_field.html" with field=form.query_string only %}
|
||||
</li>
|
||||
<li>
|
||||
{% include "wagtailsearchpromotions/includes/searchpromotions_formset.html" with formset=searchpicks_formset only %}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{% block footer %}
|
||||
{{ block.super }}
|
||||
{% endblock %}
|
||||
</form>
|
||||
{% blocktrans trimmed %}
|
||||
<p>The "Search term(s)/phrase" field below must contain the full and exact search for which you wish to provide recommended results, <em>including</em> any misspellings/user error. To help, you can choose from search terms that have been popular with users of your site.</p>
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block form_content %}
|
||||
<ul class="fields">
|
||||
<li>
|
||||
{% include "wagtailsearchpromotions/queries/chooser_field.html" with field=form.query_string only %}
|
||||
</li>
|
||||
<li>
|
||||
{% include "wagtailsearchpromotions/includes/searchpromotions_formset.html" with formset=searchpicks_formset only %}
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% versioned_static 'wagtailsearchpromotions/js/query-chooser-modal.js' %}"></script>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"])
|
||||
|
|
Ładowanie…
Reference in New Issue