mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 17:36:49 +01:00
Add 'no results' messages to chooser results
Add attributes for chooser template overrides Fix incorrect variable name when outputting hidden fields
This commit is contained in:
parent
df27a164ec
commit
b93729fd86
@ -13,7 +13,7 @@
|
||||
{% if filter_form.fields %}
|
||||
<form data-chooser-modal-search class="search-bar" action="{% url results_url_name %}" method="GET" novalidate>
|
||||
{% if filter_form.hidden_fields %}
|
||||
{% for field in form.hidden_fields %}{{ field }}{% endfor %}
|
||||
{% for field in filter_form.hidden_fields %}{{ field }}{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if filter_form.visible_fields %}
|
||||
@ -28,7 +28,7 @@
|
||||
{% endif %}
|
||||
|
||||
<div id="search-results" class="listing">
|
||||
{% include "wagtailadmin/generic/chooser/results.html" %}
|
||||
{% include view.results_template_name %}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
@ -1,4 +1,28 @@
|
||||
{% load i18n wagtailadmin_tags %}
|
||||
|
||||
{% component table %}
|
||||
{% include "wagtailadmin/shared/pagination_nav.html" with items=results linkurl=results_url_name %}
|
||||
{% if results %}
|
||||
{% if is_searching %}
|
||||
{% block search_results_count %}
|
||||
<h2 role="alert">
|
||||
{% blocktrans trimmed count counter=results.paginator.count %}
|
||||
There is {{ counter }} match
|
||||
{% plural %}
|
||||
There are {{ counter }} matches
|
||||
{% endblocktrans %}
|
||||
</h2>
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
|
||||
{% component table %}
|
||||
{% include "wagtailadmin/shared/pagination_nav.html" with items=results linkurl=results_url_name %}
|
||||
{% else %}
|
||||
{% if is_searching %}
|
||||
{% block no_search_results_message %}
|
||||
<p role="alert">{% blocktrans trimmed %}Sorry, there are no matches for "<em>{{ search_query }}</em>"{% endblocktrans %}</p>
|
||||
{% endblock %}
|
||||
{% else %}
|
||||
{% block no_items_message %}
|
||||
<p>{% trans "No items have been created." %}</p>
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -41,6 +41,8 @@ class BaseChooseView(ModalPageFurnitureMixin, ContextMixin, View):
|
||||
icon = "snippet"
|
||||
page_title = _("Choose")
|
||||
filter_form_class = None
|
||||
template_name = "wagtailadmin/generic/chooser/chooser.html"
|
||||
results_template_name = "wagtailadmin/generic/chooser/results.html"
|
||||
|
||||
def get_object_list(self):
|
||||
return self.model.objects.all()
|
||||
@ -70,10 +72,15 @@ class BaseChooseView(ModalPageFurnitureMixin, ContextMixin, View):
|
||||
if search_query:
|
||||
search_backend = get_search_backend()
|
||||
objects = search_backend.search(search_query, objects)
|
||||
self.is_searching = True
|
||||
self.search_query = search_query
|
||||
return objects
|
||||
|
||||
def get(self, request):
|
||||
objects = self.get_object_list()
|
||||
self.is_searching = False
|
||||
self.search_query = None
|
||||
|
||||
self.filter_form = self.get_filter_form()
|
||||
if self.filter_form.is_valid():
|
||||
objects = self.filter_object_list(objects, self.filter_form)
|
||||
@ -102,6 +109,8 @@ class BaseChooseView(ModalPageFurnitureMixin, ContextMixin, View):
|
||||
"results": self.results,
|
||||
"table": self.table,
|
||||
"results_url_name": self.results_url_name,
|
||||
"is_searching": self.is_searching,
|
||||
"search_query": self.search_query,
|
||||
}
|
||||
)
|
||||
return context
|
||||
@ -119,7 +128,7 @@ class ChooseView(BaseChooseView):
|
||||
def render_to_response(self):
|
||||
return render_modal_workflow(
|
||||
self.request,
|
||||
"wagtailadmin/generic/chooser/chooser.html",
|
||||
self.template_name,
|
||||
None,
|
||||
self.get_context_data(),
|
||||
json_data={
|
||||
@ -132,7 +141,7 @@ class ChooseResultsView(BaseChooseView):
|
||||
def render_to_response(self):
|
||||
return TemplateResponse(
|
||||
self.request,
|
||||
"wagtailadmin/generic/chooser/results.html",
|
||||
self.results_template_name,
|
||||
self.get_context_data(),
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user