mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-14 20:10:59 +00:00
Merge pull request #1849 from gasman/feature/page-chooser-search-pagination
Add pagination to page chooser search
This commit is contained in:
commit
f7e19f2a06
3 changed files with 15 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{% load i18n %}
|
||||
{% load i18n wagtailadmin_tags %}
|
||||
|
||||
<h2>
|
||||
{% blocktrans count counter=pages|length %}
|
||||
{% blocktrans count counter=pages.paginator.count %}
|
||||
There is one match
|
||||
{% plural %}
|
||||
There are {{ counter }} matches
|
||||
|
|
@ -10,4 +10,7 @@
|
|||
|
||||
{% if pages %}
|
||||
{% include "wagtailadmin/pages/listing/_list_choose.html" with show_parent=1 pages=pages parent_page=parent_page %}
|
||||
|
||||
{% url 'wagtailadmin_choose_page_search' as pagination_base_url %}
|
||||
{% paginate pages base_url=pagination_base_url classnames="navigate-pages" %}
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,12 @@ function(modal) {
|
|||
|
||||
return false;
|
||||
});
|
||||
/* pagination links within search results should be AJAX-fetched
|
||||
and the result loaded into .page-results (and ajaxified) */
|
||||
$('.page-results a.navigate-pages', modal.body).click(function() {
|
||||
$('.page-results', modal.body).load(this.href, ajaxifySearchResults);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -116,20 +116,20 @@ def search(request, parent_page_id=None):
|
|||
depth=1 # never include root
|
||||
)
|
||||
pages = filter_page_type(pages, desired_classes)
|
||||
pages = pages.search(search_form.cleaned_data['q'], fields=['title'])[:10]
|
||||
pages = pages.search(search_form.cleaned_data['q'], fields=['title'])
|
||||
else:
|
||||
pages = Page.objects.none()
|
||||
|
||||
shown_pages = []
|
||||
paginator, pages = paginate(request, pages, per_page=25)
|
||||
|
||||
for page in pages:
|
||||
page.can_choose = True
|
||||
shown_pages.append(page)
|
||||
|
||||
return render(
|
||||
request, 'wagtailadmin/chooser/_search_results.html',
|
||||
shared_context(request, {
|
||||
'searchform': search_form,
|
||||
'pages': shown_pages,
|
||||
'pages': pages,
|
||||
'page_type_string': page_type_string,
|
||||
})
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue