Commit 540e5904 authored by Bonnegent's avatar Bonnegent
Browse files

cours 3 ok

parent 8bb2a298
% Django par la pratique #03
% Sébastien Bonnegent
% version 17.10.30
# Sphinx
## Mise en place
### sphinx-quickstart
~~~
$ mkdir docs && cd docs
$ sphinx-quickstart
Enter the root path for documentation.
> Root path for the documentation [.]:
> Separate source and build directories (y/n) [n]:
> Name prefix for templates and static dir [_]:
> Project name: FireWall Manager
> Author name(s): S.Bonnegent
> Project language [en]: fr
> Source file suffix [.rst]:
> Name of your master document (without suffix) [index]:
> Create Makefile? (y/n) [y]:
> Create Windows command file? (y/n) [y]:
~~~
## Utilisation
### Génération du html
~~~
$ make html
~~~
### Organisation des fichiers
\center\includegraphics[height=4.5cm]{images/tree-sphinx.png}
## Premiers fichiers #1
### docs/about.rst
~~~{.numberLines}
========
À propos
========
FWM permet de gérer des parefeux linux simple,
à partir de modèle, et de déployer directement
les règles.
~~~
## Premiers fichiers #2
### docs/index.rst
~~~{.numberLines}
FireWall Manager
================
.. toctree::
:maxdepth: 2
about
~~~
# Consultation en ligne
## django-docs
### Prérequis
~~~
$ pip install django-docs
~~~
## Configuration #1
### conf/settings\_common.py
~~~{.py .numberLines}
INSTALLED_APPS = [
...
'webui',
'django_extensions',
'docs',
]
DOCS_ROOT = os.path.join(PROJECT_PATH,
'../docs/_build/html')
~~~
## Configuration #2
### conf/urls.py
~~~{.py .numberLines}
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^docs/', include('docs.urls')),
url(r'^', include('webui.urls')),
]
~~~
## Consultation
- http://127.0.0.1:8000/docs/
# Documentation
## Sphinx #1
### Prérequis
~~~
$ pip install pydotplus
~~~
### docs/conf.py
~~~{.py .numberLines}
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.inheritance_diagram']
~~~
## Sphinx #2
### docs/index.rst
~~~{.numberLines}
FireWall Manager
================
.. toctree::
:maxdepth: 2
about
modeles
~~~
## Sphinx #3
### docs/modeles.rst
~~~{.numberLines}
=======
Modèles
=======
.. image:: _static/graph_models_webui.png
:alt: fwm
Parefeu
=======
.. autoclass:: webui.models.Parefeu
:members:
:exclude-members: objects
...
~~~
## Graphique des modèles #1
### django extensions
~~~
./manage.py graph_models webui \
--output docs/_static/graph_models_webui.png
~~~
## Graphique des modèles #2
\center\includegraphics[height=6.5cm]{images/graph_models_webui.png}
## Docstring
### webui/models.py
~~~{.py .numberLines}
class Truc(models.Model):
"""Une définition courte...
:param toto: sert à truc (str)
:return: Truc()
"""
~~~
## Gérer un numéro de version
### conf/settings_common.py
~~~{.py .numberLines}
VERSION = "0.1.171009"
~~~
### docs/conf.py
~~~{.py .numberLines}
import sys
import os
import django
sys.path.insert(0, os.path.abspath('..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'conf.settings'
django.setup()
from django.conf import settings
version = settings.VERSION
release = version
~~~
## Thème bootstrap #1
### Prérequis
~~~
$ pip install sphinx-bootstrap-theme
~~~
### docs/conf.py
~~~{.py .numberLines}
# html_theme = 'alabaster'
html_theme = 'bootstrap'
html_theme_path = \
sphinx_bootstrap_theme.get_html_theme_path()
~~~
## Thème bootstrap #2
~~~{.py .numberLines}
html_theme_options = {
'navbar_title': 'FWM',
'navbar_site_name': "Documentation",
'navbar_links': [(
'<span class="glyphicon glyphicon-home"></span>',
"/", True), ],
'navbar_sidebarrel': False,
'navbar_pagenav': False,
'navbar_pagenav_name': "Page",
'globaltoc_depth': 1,
'globaltoc_includehidden': "true",
'navbar_fixed_top': "true",
'source_link_position': "nav",
'bootstrap_version': "3",
}
~~~
## Version avec authentification
### conf/settings\_common.py
~~~{.py .numberLines}
DOCS_ACCESS = 'login_required'
~~~
## Authentification Django #1
### conf/urls.py
~~~
url(r'^accounts/',
include('django.contrib.auth.urls')),
~~~
### Liens créés
~~~{.py .numberLines}
^login/$
^logout/$
^password_change/$
^password_change/done/$
^password_reset/$
^password_reset/done/$
^reset/...)/$
^reset/done/$
~~~
## Authentification Django #2
### conf/settings\_common.py
~~~{.py .numberLines}
TEMPLATES = [
...
'DIRS': [os.path.join(BASE_DIR,
'templates')],
...
~~~
## Authentification Django #3
### webui/templates/registration/login.html
~~~{.py .numberLines}
{% extends "webui/base.html" %}
{% block content %}
<form method="post"
action="{% url 'login' %}">
...
{% endblock %}
~~~
# Les templates
## Prérequis
### Prérequis
~~~
$ pip install django-bootstrap3
~~~
## Base #1
### webui/templates/webui/base.html
~~~
{% load staticfiles %}
<!DOCTYPE html>
<html lang="fr">
<head>
<link rel="shortcut icon"
href="{% static 'webui/images/favicon.ico' %}"/>
<title>FWM</title>
</head>
<body>
{# Load the tag library #}
{% load bootstrap3 %}
{# Load CSS and JavaScript #}
{% bootstrap_css %}
{% bootstrap_javascript %}
{# Display django.contrib.messages as Bootstrap alerts #}
{% bootstrap_messages %}
~~~
## Base #2
### webui/templates/webui/base.html
~~~
<div class="container">
<div class="page-header" id="banner">
<div class="row">
<h1>{% block title %}Accueil{% endblock %}</h1>
</div>
</div>
{% block content %}
<p>Texte d'accueil par défaut.</p>
{% endblock %}
</div>
</body>
</html>
~~~
## Vue
### webui/views.py
~~~{.py .numberLines}
from django.shortcuts import render
def accueil(request):
"""Page d'accueil par défaut"""
return render(request, 'webui/base.html')
~~~
## L'URL
### webui/urls.py
~~~{.py .numberLines}
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.accueil, name='index'),
]
~~~
## Fichiers statiques
### conf/urls.py
~~~{.py .numberLines}
# pour les fichiers static
from django.conf import settings
from django.conf.urls.static import static
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
~~~
## CDN vs Local
### Local !
~~~
$ mkdir -p webui/static/webui/{images,css,js,fonts}
$ wget https://github.com/twbs/../bootstrap-3.3.7-dist.zip
$ wget https://code.jquery.com/jquery-3.2.1.min.js
~~~
## Thème #1
### https://bootswatch.com/3/
~~~
$ wget https://bootswatch.com/3/flatly/bootstrap.min.css
$ mv bootstrap.min.css css/bootstrap-theme-flatly.min.css
~~~
### Suppression de la 1er ligne
~~~
@import url("https://fonts.googleapis.com/
css?family=Lato:400,700,400italic");
~~~
## Thème #2
### conf/settings_common.py
~~~{.py .numberLines}
BOOTSTRAP3 = {
'jquery_url': '/static/webui/js/jquery-3.2.1.min.js',
'base_url': '/static/webui/',
'theme_url': '/static/webui/css/bootstrap-theme-flatly.min.css',
}
~~~
## À faire
### https://docs.djangoproject.com/fr/
- afficher une liste de services
% Django par la pratique #04
% Sébastien Bonnegent
% version 17.10.30
# formulaires / vue
% Django par la pratique #05
% Sébastien Bonnegent
% version 17.10.30
% Django par la pratique #06
% Sébastien Bonnegent
% version 17.10.30
% Django par la pratique #07
% Sébastien Bonnegent
% version 17.10.30
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment