From cd39f305a53b9049245a4c1ef4dc5fe9304ae64c Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Fri, 25 Jul 2014 14:36:38 +0100 Subject: [PATCH] fixing search in page chooser, which would allow selection of any page even if the developer has chosen to restrict to only certain types allowed. --- .../wagtailadmin/chooser/_search_results.html | 22 ++++++++++++++----- .../wagtailadmin/chooser/browse.html | 12 ++++++---- .../templates/wagtailadmin/shared/header.html | 2 +- wagtail/wagtailadmin/views/chooser.py | 14 +++++++++--- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/chooser/_search_results.html b/wagtail/wagtailadmin/templates/wagtailadmin/chooser/_search_results.html index 6f575259e..7554187eb 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/chooser/_search_results.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/chooser/_search_results.html @@ -1,11 +1,19 @@ {% load i18n %} + +{% if is_restricted %} +

+ {% blocktrans with type=page_type.get_verbose_name %} + Only pages of type "{{ type }}" may be chosen for this field. Search results will exclude pages of other types. + {% endblocktrans %} +

+{% endif %} + {% if not is_searching %}

{% trans "Explorer" %}

{% include "wagtailadmin/shared/breadcrumb.html" with page=parent_page choosing=1 %} - {% else %}

- {% blocktrans count counter=pages.count %} + {% blocktrans count counter=pages|length %} There is one match {% plural %} There are {{ counter }} matches @@ -13,8 +21,10 @@

{% endif %} -{% if is_searching %} - {% include "wagtailadmin/pages/list.html" with choosing=1 show_parent=1 pages=pages parent_page=parent_page %} -{% else %} - {% include "wagtailadmin/pages/list.html" with choosing=1 allow_navigation=1 orderable=0 pages=pages parent_page=parent_page %} +{% if pages %} + {% if is_searching%} + {% include "wagtailadmin/pages/list.html" with choosing=1 show_parent=1 pages=pages parent_page=parent_page %} + {% else %} + {% include "wagtailadmin/pages/list.html" with choosing=1 allow_navigation=1 orderable=0 pages=pages parent_page=parent_page %} + {% endif %} {% endif %} \ No newline at end of file diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/chooser/browse.html b/wagtail/wagtailadmin/templates/wagtailadmin/chooser/browse.html index 5714ddb45..50e81c0f1 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/chooser/browse.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/chooser/browse.html @@ -1,13 +1,17 @@ {% load i18n %} -{% trans "Choose a page" as choose_str %} -{% include "wagtailadmin/shared/header.html" with title=choose_str search_url="wagtailadmin_choose_page" icon="doc-empty-inverse" %} +{% if is_restricted %} + {% trans "Choose" as choose_str %} + {% trans page_type.get_verbose_name as subtitle %} +{% else %} + {% trans "Choose a page" as choose_str %} +{% endif %} + +{% include "wagtailadmin/shared/header.html" with title=choose_str subtitle=subtitle search_url="wagtailadmin_choose_page" query_parameters="page_type="|add:page_type_string icon="doc-empty-inverse" %}
{% include 'wagtailadmin/chooser/_link_types.html' with current='internal' %}
- {# content in here will be replaced by live search results #} - {% include 'wagtailadmin/chooser/_search_results.html' %}
diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/shared/header.html b/wagtail/wagtailadmin/templates/wagtailadmin/shared/header.html index be391989d..b5de84832 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/shared/header.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/shared/header.html @@ -5,7 +5,7 @@

{{ title }} {{ subtitle }}

{% if search_url %} -
+