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 <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2020-03-24 14:43:58 -07:00 committed by Veiko Aasa
parent b80083cfce
commit 56250562d4
No known key found for this signature in database
GPG Key ID: 478539CAE680674E
2 changed files with 14 additions and 8 deletions

View File

@ -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"""

View File

@ -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')