Skip to content

Commit

Permalink
Add locale labels in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolab authored and gasman committed Jan 13, 2022
1 parent 6f5fa46 commit 85e5864
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h3 id="page-types-title" class="filter-title">{% trans "Page types" %}</h3>
</nav>
{% endif %}

{% include "wagtailadmin/pages/listing/_list_explore.html" with show_parent=1 sortable=1 sortable_by_type=0 show_bulk_actions=1 %}
{% include "wagtailadmin/pages/listing/_list_explore.html" with show_parent=1 sortable=1 sortable_by_type=0 show_bulk_actions=1 show_locale_labels=show_locale_labels %}

{% url 'wagtailadmin_pages:search' as pagination_base_url %}
{% paginate pages base_url=pagination_base_url %}
Expand Down
8 changes: 8 additions & 0 deletions wagtail/admin/views/pages/search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.paginator import Paginator
from django.http import Http404
Expand Down Expand Up @@ -41,6 +42,11 @@ def page_filter_search(q, pages, all_pages=None, ordering=None):
@user_passes_test(user_has_any_page_permission)
def search(request):
pages = all_pages = Page.objects.all().prefetch_related('content_type').specific()
show_locale_labels = getattr(settings, 'WAGTAIL_I18N_ENABLED', False)
if show_locale_labels:
pages = pages.select_related('locale')
all_pages = all_pages.select_related('locale')

q = MATCH_ALL
content_types = []
pagination_query_params = QueryDict({}, mutable=True)
Expand Down Expand Up @@ -113,6 +119,7 @@ def search(request):
'selected_content_type': selected_content_type,
'ordering': ordering,
'pagination_query_params': pagination_query_params.urlencode(),
'show_locale_labels': show_locale_labels,
})
else:
return TemplateResponse(request, "wagtailadmin/pages/search.html", {
Expand All @@ -124,4 +131,5 @@ def search(request):
'selected_content_type': selected_content_type,
'ordering': ordering,
'pagination_query_params': pagination_query_params.urlencode(),
'show_locale_labels': show_locale_labels,
})

0 comments on commit 85e5864

Please sign in to comment.