Skip to content
Snippets Groups Projects
Commit ef180b4a authored by Matthieu Fesselier's avatar Matthieu Fesselier
Browse files

Merge branch 'master' into 'dev'

# Conflicts:
#   source/import_documentation/Components/Solid-Form.rst
parents 87b5b7a0 ef4e12ae
No related branches found
No related tags found
No related merge requests found
......@@ -90,6 +90,13 @@ Attributes
Add this attribute when the form does not include
all the fields of the resource to update.
.. _required-field:
``required-[field]``
~~~~~~~~~~~~~~~~~~~~
Add this attribute to make the ``[field]`` required by adding the ``required`` attribute to the input.
.. _min-field:
``min-[field]``
~~~~~~~~~~~~~~~
......
......@@ -47,7 +47,8 @@ Name of the template to use. Available templates:
- ``number``: set ``value`` in an ``<input>`` of type ``number``.
- ``rangenumber``: set 2 values in 2 ``<input>`` of type ``number``. Used for filtering with min and max.
Possible to add ``start-value-[field]`` and ``end-value-[field]`` attributes to set min and max values.
- ``hidden``: set ``value`` in an ``<input>`` of type ``hidden``.
- ``hidden``: set ``value`` in an ``<input>`` of type ``hidden``. If you need to use a boolean or numeric value you can add a ``bool`` or
``num`` mixin (ie: ``solid-form-hidden-bool``).
- ``dropdown``: set ``value`` in a ``<select>``. The list is provided via the ``range`` attribute, which expects a container’s URL, or via the ``enum`` attribute, which takes a list of the values separated by commas.
- ``radio``: set ``value`` in a list of radio buttons. The list is provided via the ``range`` attribute, which expects a container’s URL, or via the ``enum`` attribute, which takes a list of the values separated by commas.
- ``multiple``: Accept a container URI as a ``value``, and inserts one widget per resource with a “remove” button for each widget, and an “add” button.
......
......@@ -251,6 +251,7 @@ List of attributes (core framework)
``required-[field]``
~~~~~~~~~~~~~~~~~~~~
* :ref:`required-mixin <required-mixin>`
* :ref:`solid-form <solid-form>`
``selectable``
~~~~~~~~~~~~~~
......
DjangoLDP reference guide
#########################
The DjangoLDP commands
======================
.. code-block:: bash
$ djangoldp --help
Usage: djangoldp [OPTIONS] COMMAND [ARGS]...
DjangoLDP CLI
Options:
--version Show the version and exit.
--help Show this message and exit.
Commands:
configure Configure the project.
initserver Start a DjangoLDP server.
install Install project dependencies.
runserver Run the Django embeded webserver.
startpackage Start a DjangoLDP package.
The `djangoldp` server is built ontop of `django` framework. The `django` core commands are also available. Check `python manage.py --help` and [the official Django documentation](https://docs.djangoproject.com/en/2.2/)
The Initserver command
----------------------
This command initiate a new server folder from a template. It has the minimal option to work out of the box.
The Configure command
---------------------
This is a command meant to tell the server the settings have changed and it must run some maintenance operations and data integrity check, such as the model migration of the LDP packages.
It has options to create new administrator users during the configuration process.
The Install command
-------------------
This command parses the `dependencies` section of the configuration file and install all python distribution required by the project. It is a wrapper around the `requirements.txt` file.
The runserver command
---------------------
This command loads the configuration and starts the LDP server. It is a wrapper around the `django-admin runserver` command.
The startpackage command
------------------------
This a helper command working the same way the `django startpackage` does command. It creates a folder with a DjangoLPD package template.
The DjangoLDP configuration file
================================
The server comes with a default `settings.yml` you can customize.
It contains 3 main sections:
* `dependencies`: contains a list of dependencies to install with pip during the `install` phase
* `ldppackages`: contains a list of djangoldp packages to activate
* `server`: contains all the configuration required by djangoldp server
You need to restart the server after a change in configuration.
The Dependencies section
------------------------
This is not mandatory as you can install all your dependencies manually. But it is convienent to have all in one file when exchanging server configurations.
The format for dependencies is the one accepted by pip. For example:
.. code-block:: yml
dependencies:
- git+https://git.startinblox.com/djangoldp-packages/djangoldp-account.git
As for any python project when you declare a dependency you have to make sure it is installed. You can use the wrapper command `djangoldp install` for this.
The LDP packages section
------------------------
When you want to use a LDP package you need to reference it in the configuration. For example:
.. code-block:: yml
ldppackages:
- djangoldp_account
The name referenced there must be the name of the python module, the one your would use with the `import` statement.
Some packages may require some configuration to work properly. It is a good practice to run the `djangoldp configure` command after adding or upgrading a LDP package.
Here you have :
* `a list of all the package available <https://git.startinblox.com/djangoldp-packages/>`__
* `Explanation on how to make one <develop-sib-ldp-packages.html>`__
If the description of the available packages is unclear, open an issue to ask for more description.
The Server section
------------------
This section contains all parameters to the server itself. All this section is loaded as a Django configuration object to initialize the server.
see https://docs.djangoproject.com/fr/2.2/topics/settings/
The extra config module
-----------------------
The DjangoLDP server also load a `settings.py` module when it exists in along with the `settings.yml`.
The DjangoLDP packages capabilities
===================================
Among other things, the package has a special file allowing a package to load settings when the djangoldp server starts. The `djangoldp_settings.py` file can reference custom variables and load extra middlewares (they are added to the ones loaded by the djangoldp server itself).
```
# cat mypkg/mypkg/djangoldp_settings.py
MIDDLEWARE = []
MYPACKAGE_VAR = 'MY_DEFAULT_VAR'
```
As any other packages, local packages needs to be referenced in the project `settings.yml`:
```
ldppackages:
- mypkg
```
Get started with the DjangoLDP server
#####################################
What is behind the DjangoLDP server ?
=====================================
Our solution is based on `Django <https://www.djangoproject.com/>`__ and named `DjangoLDP <https://git.startinblox.com/djangoldp-packages/djangoldp/>`__, adapted to be compatible with Linked Datas convention.
Go to `Server Architecture <server-architecture.html>`_ to know more about it.
And check the `References guide <djangoldp_references.html>`__ to know all the details.
Requirements
============
The DjangoLDP server requires:
* python 3.6
* postgresql database (for production)
.. note::
If you're working on many project in Python, we advice you to use `a virtual environement <https://virtualenvwrapper.readthedocs.io/en/latest/>`__.
.. note::
`See the documentation to set it with Docker <https://docs.startinblox.com/import_documentation/install-sib-server.html#initiate-the-server-with-docker/>`__.
From a fresh environment, get the last version of DjangoLDP:
.. code-block:: bash
python -m pip install djangoldp
Initiate a new server
=====================
Create a server workdir:
.. code-block:: bash
djangoldp initserver sibserver
cd sibserver
All the command must be issued from this working directory.
Add a package to your `settings.yml` file, let's start with `djangoldp_account`:
.. code-block:: yml
dependencies
- djangoldp-account
ldppackages:
- djangoldp_account
The `server` section should work out of the box. Check the reference guide for details on the settings file.
Install the dependencies you just added:
.. code-block:: bash
djangoldp install
This downloads the `djangoldp-account` distribution from pypi.org.
Configure your backend to support the new package:
.. code-block:: bash
djangoldp configure --with-dummy-admin
This will also create a local admin user (not suited for production use).
Then launch the server:
.. code-block:: bash
djangoldp runserver
Then go to `http://localhost:8000/admin/ <http://localhost:8000/admin/>`__ to acces to your Django administration with the `admin` user and `admin` password.
You should be able to get you api at `http://localhost:8000/abc/` where abc is the model of data you want to get.
Start your own DjangoLDP package
================================
.. note::
A bug in with the local package loading breaks the Django migrations directory recognition. To workaround it, you need to start or move your DjangoLDP package outside the server workdir and make a symlink inside the working directory.
Start a new package in the server workdir parent directory:
.. code-block:: bash
djangoldp startpackage mypkg
From the server workdir create a symlink to the package python module:
.. code-block:: bash
cd sibserver
ln -s ../mypkg/mypkg mypkg
Then reference your new package in the `ldppackages` section:
.. code-block:: yml
ldppackages:
- mypkg
Don't forget to run the `configure` command if your package load django migrations.
How to install a SIB server
############################
What is behind SiB server ?
==========================
Our solution is based on `Django <https://www.djangoproject.com/>`__ and named `DjangoLDP <https://git.startinblox.com/djangoldp-packages/djangoldp/>`__, adapted to be compatible with Linked Datas convention.
Go to `Server Architecture <server-architecture.html>`_ to know more about it.
Requirements
============
The SIB server requires:
* python 3.6
* postgresql database (for production)
.. note::
`See the documentation to set it with Docker <https://docs.startinblox.com/import_documentation/install-sib-server.html#initiate-the-server-with-docker/>`__.
Initiate the server
===================
.. note::
If you're working on many project in Python, we advice you to use `a virtual environement <https://virtualenvwrapper.readthedocs.io/en/latest/>`__.
From a fresh environment, get the last version of the sib-manager:
.. code-block:: bash
python -m pip install -U sib-manager
Create a project structure from a production template:
.. code-block:: bash
sib startproject sibserver --production
cd sibserver
For a development server remove the --production flag.
now your architecture should look like :
.. code-block:: bash
sibserver/
server/
__init__.py
settings.py
urls.py
wsgi.py
manage.py
packages.yml
For more detail, go to `the official Django project documentation <https://docs.djangoproject.com/en/1.11/intro/tutorial01/>`__.
Configure your LDP packages
============================
The configuration of the packages goes in packages.yml file in the ldppackages section. Those following ones are given as an example. Yours depend on what your app does.
Here you have :
* `a list of all the package available <https://git.startinblox.com/djangoldp-packages/>`__
* `Explanation on how to make one <develop-sib-ldp-packages.html>`__
If the description of the available packages is unclear, open an issue to ask for more description.
.. code-block:: yml
ldppackages:
djangoldp_account: djangoldp_account
oidc_provider: 'git+https://github.com/jblemee/django-oidc-provider.git@develop'
Details about packages.yml format are given in the template file.
Configure your server parameters
===============================
The packages.yml files is also use to provide parameters to the server itself.
Configure the server parameters in the packages.yml:
.. code-block:: yml
server:
site_url: 'http://localhost:8000'
admin_email: admin@example.org
admin_name: admin
admin_pass: admin
registration_open: True
xmpp_url: 'https://jabber.localhost'
jabber_host: 'jabber.localhost'
default_client: 'http://localhost:3000'
This configuration works for a local development server but for a production instance you need to setup a postgresql database and configure dependent services:
.. code-block:: yml
server:
site_url: 'https://api.batman.happy-dev.fr'
allowed_hosts:
- api.batman.happy-dev.fr
db_host: postgresql-batman.happy-dev.fr
db_name: batman_db
db_user: batman
db_pass: changeit
smtp_host: smtp-batman.happy-dev.fr
smtp_user: batman
smtp_pass: changeit
admin_email: admin@example.org
admin_name: admin
admin_pass: changeit
xmpp_url: 'https://jabber.happy-dev.fr'
jabber_host: 'happy-dev.fr'
Make your migration
===================
.. code-block:: bash
python manage.py migrate
Create your super user
===================
.. code-block:: bash
python manage.py createsuperuser
Follow the instructions you get in your terminal.
Launch the server
==================
Run the server in development:
.. code-block:: bash
python manage.py runserver
Then go to `http://127.0.0.1:8000/admin/ <http://127.0.0.1:8000/admin/>`__ to acces to your Django administration.
Enter the identifier you've just created and you shoud see the Django admin.
.. warning::
In some case, you could get this kind of error : `no such table: djangoldp_xyz_abc`. Enter this command to solve it : `python3 manage.py migrate - -run-syncdb`
You should be able to get you api at `http://localhost:8000/abc/` where abc is the model of data you want to get.
To update the installation
========================
Install/update the project:
.. code-block:: bash
sib install sibserver
To launch the server in production:
------------------------------------
* You have to install the static files with `python manage.py collectstatic`
* You have to configure your python server to server the script: wsgi.py on the URL api.batman.happy-dev.fr/.
If you have any problem, `tell us reporting it in an issue <https://git.startinblox.com/djangoldp-packages/djangoldp/>`__. Thanks!
Tips & tricks
================
Activate debug mode
To activate the debug mode (default in development) you can override manually the `DEBUG` variable in the settings.py
Install the server as a subfolder URL
This method isn't officially supported and requires to change values in the core configuration.
To setup the SIB server on a subfolder https://batman.happy-dev.fr/api you have to manually override the configuration in the settings.py:
.. code-block:: python
BASE_URL = 'https://batman.happy-dev.fr'
SITE_URL = 'https://batman.happy-dev.fr/api'
STATIC_URL = '/api/static/'
and URLs in urls.py:
.. code-block:: python
urlpatterns = [
url(r'^api/', include('djangoldp.urls')),
url(r'^api/admin/', admin.site.urls),
]
Note: Alwaysdata static config /api/static/=/static/
Initiate the server with Docker
===============================
This is not intended to support production running.
Setup your SIB server
---------------------
Create your packages.yml according to the documentation.
Create the Dockerfile:
.. code-block:: bash
FROM python:3.6
ENV PATH="/root/.local/bin:${PATH}"
RUN pip install --user -U sib-manager
WORKDIR /opt
RUN cd /opt/ && sib startproject sib_server
ADD packages.yml /opt/sib_server/packages.yml
RUN cd /opt/sib_server && sib install sib_server
EXPOSE 8000
CMD cd /opt/sib_server && python manage.py runserver 0.0.0.0:8000
Build the image:
.. code-block:: bash
docker build -t sibserver .
Run the container:
.. code-block:: bash
docker run --rm -p 127.0.0.1:8000:8000 -d sibserver
Serve your client app
---------------------
Launch a container from within your code folder:
.. code-block:: bash
docker run --rm -v $PWD:/code -w /code -u $UID -it -p 127.0.0.1:3000:3000 node npm install && npm run watch
\ No newline at end of file
......@@ -16,8 +16,8 @@ Welcome to Startinblox's documentation
:caption: How it works
import_documentation/About-our-components
import_documentation/install-sib-server
import_documentation/develop-sib-ldp-packages
import_documentation/install-djangoldp-server
import_documentation/djangoldp-references
import_documentation/server-architecture
import_documentation/frequent-errors
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment