forked from numerique-gouv/django-dsfr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Amélioration de la documentation (numerique-gouv#73)
* Improve documentation * Add doc for forms * Add syntax highlighting * Update deploy-doc version * Fix README * .py → .python * Update doc * Add doc for components * style * Add resource pages for icons and pictograms * Add resource pages for icons and pictograms * Move doc in a tab panel * Improve text * Improve text * Improve style * sensible number of rows for textarea samples * detail * typo * Update example_app/templates/example_app/blocks/header.html Co-authored-by: Agnès Haasser <[email protected]> --------- Co-authored-by: Agnès Haasser <[email protected]>
- Loading branch information
Showing
22 changed files
with
862 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Installation de django-DSFR | ||
|
||
## Installation basique | ||
|
||
- Installez le paquet | ||
|
||
```{ .bash } | ||
pip install django-dsfr | ||
``` | ||
|
||
- Ajoutez `widget_tweaks` et `dsfr` à `INSTALLED_APPS` dans le `settings.py` avant la ou les app avec laquelle vous voulez l’utiliser : | ||
|
||
```{ .python } | ||
INSTALLED_APPS = [ | ||
... | ||
"widget_tweaks" | ||
"dsfr", | ||
<votre_app> | ||
] | ||
``` | ||
|
||
- Ajouter les lignes suivantes dans la section `TEMPLATES` du `settings.py` pour faire fonctionner les formulaires : | ||
|
||
```{ .python } | ||
TEMPLATES = [ | ||
{ | ||
[...] | ||
"DIRS": [ | ||
os.path.join(BASE_DIR, "dsfr/templates"), | ||
os.path.join(BASE_DIR, "templates"), | ||
], | ||
}, | ||
] | ||
``` | ||
|
||
- Ajouter le `FORM_RENDERER` in `settings.py` pour faire fonctionner les formulaires : | ||
|
||
```{ .python } | ||
FORM_RENDERER = "django.forms.renderers.TemplatesSetting" | ||
``` | ||
|
||
- Inclure les tags dans votre fichier `base.html` (voir par exemple sur [base.html](https://github.com/numerique-gouv/django-dsfr/blob/main/example_app/templates/example_app/base.html)) | ||
|
||
- Lancer le serveur (`python manage.py runserver`) et aller sur [http://127.0.0.1:8000/](http://127.0.0.1:8000/) | ||
|
||
|
||
## Installation avancée (optionnelle) | ||
### Utilisation de la conf en admin | ||
- Ajoutez le `context_processor` au fichier `settings.py` : | ||
|
||
```{ .python } | ||
TEMPLATES = [ | ||
{ | ||
[...] | ||
"OPTIONS": { | ||
"context_processors": [ | ||
[...] | ||
"dsfr.context_processors.site_config", | ||
], | ||
}, | ||
}, | ||
] | ||
``` | ||
|
||
- Créez un objet "DsfrConfig" dans le panneau d’administration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Le système de design propose [un certain nombre de composants](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants), et Django-DSFR vise à les implémenter sous forme de balises utilisables dans les templates Django, soit en passant directement les paramètres, soit en les passant depuis la vue via un dictionnaire. | ||
|
||
Par exemple, il est possible de créer un bouton soit en passant directement les paramètres : | ||
|
||
```{.django} | ||
{% dsfr_button label="Bouton principal" onclick="alert('Vous avez cliqué sur le bouton principal')" %} | ||
``` | ||
|
||
Soit en définissant un dictionnaire dans la vue : | ||
|
||
```{ .python } | ||
context["data_dict"] = { | ||
"label": "Bouton principal", | ||
"onclick": "alert('Vous avez cliqué sur le bouton principal')", | ||
} | ||
``` | ||
|
||
et en l’appelant depuis le template : | ||
|
||
```{.django} | ||
{% dsfr_button data_dict %} | ||
``` | ||
|
||
L’implémentation de ces balises est un travail en cours, mais il est tout à fait possible d’utiliser directement l’ensemble du système de design de l’État en utilisant directement le code HTML tel que défini dans la documentation officielle : | ||
|
||
```{.html} | ||
<button class="fr-btn" onclick="alert('Vous avez cliqué sur le bouton principal')" type="submit"> | ||
Bouton principal | ||
</button> | ||
``` | ||
|
||
Toutes ces options produisent le même résultat : | ||
|
||
<button class="fr-btn" onclick="alert('Vous avez cliqué sur le bouton principal')" type="submit"> | ||
Bouton principal | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Les formulaires sont construits en se basant sur la classe `DsfrBaseForm`, par exemple : | ||
|
||
```{ .python } | ||
# votre_app/forms.py | ||
from dsfr.forms import DsfrBaseForm | ||
class ExampleForm(DsfrBaseForm): | ||
# basic fields | ||
user_name = forms.CharField(label="Nom d’utilisateur", max_length=100) | ||
user_email = forms.EmailField( | ||
label="Adresse électronique", | ||
help_text="Format attendu : [email protected]", | ||
required=False, | ||
) | ||
``` | ||
|
||
Il est possible de multi-classer : | ||
|
||
```{ .python } | ||
class AuthorCreateForm(ModelForm, DsfrBaseForm): | ||
``` | ||
|
||
Le formulaire ajoute la ou les classes appropriées (`fr-input`, `fr-select`, etc.) en fonction du type de champ, mais uniquement si une classe n’a pas déjà été ajoutée. | ||
|
||
Si c'est le cas, il faut aussi forcer manuellement les classes à utiliser : | ||
|
||
```{ .python } | ||
password = forms.CharField( | ||
label="Mot de passe", widget=forms.PasswordInput( | ||
"autocomplete": "current-password", | ||
"required": True, | ||
"class": "fr-input my-custom-class" | ||
) | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,6 @@ | |
"dsfr", | ||
"example_app", | ||
"django_distill", | ||
"crispy_forms", | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
Oops, something went wrong.