From 56250562d48f29b926e960e0553aa351c30231de Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 24 Mar 2020 14:43:58 -0700 Subject: [PATCH] help: Move custom static file handling into app from central place Tests performed: - Print the calls to _mount_static_directory() before and after the changes. They should print the same. - With English as the preferred language, visit the user manual. Images should be visible. Visit MediaWiki manual page with learn more link in MediaWiki. Images should be visible. - Repeat with Spanish as the preferred language. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- plinth/modules/help/__init__.py | 15 ++++++++++++++- plinth/web_server.py | 7 ------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/plinth/modules/help/__init__.py b/plinth/modules/help/__init__.py index 8e7420733..b062bdeb1 100644 --- a/plinth/modules/help/__init__.py +++ b/plinth/modules/help/__init__.py @@ -3,10 +3,12 @@ FreedomBox app for help pages. """ +import os + from django.utils.translation import ugettext_lazy as _ from plinth import app as app_module -from plinth import menu +from plinth import cfg, menu, web_server version = 1 @@ -51,6 +53,17 @@ class HelpApp(app_module.App): order=100) self.add(menu_item) + directory_map = {} + langs = os.listdir(os.path.join(cfg.doc_dir, 'manual')) + for lang in langs: + manual_dir = os.path.join(cfg.doc_dir, 'manual', lang, 'images') + manual_url = f'/help/manual/{lang}/images' + directory_map[manual_url] = manual_dir + + static_files = web_server.StaticFiles('static-files-help', + directory_map) + self.add(static_files) + def init(): """Initialize the Help module""" diff --git a/plinth/web_server.py b/plinth/web_server.py index 59994af93..b85283776 100644 --- a/plinth/web_server.py +++ b/plinth/web_server.py @@ -56,13 +56,6 @@ def init(): _mount_static_directory('/usr/share/javascript', '/javascript') - langs = os.listdir(os.path.join(cfg.doc_dir, 'manual')) - for lang in langs: - manual_dir = os.path.join(cfg.doc_dir, 'manual', lang, 'images') - manual_url = '/'.join([cfg.server_dir, f'help/manual/{lang}/images']) \ - .replace('//', '/') - _mount_static_directory(manual_dir, manual_url) - for module_name, module in module_loader.loaded_modules.items(): module_path = os.path.dirname(module.__file__) static_dir = os.path.join(module_path, 'static')