misc: fallback skeleton to standard page template (#46412) #106

Merged
fpeters merged 1 commits from wip/46412-missing-template-in-skeleton into main 2023-05-26 17:22:43 +02:00
2 changed files with 35 additions and 1 deletions

View File

@ -340,7 +340,10 @@ def skeleton(request):
cells = [x for x in cells if x.is_visible(request, context={'render_skeleton': True})]
pages = selected_page.get_parents_and_self()
combo_template = settings.COMBO_PUBLIC_TEMPLATES[selected_page.template_name]
try:
combo_template = settings.COMBO_PUBLIC_TEMPLATES[selected_page.template_name]
except KeyError:
combo_template = settings.COMBO_PUBLIC_TEMPLATES['standard']
extend_with_parent_cells(cells, hierarchy=pages)
mark_duplicated_slugs(cells)
@ -356,6 +359,11 @@ def skeleton(request):
}
template_name = combo_template['template']
try:
get_template(template_name)
except TemplateDoesNotExist:
template_name = settings.COMBO_PUBLIC_TEMPLATES['standard'].get('template')
response = render(request, template_name, ctx)
response.content = b'{%% with page_template_name="%s" %%}%s{%% endwith %%}' % (
selected_page.template_name.encode(),

View File

@ -511,6 +511,32 @@ def test_page_skeleton(app):
assert "Foobar2" in resp.text
def test_page_skeleton_missing_template(app):
Page.objects.all().delete()
page = Page(
title='Elsewhere', slug='elsewhere', template_name='missing', redirect_url='http://example.net/foo/'
)
page.save()
# template that is not even defined
app.get('/__skeleton__/?source=%s' % quote('http://example.net/'), status=200)
# template with missing file
with override_settings(
COMBO_PUBLIC_TEMPLATES={
'standard': {
'name': 'Standard',
'template': 'combo/page_template.html',
},
'missing': {
'name': 'Missing',
'template': 'combo/page_missing_template.html',
},
}
):
app.get('/__skeleton__/?source=%s' % quote('http://example.net/'), status=200)
def test_subpage_location(app):
Page.objects.all().delete()