From 121c1cf4ca66629dbe0cdf287833cc81dca706c5 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 27 Oct 2019 18:44:21 -0700 Subject: [PATCH] help: Fix showing manual pages in fallback cases - When a manual page for a certain language is not found, redirect to 'en' for that manual page. Simply showing English content will cause issues with serving images. - Don't use language preferences unless the URL language is not generic. The language of the page shown will always correspond to the language in the URL. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/help/help.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plinth/modules/help/help.py b/plinth/modules/help/help.py index cdba80c50..f16893dc9 100644 --- a/plinth/modules/help/help.py +++ b/plinth/modules/help/help.py @@ -123,25 +123,26 @@ def about(request): def manual(request, lang=None, page=None): """Serve the manual page from the 'doc' directory""" - language_code = get_language_from_request(request) - if not lang or lang == '-': - kwargs = {'lang': language_code} + kwargs = {'lang': get_language_from_request(request)} if page: return HttpResponseRedirect( reverse('help:manual-page', kwargs=dict(kwargs, page=page))) return HttpResponseRedirect(reverse('help:manual', kwargs=kwargs)) - def read_file(language_code, page): + def read_file(lang, file_name): """Read the page from disk and return contents or None.""" - page_file = pathlib.Path(cfg.doc_dir) / 'manual' / language_code / page + page_file = pathlib.Path(cfg.doc_dir) / 'manual' / lang / file_name return page_file.read_text() if page_file.exists() else None page = page or 'freedombox-manual' - page = f'{page}.part.html' - content = read_file(language_code, page) or read_file(language_code, 'en') + content = read_file(lang, f'{page}.part.html') if not content: + if lang != 'en': + return HttpResponseRedirect( + reverse('help:manual-page', kwargs=dict(lang='en', page=page))) + raise Http404 return TemplateResponse(