Merge branch 'davecranwell-fix/page-chooser-model-restrictions'

This commit is contained in:
Matt Westcott 2014-08-27 11:26:56 +01:00
commit c2458a01dd
5 changed files with 37 additions and 14 deletions

View file

@ -19,6 +19,7 @@ Bug fixes
~~~~~~~~~
* Page URL generation now returns correct URLs for sites that have the main 'serve' view rooted somewhere other than '/'.
* Search results in the page chooser now respect the page_type parameter on PageChooserPanel.
Upgrade considerations
======================

View file

@ -1,11 +1,19 @@
{% load i18n %}
{% if page_types_restricted %}
<p class="help-block help-warning">
{% 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 %}
</p>
{% endif %}
{% if not is_searching %}
<h2>{% trans "Explorer" %}</h2>
{% include "wagtailadmin/shared/breadcrumb.html" with page=parent_page choosing=1 %}
{% else %}
<h2>
{% blocktrans count counter=pages.count %}
{% blocktrans count counter=pages|length %}
There is one match
{% plural %}
There are {{ counter }} matches
@ -13,8 +21,10 @@
</h2>
{% 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 %}

View file

@ -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 page_types_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" %}
<div class="nice-padding">
{% include 'wagtailadmin/chooser/_link_types.html' with current='internal' %}
<div class="page-results">
{# content in here will be replaced by live search results #}
{% include 'wagtailadmin/chooser/_search_results.html' %}
</div>
</div>

View file

@ -6,7 +6,7 @@
<h1 class="icon icon-{{ icon }}">{{ title }} <span>{{ subtitle }}</span></h1>
</div>
{% if search_url %}
<form class="col search-form" action="{% url search_url %}" method="get">
<form class="col search-form" action="{% url search_url %}{% if query_parameters %}?{{ query_parameters }}{% endif %}" method="get">
<ul class="fields">
{% for field in search_form %}
{% include "wagtailadmin/shared/field_as_li.html" with field=field field_classes="field-small iconfield" input_classes="icon-search" %}

View file

@ -3,6 +3,7 @@ from django.shortcuts import get_object_or_404, render
from django.http import Http404
from django.utils.http import urlencode
from django.contrib.auth.decorators import permission_required
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from wagtail.wagtailadmin.modal_workflow import render_modal_workflow
from wagtail.wagtailadmin.forms import SearchForm, ExternalLinkChooserForm, ExternalLinkChooserWithLinkTextForm, EmailLinkChooserForm, EmailLinkChooserWithLinkTextForm
@ -25,6 +26,7 @@ def browse(request, parent_page_id=None):
content_type_app_name, content_type_model_name = page_type.split('.')
is_searching = False
page_types_restricted = page_type != 'wagtailcore.page'
try:
content_type = ContentType.objects.get_by_natural_key(content_type_app_name, content_type_model_name)
@ -66,8 +68,11 @@ def browse(request, parent_page_id=None):
return render(request, 'wagtailadmin/chooser/_search_results.html', {
'querystring': get_querystring(request),
'searchform': search_form,
'pages': pages,
'is_searching': is_searching
'pages': shown_pages,
'is_searching': is_searching,
'page_type_string': page_type,
'page_type': desired_class,
'page_types_restricted': page_types_restricted
})
return render_modal_workflow(request, 'wagtailadmin/chooser/browse.html', 'wagtailadmin/chooser/browse.js', {
@ -77,7 +82,10 @@ def browse(request, parent_page_id=None):
'parent_page': parent_page,
'pages': shown_pages,
'search_form': search_form,
'is_searching': False
'is_searching': False,
'page_type_string': page_type,
'page_type': desired_class,
'page_types_restricted': page_types_restricted
})