misc: prefer latest match when looking for skeleton (#38899)
This commit is contained in:
parent
dea9a0484a
commit
f17553257c
|
@ -246,7 +246,8 @@ def skeleton(request):
|
||||||
selected_page = None
|
selected_page = None
|
||||||
same_domain_pages = []
|
same_domain_pages = []
|
||||||
|
|
||||||
# look in redirect pages after the best match for the source
|
# look in redirect pages after the best match for the source, in case of
|
||||||
|
# several exact matches take the latest.
|
||||||
redirect_pages = Page.objects.exclude(redirect_url__isnull=True).exclude(redirect_url='')
|
redirect_pages = Page.objects.exclude(redirect_url__isnull=True).exclude(redirect_url='')
|
||||||
for page in redirect_pages:
|
for page in redirect_pages:
|
||||||
try:
|
try:
|
||||||
|
@ -256,7 +257,7 @@ def skeleton(request):
|
||||||
if not redirect_url:
|
if not redirect_url:
|
||||||
continue
|
continue
|
||||||
if source.startswith(redirect_url):
|
if source.startswith(redirect_url):
|
||||||
if selected_page is None or len(redirect_url) > len(selected_page.get_redirect_url()):
|
if selected_page is None or len(redirect_url) >= len(selected_page.get_redirect_url()):
|
||||||
selected_page = page
|
selected_page = page
|
||||||
|
|
||||||
if urlparse.urlparse(redirect_url).netloc == netloc:
|
if urlparse.urlparse(redirect_url).netloc == netloc:
|
||||||
|
|
|
@ -339,6 +339,22 @@ def test_page_skeleton(app):
|
||||||
resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/'))
|
resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/'))
|
||||||
assert resp.headers['x-combo-page-id'] == '__root'
|
assert resp.headers['x-combo-page-id'] == '__root'
|
||||||
|
|
||||||
|
# prefer last match
|
||||||
|
Page.objects.all().delete()
|
||||||
|
page = Page(title='Elsewhere', slug='elsewhere', template_name='standard',
|
||||||
|
redirect_url='http://example.net/foo/')
|
||||||
|
page.save()
|
||||||
|
cell = TextCell(page=page, placeholder='footer', text='Foobar1', order=0)
|
||||||
|
cell.save()
|
||||||
|
page = Page(title='Elsewhere2', slug='elsewhere2', template_name='standard',
|
||||||
|
redirect_url='http://example.net/foo/', order=2)
|
||||||
|
page.save()
|
||||||
|
cell = TextCell(page=page, placeholder='footer', text='Foobar2', order=0)
|
||||||
|
cell.save()
|
||||||
|
|
||||||
|
resp = app.get('/__skeleton__/?source=%s' % quote('http://example.net/foo/bar'))
|
||||||
|
assert "Foobar2" in resp.text
|
||||||
|
|
||||||
|
|
||||||
def test_subpage_location(app):
|
def test_subpage_location(app):
|
||||||
Page.objects.all().delete()
|
Page.objects.all().delete()
|
||||||
|
|
Loading…
Reference in New Issue