mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Merge branch 'redirects-fixes' of https://github.com/kaedroho/wagtail into kaedroho-redirects-fixes
This commit is contained in:
commit
a603961134
@ -40,6 +40,9 @@ class Redirect(models.Model):
|
||||
|
||||
@staticmethod
|
||||
def normalise_path(url):
|
||||
# Strip whitespace
|
||||
url = url.strip()
|
||||
|
||||
# Parse url
|
||||
url_parsed = urlparse(url)
|
||||
|
||||
|
@ -20,6 +20,8 @@ class TestRedirects(TestCase):
|
||||
self.assertEqual(path, normalise_path('Hello/world.html/?foo=Bar&Baz=quux2')) # Trailing slashes are ignored
|
||||
self.assertEqual(path, normalise_path('/Hello/world.html?foo=Bar&Baz=quux2#cool')) # Fragments are ignored
|
||||
self.assertEqual(path, normalise_path('/Hello/world.html?Baz=quux2&foo=Bar')) # Order of query string parameters are ignored
|
||||
self.assertEqual(path, normalise_path(' /Hello/world.html?foo=Bar&Baz=quux2')) # Leading whitespace
|
||||
self.assertEqual(path, normalise_path('/Hello/world.html?foo=Bar&Baz=quux2 ')) # Trailing whitespace
|
||||
|
||||
# Test against different paths
|
||||
self.assertNotEqual(path, normalise_path('/hello/world.html?foo=Bar&Baz=quux2')) # 'hello' is lowercase
|
||||
@ -119,6 +121,7 @@ class TestRedirectsAddView(TestCase, WagtailTestUtils):
|
||||
redirects = models.Redirect.objects.filter(old_path='/test')
|
||||
self.assertEqual(redirects.count(), 1)
|
||||
self.assertEqual(redirects.first().redirect_link, 'http://www.test.com/')
|
||||
self.assertEqual(redirects.first().site, None)
|
||||
|
||||
def test_add_validation_error(self):
|
||||
response = self.post({
|
||||
|
@ -108,9 +108,7 @@ def add(request):
|
||||
if request.POST:
|
||||
form = form_class(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
theredirect = form.save(commit=False)
|
||||
theredirect.site = request.site
|
||||
theredirect.save()
|
||||
theredirect = form.save()
|
||||
|
||||
messages.success(request, _("Redirect '{0}' added.").format(theredirect.title), buttons=[
|
||||
messages.button(reverse('wagtailredirects:edit', args=(theredirect.id,)), _('Edit'))
|
||||
|
Loading…
Reference in New Issue
Block a user