from marshmallow import Schema, pre_load, fields, EXCLUDE
from pypnnomenclature.schemas import NomenclatureSchema
from pypnusershub.schemas import UserSchema
from geonature.utils.env import MA
from geonature.core.gn_commons.models import (
TModules,
TMedias,
TValidations,
TAdditionalFields,
BibWidgets,
)
[docs]
class ModuleSchema(MA.SQLAlchemyAutoSchema):
[docs]
class TValidationSchema(MA.SQLAlchemyAutoSchema):
[docs]
validation_label = fields.Nested(NomenclatureSchema, dump_only=True)
[docs]
validator_role = MA.Nested(UserSchema, dump_only=True)
[docs]
class LabelValueDict(Schema):
[docs]
class TAdditionalFieldsSchema(MA.SQLAlchemyAutoSchema):
[docs]
def load(self, data, *, many=None, **kwargs):
if data["type_widget"].widget_name in (
"select",
"checkbox",
"radio",
"multiselect",
):
LabelValueDict(many=True).load(data["field_values"])
return super().load(data, many=many, unknown=EXCLUDE)