File: __init__.py

package info (click to toggle)
freedombox 26.2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 82,976 kB
  • sloc: python: 48,504; javascript: 1,736; xml: 481; makefile: 290; sh: 167; php: 32
file content (84 lines) | stat: -rw-r--r-- 3,265 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app for help pages.
"""

import logging
import os

from django.utils.translation import gettext_lazy as _
from django.utils.translation import pgettext_lazy

from plinth import app as app_module
from plinth import cfg, menu, web_server

logger = logging.getLogger(__name__)


class HelpApp(app_module.App):
    """FreedomBox app for showing help."""

    app_id = 'help'

    _version = 1

    def __init__(self) -> None:
        """Create components for the app."""
        super().__init__()

        info = app_module.Info(app_id=self.app_id, version=self._version,
                               is_essential=True)
        self.add(info)

        menu_item = menu.Menu('menu-help', _('Help'), 'fa-book', None,
                              'help:index', parent_url_name='index')
        self.add(menu_item)
        menu_item = menu.Menu('menu-help-manual',
                              pgettext_lazy('User guide', 'Manual'),
                              'fa-info-circle', None, 'help:manual',
                              parent_url_name='help:index', order=10)
        self.add(menu_item)
        menu_item = menu.Menu('menu-help-support', _('Get Support'),
                              'fa-life-ring', None, 'help:support',
                              parent_url_name='help:index', order=20)
        self.add(menu_item)
        menu_item = menu.Menu('menu-help-feedback', _('Submit Feedback'),
                              'fa-comments', None, 'help:feedback',
                              parent_url_name='help:index', order=25)
        self.add(menu_item)
        menu_item = menu.Menu('menu-help-contribute', _('Contribute'),
                              'fa-wrench', None, 'help:contribute',
                              parent_url_name='help:index', order=30)
        self.add(menu_item)
        menu_item = menu.Menu('menu-help-about', _('About'), 'fa-star', None,
                              'help:about', parent_url_name='help:index',
                              order=100)
        self.add(menu_item)

    def post_init(self):
        """Perform post initialization operations."""
        directory_map = {}
        try:
            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
        except FileNotFoundError:
            logger.error('Unable to find manual directory. Ensure that '
                         'freedombox-doc-* packages are installed')

        static_files = web_server.StaticFiles('static-files-help',
                                              directory_map)
        self.add(static_files)

        # Mounting has to be done manually because web server will been
        # initialized before post_init() runs. Web server initialization is
        # when all existing StaticFiles components are auto-mounted.
        static_files.mount()

    def setup(self, old_version):
        """Install and configure the app."""
        super().setup(old_version)
        self.enable()