misc: fallback skeleton to standard page template (#46412)
gitea/combo/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-05-24 08:20:59 +02:00
parent 95c0377933
commit 759e18c70c
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()