doc: Add filename to code snippets in tutorial

[sunil: Add caption for another file too]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Carlos Henrique Lima Melara 2021-04-13 12:14:14 -03:00 committed by Sunil Mohan Adapa
parent ec67b71aa6
commit 213e01abcd
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
6 changed files with 29 additions and 1 deletions

View File

@ -16,6 +16,7 @@ We need to provide some basic information about the application for the app to
function normally. function normally.
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
from plinth import app as app_module from plinth import app as app_module
@ -60,6 +61,7 @@ need to list them and present them. Let's add this information to
``manifest.py``. ``manifest.py``.
.. code-block:: python3 .. code-block:: python3
:caption: ``manifest.py``
clients = [{ clients = [{
'name': _('Transmission'), 'name': _('Transmission'),
@ -84,6 +86,7 @@ concerns are automatically handled by the framework if a
our app's class. our app's class.
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
from plinth.daemon import Daemon from plinth.daemon import Daemon
@ -120,6 +123,7 @@ these concerns are automatically handled by the framework if a
app. Let us do that in our app's class. app. Let us do that in our app's class.
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
from plinth.modules.apache.components import Webserver from plinth.modules.apache.components import Webserver
@ -143,6 +147,7 @@ This information is used to check if the URLs are accessible as expected when
the user requests diagnostic tests on the app. the user requests diagnostic tests on the app.
.. code-block:: apache .. code-block:: apache
:caption: ``data/etc/apache2/conf-available/transmission-freedombox.conf``
## On all sites, provide Transmission on a default path: /transmission ## On all sites, provide Transmission on a default path: /transmission
<Location /transmission> <Location /transmission>
@ -166,6 +171,7 @@ available over Internet. Create the
initialization. initialization.
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
from plinth.modules.firewall.components import Firewall from plinth.modules.firewall.components import Firewall
@ -196,6 +202,7 @@ and we simply need to declare and use. First we need to register a user group
with the FreedomBox framework in ``__init.py__``. with the FreedomBox framework in ``__init.py__``.
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
from plinth.modules.users.components import UsersAndGroups from plinth.modules.users.components import UsersAndGroups
@ -216,6 +223,7 @@ group (and, of course, admin users) should be allowed to access our app. In the
file ``tranmission-freedombox.conf``, add the following. file ``tranmission-freedombox.conf``, add the following.
.. code-block:: apache .. code-block:: apache
:caption: ``data/etc/apache2/conf-available/transmission-freedombox.conf``
<Location /transmission> <Location /transmission>
... ...
@ -236,6 +244,7 @@ when they visit FreedomBox. To provide this shortcut, a
:class:`~plinth.frontpage.Shortcut` component can added to the app. :class:`~plinth.frontpage.Shortcut` component can added to the app.
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
from plinth import frontpage from plinth import frontpage
@ -277,6 +286,7 @@ initialization.
In ``__init__.py``, add: In ``__init__.py``, add:
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
from plinth.modules.backups.components import BackupRestore from plinth.modules.backups.components import BackupRestore
@ -295,6 +305,7 @@ In ``__init__.py``, add:
In ``manifest.py``, add: In ``manifest.py``, add:
.. code-block:: python3 .. code-block:: python3
:caption: ``manifest.py``
backup = { backup = {
'data': { 'data': {

View File

@ -11,6 +11,7 @@ file is provided by the framework. In some cases, we will need to customize this
template. Let us create a custom template file in ``transmission.html``. template. Let us create a custom template file in ``transmission.html``.
.. code-block:: django .. code-block:: django
:caption: ``templates/transmission.html``
{% extends "app.html" %} {% extends "app.html" %}
@ -48,6 +49,7 @@ To start using our custom template, we need to pass this to our view. In
``views.py``, add the following line: ``views.py``, add the following line:
.. code-block:: python3 .. code-block:: python3
:caption: ``views.py``
class TransmissionAppView(AppView): class TransmissionAppView(AppView):
... ...
@ -60,6 +62,7 @@ Our app needs some configuration. So, we need to write a configuration form to
provide options to the user. Add the following to ``forms.py``. provide options to the user. Add the following to ``forms.py``.
.. code-block:: python3 .. code-block:: python3
:caption: ``forms.py``
from django import forms from django import forms
@ -95,6 +98,7 @@ The view we have created needs to display the form and process the form after
the user submits it. Let us implement that in ``views.py``. the user submits it. Let us implement that in ``views.py``.
.. code-block:: python3 .. code-block:: python3
:caption: ``views.py``
from django.contrib import messages from django.contrib import messages
@ -157,6 +161,7 @@ enable and disable the web configuration. We will do this by creating a file
``actions/transmission``. ``actions/transmission``.
.. code-block:: python3 .. code-block:: python3
:caption: ``actions/transmission``
import argparse import argparse
import json import json

View File

@ -21,6 +21,7 @@ itself is a two-tuple containing the display name of the test followed by the
result as ``passed``, ``failed`` or ``error``. result as ``passed``, ``failed`` or ``error``.
.. code-block:: python3 .. code-block:: python3
:caption: ``views.py``
class TransmissionAppView(views.AppView): class TransmissionAppView(views.AppView):
... ...
@ -47,6 +48,7 @@ system logs. Doing this in FreedomBox is just like doing this any other Python
application. application.
.. code-block:: python3 .. code-block:: python3
:caption: ``views.py``
import logging import logging
@ -75,6 +77,7 @@ requires marking the user visible messages for translation. FreedomBox apps use
the Django's localization methods to make that happen. the Django's localization methods to make that happen.
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _

View File

@ -14,6 +14,7 @@ Debian packages required in the ``setup()`` method that is called during
installation: installation:
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
managed_packages = ['transmission-daemon'] managed_packages = ['transmission-daemon']

View File

@ -52,7 +52,10 @@ Tell FreedomBox that our app exists
The first thing to do is tell FreedomBox that our app exists. This is done by The first thing to do is tell FreedomBox that our app exists. This is done by
writing a small file with the Python import path to our app and placing it in writing a small file with the Python import path to our app and placing it in
``plinth/modules/transmission/data/etc/plinth/modules-enabled/``. Let us create ``plinth/modules/transmission/data/etc/plinth/modules-enabled/``. Let us create
this file ``transmission``:: this file ``transmission``:
.. code-block:: text
:caption: ``plinth/modules/transmission/data/etc/plinth/modules-enabled/transmission``
plinth.modules.transmission plinth.modules.transmission
@ -71,6 +74,7 @@ In the FreedomBox framework, each app must be a class derived from the
class later. class later.
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
from plinth import app as app_module from plinth import app as app_module
@ -89,6 +93,7 @@ itself by calling the ``init()`` method if there is such a method available as
``<module>.init()``. The app class must be instantiated here. ``<module>.init()``. The app class must be instantiated here.
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
app = None app = None

View File

@ -11,6 +11,7 @@ user visits this URL, a view is executed and a page is displayed. In ``urls.py``
write the following: write the following:
.. code-block:: python3 .. code-block:: python3
:caption: ``urls.py``
from django.conf.urls import url from django.conf.urls import url
@ -33,6 +34,7 @@ a link in FreedomBox web interface. Let us add a link in the apps list. In
``__init__.py`` add the following: ``__init__.py`` add the following:
.. code-block:: python3 .. code-block:: python3
:caption: ``__init__.py``
from plinth.menu import main_menu from plinth.menu import main_menu
@ -83,6 +85,7 @@ section of the web interface that points to our view. We now need to create a
view to show the app page for our app. In ``views.py``, let us add a view. view to show the app page for our app. In ``views.py``, let us add a view.
.. code-block:: python3 .. code-block:: python3
:caption: ``views.py``
from plinth import views from plinth import views
from plinth.modules import transmission from plinth.modules import transmission