Skip to content

Commit

Permalink
update schema conf for separate module section
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed Aug 14, 2023
1 parent 652a7fd commit 3363aff
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions contrib/occtax/backend/occtax/conf_schema_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
Fichier à ne pas modifier. Paramètres surcouchables dans config/config_gn_module.tml
"""

from marshmallow import Schema, fields, post_load
from marshmallow import Schema, fields


from geonature.utils.module import get_module_config_path
from geonature.utils.utilstoml import load_toml


class MapListConfig(Schema):
Expand Down Expand Up @@ -157,7 +161,7 @@ class FormConfig(Schema):
]


class GnModuleSchemaConf(Schema):
class OcctaxSchemaConf(Schema):
form_fields = fields.Nested(FormConfig, load_default=FormConfig().load({}))
observers_txt = fields.Boolean(load_default=False)
export_view_name = fields.String(load_default="v_export_occtax")
Expand Down Expand Up @@ -191,3 +195,22 @@ class GnModuleSchemaConf(Schema):
ADD_MEDIA_IN_EXPORT = fields.Boolean(load_default=False)
ID_LIST_HABITAT = fields.Integer(load_default=None)
CD_TYPO_HABITAT = fields.Integer(load_default=None)


occtax_config_path = get_module_config_path("OCCTAX")
occtax_config = load_toml(occtax_config_path) if occtax_config_path else {}
submodules = occtax_config.get("SUBMODULES", [])

config_fields = OcctaxSchemaConf().fields


if len(submodules) > 0:
submodules.append("DEFAULT")
dict_nested = {}
for sub in submodules:
dict_nested[sub] = fields.Nested(config_fields, load_default=OcctaxSchemaConf().load({}))

GnModuleSchemaConf = type("GnModuleSchemaConf", (Schema,), dict_nested)

else:
GnModuleSchemaConf = type("GnModuleSchemaConf", (Schema,), config_fields)

0 comments on commit 3363aff

Please sign in to comment.