Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix t_roles: add option to select no organism #178

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/t_roles/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,29 @@ class MultiCheckboxField(SelectMultipleField):
widget = widgets.ListWidget(prefix_label=False)
option_widget = widgets.CheckboxInput()

def coerce_for_select(value):
"""Permet à un champ de type SelectField contenant des id (=integer)
d'accepter une valeur vide permettant de définir le champ à NULL dans
la base de données.
Utiliser "coerce_for_select" à la place de la valeur "int" du
paramètre "coerce" d'un champ SelectField().
Ajouter ensuite :
- une entrée au paramètre "choices" qui contiendra :
choices=[("", "-- Selectionnez une valeur...")]
- une entrée au paramètre "validators" :
validators=[validators.Optional()]
"""
if value == "":
return None
else:
return int(value)

class Utilisateur(FlaskForm):
active = BooleanField('Actif', default = True, false_values=(False, 'false'))
nom_role = StringField('Nom', validators=[DataRequired(message="Le nom de l'utilisateur est obligatoire")])
prenom_role = StringField('Prenom')
desc_role = TextAreaField('Description')
id_organisme = SelectField('Organisme', coerce=int, choices=[], default=-1)
id_organisme = SelectField('Organisme', choices=[], coerce=coerce_for_select, default="", validators=[validators.Optional()])
a_groupe = SelectMultipleField('', choices=[], coerce=int)
identifiant = StringField('Identifiant')
pass_plus = PasswordField('Mot de passe')
Expand Down
2 changes: 1 addition & 1 deletion app/t_roles/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from pypnusershub import routes as fnauth
from pypnusershub.db.models import check_and_encrypt_password


from app.t_roles import forms as t_rolesforms
from app.models import TRoles, Bib_Organismes, CorRoles
from app.utils.utils_all import strigify_dict
Expand Down Expand Up @@ -131,6 +130,7 @@ def addorupdate(id_role=None):
form.id_organisme.choices = Bib_Organismes.choixSelect(
"id_organisme", "nom_organisme", order_by="nom_organisme"
)
form.id_organisme.choices.insert(0, ("", "-- Selectionnez un organisme..."))
form.a_groupe.choices = TRoles.choix_group("id_role", "nom_role", aucun=None)

if id_role is not None:
Expand Down