Improve redirect links search in the admin

pull/4319/head
Michael Harrison 2018-02-15 13:53:22 -06:00 zatwierdzone przez Loic Teixeira
rodzic cde31260d8
commit 4da0bd7bd2
5 zmienionych plików z 13 dodań i 1 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ Changelog
* Persist tab hash in URL to allow direct navigation to tabs in the admin interface (Ben Weatherman)
* Animate the chevron icon when opening sub-menus in the admin (Carlo Ascani)
* Look through the target link and target page slug (in addition to the old slug) when searching for redirects in the admin (Michael Harrison)
* Fix: Status button on 'edit page' now links to the correct URL when live and draft slug differ (LB (Ben Johnston))
* Fix: Image title text in the gallery and in the chooser now wraps for long filenames (LB (Ben Johnston), Luiz Boaretto)
* Fix: Move image editor action buttons to the bottom of the form on mobile (Julian Gallo)

Wyświetl plik

@ -277,6 +277,7 @@ Contributors
* Carlo Ascani
* Julian Gallo
* Dan Dietz
* Michael Harrison
Translators
===========

Wyświetl plik

@ -16,6 +16,7 @@ Other features
* Persist tab hash in URL to allow direct navigation to tabs in the admin interface (Ben Weatherman)
* Animate the chevron icon when opening sub-menus in the admin (Carlo Ascani)
* Look through the target link and target page slug (in addition to the old slug) when searching for redirects in the admin (Michael Harrison)
Bug fixes
~~~~~~~~~

Wyświetl plik

@ -291,6 +291,12 @@ class TestRedirectsIndexView(TestCase, WagtailTestUtils):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['query_string'], "Hello")
def test_search_results(self):
models.Redirect.objects.create(old_path="/aaargh", redirect_link="http://torchbox.com/")
models.Redirect.objects.create(old_path="/torchbox", redirect_link="http://aaargh.com/")
response = self.get({'q': "aaargh"})
self.assertEqual(len(response.context['redirects']), 2)
def test_pagination(self):
pages = ['0', '1', '-1', '9999', 'Not a page']
for page in pages:

Wyświetl plik

@ -1,3 +1,4 @@
from django.db.models import Q
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils.translation import ugettext as _
@ -24,7 +25,9 @@ def index(request):
# Search
if query_string:
redirects = redirects.filter(old_path__icontains=query_string)
redirects = redirects.filter(Q(old_path__icontains=query_string) |
Q(redirect_page__url_path__icontains=query_string) |
Q(redirect_link__icontains=query_string))
# Ordering (A bit useless at the moment as only 'old_path' is allowed)
if ordering not in ['old_path']: