-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change model -> drop v_regne + v_group2inpn + tests (#514)
Co-authored-by: TheoLechemia <lechemia.theo@gmail.com> fix (bibattributs) : formatters works with empty liste_valeur_attribut Detail taxon : afficher les listes Populate cor_nom_liste : Correction si ligne vide ou champ cd_nom vide Populate bib_liste: bouton cancel Black Add test on populate bib_list (#520) Co-authored-by: TheoLechemia <lechemia.theo@gmail.com>
- Loading branch information
1 parent
f56043a
commit 355aa68
Showing
16 changed files
with
218 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from flask_admin.contrib.sqla.fields import QuerySelectField | ||
from flask_admin.form.fields import Select2Field | ||
from sqlalchemy import select | ||
|
||
from apptax.database import db | ||
from apptax.taxonomie.models import VMRegne, VMGroup2Inpn | ||
|
||
from flask_admin.contrib.sqla.fields import QuerySelectField | ||
from flask_admin.form.fields import Select2Field | ||
from sqlalchemy import select | ||
|
||
from apptax.database import db | ||
from apptax.taxonomie.models import VMRegne, VMGroup2Inpn | ||
|
||
|
||
class RegneAndGroupFormMixin: | ||
form_overrides = {"regne": QuerySelectField, "group2_inpn": QuerySelectField} | ||
|
||
form_args = { | ||
"regne": { | ||
"query_factory": lambda: db.session.scalars( | ||
select(VMRegne).where(VMRegne.regne.isnot(None)) | ||
).all(), | ||
"allow_blank": True, | ||
}, | ||
"group2_inpn": { | ||
"query_factory": lambda: db.session.scalars( | ||
select(VMGroup2Inpn).where(VMGroup2Inpn.group2_inpn.isnot(None)) | ||
), | ||
"allow_blank": True, | ||
}, | ||
} | ||
|
||
def on_model_change(self, form, model, is_created): | ||
""" | ||
Force None on empty string regne | ||
and put transform orm object in str | ||
""" | ||
# HACK otherwise QuerySelectField insert the VRegne object .. | ||
# Select2Fields with choices does not work because choices list | ||
# is load when app is loaded (its a probleme for migrations) | ||
if model.regne: | ||
model.regne = model.regne.regne | ||
if model.regne == "": | ||
model.regne = None | ||
|
||
if model.group2_inpn: | ||
model.group2_inpn = model.group2_inpn.group2_inpn | ||
if model.group2_inpn == "": | ||
model.group2_inpn = None |
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
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
Oops, something went wrong.