Commit 75b788e7 authored by Bonnegent's avatar Bonnegent
Browse files

Cours 3 ok

parent 540e5904
......@@ -13,7 +13,8 @@ dnf install pandoc pandoc-pdf texlive-latex-bin-bin texlive-beamer \
git clone git@framagit.org:bonnegent/cours_django.git
Ensuite, il y a un Makefile par sous répertoire.
Le répertoire pdf/ contient les présentations et les répertoires cours_XX
contiennent les supports de cours.
Outils utilisés
......
......@@ -161,15 +161,15 @@ INSTALLED_APPS = [
### conf/settings{\_common,}.py
~~~
$ ./manage.py generate_secret_key
f#wgrz$@#wh@*x5)_+(*$$^aw(c!q#a4)c0230bwp!iy
$
$ mv conf/settings.py conf/settings_common.py
$ cat conf/settings.py
from .settings_common import *
DEBUG = True
ALLOWED_HOSTS = ['*']
SECRET_KEY = 'Une_clef_secrete_et_longue!'
$
$ ./manage.py generate_secret_key
f#wgrz$@#wh@*x5)_+(*$$^aw(c!q#a4)c0230bwp!iy
~~~
## Pour git
......@@ -421,4 +421,7 @@ class Port(models.Model):
- Groupe
- nom: chaine de caractères (25)
- adresses: une liste d'Adresse
- Service
- nom: chaine de caractères (25)
- ports: une liste de ports
% Django par la pratique #03
% Sébastien Bonnegent
% version 17.10.30
% https://framagit.org/bonnegent/cours\_django
# Sphinx
......@@ -37,18 +37,6 @@ $ make html
## 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
......@@ -60,6 +48,18 @@ FireWall Manager
about
~~~
## Premiers fichiers #2
### 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.
~~~
# Consultation en ligne
## django-docs
......@@ -81,17 +81,18 @@ INSTALLED_APPS = [
'docs',
]
DOCS_ROOT = os.path.join(PROJECT_PATH,
'../docs/_build/html')
DOCS_ROOT = os.path.join(BASE_DIR, 'docs',
'_build', 'html')
~~~
## Configuration #2
### conf/urls.py
~~~{.py .numberLines}
from django.conf.urls import include
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^docs/', include('docs.urls')),
url(r'^', include('webui.urls')),
]
~~~
......@@ -149,6 +150,7 @@ Parefeu
~~~
## Graphique des modèles #1
graphviz doit être installé au niveau du système.
### django extensions
~~~
......@@ -201,6 +203,7 @@ $ pip install sphinx-bootstrap-theme
### docs/conf.py
~~~{.py .numberLines}
import sphinx_bootstrap_theme
# html_theme = 'alabaster'
html_theme = 'bootstrap'
html_theme_path = \
......@@ -275,118 +278,3 @@ TEMPLATES = [
{% 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
{% 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 %}
{# La barre de navigation #}
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a href="{% url 'index' %}" class="navbar-brand">FWM</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="navbar-main">
{% if user.is_authenticated %}
<ul class="nav navbar-nav">
{% if user.is_staff %}
<li><a href="/admin/">Administration</a></li>
{% endif %}
<li><a href="/docs/">Documentation</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="{% url 'logout' %}">
<span class="glyphicon glyphicon-remove-circle"></span>
</a></li>
</ul>
{% else %}
<ul class="nav navbar-nav navbar-right">
<li><a href="{% url 'login' %}">
<span class="glyphicon glyphicon-log-in"></span>
Connexion</a></li>
</ul>
{% endif %}
</div>
</div>
</div>
<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>
{% extends "webui/base.html" %}
{% block title %}Connexion{% endblock %}
{% block content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
<tr>
<td colspan=2>
<button class="btn btn-success btn-block" type="submit" value="login"/>
connexion</button>
</td>
</tr>
</table>
<input type="hidden" name="next" value="{{ next }}" />
</form>
{# Assumes you setup the password_reset view in your URLconf #}
<p><a href="{% url 'password_reset' %}">Lost password?</a></p>
{% endblock %}
% Django par la pratique #04
% Sébastien Bonnegent
% version 17.10.30
% https://framagit.org/bonnegent/cours\_django
# formulaires / vue
# 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
. . .
### Voir
- webui/templates/webui/service_list.html
- webui/views.py
File added
File added
File added
File added
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