0
0
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:
Matt Westcott 2015-09-03 16:22:45 +01:00
commit a603961134
3 changed files with 7 additions and 3 deletions

View File

@ -40,6 +40,9 @@ class Redirect(models.Model):
@staticmethod
def normalise_path(url):
# Strip whitespace
url = url.strip()
# Parse url
url_parsed = urlparse(url)

View File

@ -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({

View File

@ -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'))