2021-05-01 18:32:45 +02:00
|
|
|
# Les variables à choix
|
|
|
|
|
|
2021-05-05 15:27:06 +02:00
|
|
|
## Une variable à choix
|
2021-05-01 18:32:45 +02:00
|
|
|
|
|
|
|
|
Il est possible d'imposer une liste de valeur pour une variable particulière :
|
|
|
|
|
|
2022-11-03 22:17:43 +01:00
|
|
|
```yml
|
2023-10-12 08:17:30 +02:00
|
|
|
---
|
|
|
|
|
version: '1.0'
|
|
|
|
|
my_variable:
|
|
|
|
|
type: choice
|
|
|
|
|
choices:
|
|
|
|
|
- val1
|
|
|
|
|
- val2
|
|
|
|
|
- val3
|
2022-11-02 22:52:50 +01:00
|
|
|
```
|
|
|
|
|
|
2021-05-05 15:27:06 +02:00
|
|
|
Dans ce cas, seules les valeurs proposées sont possibles pour cette variable.
|
|
|
|
|
Cette variable n'est pas obligatoire dont il est possible de mettre la valeur "None".
|
2021-05-01 18:32:45 +02:00
|
|
|
|
2021-05-05 15:27:06 +02:00
|
|
|
Si la variable est obligatoire ou si une valeur est précisée (la variable passe obligatoire) alors la valeur "None" n'est plus autorisé :
|
2021-05-01 18:32:45 +02:00
|
|
|
|
2022-11-03 22:17:43 +01:00
|
|
|
```yml
|
2023-10-12 08:17:30 +02:00
|
|
|
---
|
|
|
|
|
version: '1.0'
|
|
|
|
|
my_variable:
|
|
|
|
|
type: choice
|
|
|
|
|
choices:
|
|
|
|
|
- val1
|
|
|
|
|
- val2
|
|
|
|
|
- val3
|
|
|
|
|
default: val1
|
2022-11-02 22:52:50 +01:00
|
|
|
```
|
|
|
|
|
|
2021-05-05 15:27:06 +02:00
|
|
|
## Un variable à choix typée
|
|
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
Les choix sont typés :
|
2022-11-02 22:52:50 +01:00
|
|
|
|
2022-11-03 22:17:43 +01:00
|
|
|
```yml
|
2023-10-12 08:17:30 +02:00
|
|
|
---
|
|
|
|
|
version: '1.0'
|
|
|
|
|
my_variable:
|
|
|
|
|
type: choice
|
|
|
|
|
choices:
|
|
|
|
|
- val1
|
|
|
|
|
- 3
|
|
|
|
|
- true
|
|
|
|
|
default: val1
|
2022-11-02 22:52:50 +01:00
|
|
|
```
|
|
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
dans ce cas, le chiffre 3 est autorisé mais pas la chaine de caractère "3".
|
2022-11-02 22:52:50 +01:00
|
|
|
|
2021-05-05 15:27:06 +02:00
|
|
|
## Redéfinir une option à choix
|
|
|
|
|
|
|
|
|
|
Si on veut supprimer un choix ou redéfinir complètement la liste, il faut redéfinir cette variable et ajouter l'attribut "remove_choice" à "True" :
|
|
|
|
|
|
2022-11-03 22:17:43 +01:00
|
|
|
```yml
|
2023-10-12 08:17:30 +02:00
|
|
|
---
|
|
|
|
|
version: '1.0'
|
|
|
|
|
my_variable:
|
|
|
|
|
redefine: true
|
|
|
|
|
choices:
|
|
|
|
|
- val1
|
|
|
|
|
- val2
|
2022-11-02 22:52:50 +01:00
|
|
|
```
|
|
|
|
|
|
2021-05-05 15:27:06 +02:00
|
|
|
Dans ce cas toutes les anciens choix ne seront plus possible. Seuls les nouveaux le seront.
|
|
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
## Un variable à choix provenant de variable
|
2021-05-05 15:27:06 +02:00
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
Les choix d'une variable peuvent provenir d'une autre variable multiple :
|
2021-05-05 15:27:06 +02:00
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
```yml
|
|
|
|
|
---
|
|
|
|
|
version: '1.0'
|
|
|
|
|
source_variable:
|
|
|
|
|
multi: true
|
|
|
|
|
default:
|
|
|
|
|
- val1
|
|
|
|
|
- val2
|
|
|
|
|
my_variable:
|
|
|
|
|
type: choice
|
|
|
|
|
choices:
|
|
|
|
|
type: variable
|
|
|
|
|
variable: rougail.source_variable
|
2021-05-05 15:27:06 +02:00
|
|
|
```
|
|
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
Ou de plusieurs autres variables :
|
2022-11-02 22:52:50 +01:00
|
|
|
|
2022-11-03 22:17:43 +01:00
|
|
|
```yml
|
2023-10-12 08:17:30 +02:00
|
|
|
---
|
|
|
|
|
version: '1.0'
|
|
|
|
|
source_variable_1:
|
|
|
|
|
default: val1
|
|
|
|
|
source_variable_2:
|
|
|
|
|
default: val2
|
|
|
|
|
my_variable:
|
|
|
|
|
type: choice
|
|
|
|
|
choices:
|
2022-11-02 22:52:50 +01:00
|
|
|
- type: variable
|
2023-10-12 08:17:30 +02:00
|
|
|
variable: rougail.source_variable_1
|
|
|
|
|
- type: variable
|
|
|
|
|
variable: rougail.source_variable_2
|
2022-11-02 22:52:50 +01:00
|
|
|
```
|
|
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
Dans ce cas, toutes les valeurs de la variable ou des variables seront des choix utilisables par l'utilisateur.
|
|
|
|
|
|
|
|
|
|
## Un variable à choix provenant d'une fonction jinja
|
2021-05-05 15:27:06 +02:00
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
Faisons d'abord une fonction `trange` dans le fichier functions.py :
|
2021-05-05 15:27:06 +02:00
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
```python
|
|
|
|
|
def trange(min, max):
|
|
|
|
|
return range(min, ma
|
2021-05-05 15:27:06 +02:00
|
|
|
```
|
2022-11-02 22:52:50 +01:00
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
On va récupérer ici les valeurs de 0 à 9 :
|
2022-11-02 22:52:50 +01:00
|
|
|
|
2022-11-03 22:17:43 +01:00
|
|
|
```yml
|
2023-10-12 08:17:30 +02:00
|
|
|
---
|
|
|
|
|
version: '1.0'
|
|
|
|
|
my_variable:
|
|
|
|
|
type: choice
|
|
|
|
|
default: 9
|
|
|
|
|
choices:
|
|
|
|
|
type: jinja
|
|
|
|
|
jinja: |+
|
|
|
|
|
{% for item in trange(0, 10) %}
|
|
|
|
|
{{ item }}
|
|
|
|
|
{%- endfor %}
|
|
|
|
|
return_type: number
|
2022-11-02 22:52:50 +01:00
|
|
|
```
|