edit_current_site redirect should not break when request.site is undefined

This commit is contained in:
Matt Westcott 2015-10-23 11:27:47 +01:00
parent 42af5c10af
commit 66f595cb5d
2 changed files with 15 additions and 1 deletions

View file

@ -144,6 +144,18 @@ class TestMultiSite(BaseTestSettingView):
response = self.client.get(start_url, follow=True, HTTP_HOST=self.other_site.hostname)
self.assertEqual([(dest_url, 302)], response.redirect_chain)
def test_with_no_current_site(self):
"""
Redirection should not break if the current request does not correspond to a site
"""
self.default_site.is_default_site = False
self.default_site.save()
start_url = reverse('wagtailsettings_edit', args=[
'tests', 'testsetting'])
response = self.client.get(start_url, follow=True, HTTP_HOST="noneoftheabove.example.com")
self.assertEqual(302, response.redirect_chain[0][1])
def test_switcher(self):
""" Check that the switcher form exists in the page """
response = self.get()

View file

@ -34,7 +34,9 @@ def get_setting_edit_handler(model):
def edit_current_site(request, app_name, model_name):
# Redirect the user to the edit page for the current site
return redirect('wagtailsettings_edit', request.site.pk, app_name, model_name)
# (or the current request does not correspond to a site, the first site in the list)
site = request.site or Site.objects.first()
return redirect('wagtailsettings_edit', site.pk, app_name, model_name)
def edit(request, site_pk, app_name, model_name):