class ReleveSchema(MA.SQLAlchemyAutoSchema): class Meta: model = TRelevesOccurrence load_instance = True include_fk = True exclude = ("geom_local", ) date_min = fields.Date(format="%Y-%m-%d") date_max = fields.Date(format="%Y-%m-%d") hour_min = fields.Time(format="%H:%M", allow_none=True) hour_max = fields.Time(format="%H:%M", allow_none=True) geom_4326 = GeojsonSerializationField() id_digitiser = MA.auto_field(dump_only=True) t_occurrences_occtax = MA.Nested(OccurrenceSchema, many=True) observers = MA.Nested( ObserverSchema, many=True, allow_none=current_app.config.get("OCCTAX", {}).get("observers_txt", True), ) digitiser = MA.Nested(ObserverSchema, dump_only=True) dataset = MA.Nested(DatasetSchema, dump_only=True) habitat = MA.Nested(HabrefSchema, dump_only=True) @pre_load def make_releve(self, data, **kwargs): if data.get("observers") is None: data["observers"] = [] if data.get("id_releve_occtax") is None: data.pop("id_releve_occtax", None) return data
class OccurrenceSchema(MA.SQLAlchemyAutoSchema): class Meta: model = TOccurrencesOccurrence load_instance = True include_fk = True cor_counting_occtax = MA.Nested(CountingSchema, many=True) taxref = MA.Nested(TaxrefSchema, dump_only=True)
class OccurrenceSchema(MA.SQLAlchemyAutoSchema): class Meta: model = TOccurrencesOccurrence load_instance = True include_fk = True additional_fields = fields.Raw(allow_none=False, required=True) # additional_fields = fields.Raw(load_only=True) cor_counting_occtax = MA.Nested(CountingSchema, many=True) taxref = MA.Nested(TaxrefSchema, dump_only=True) pre_dump_fn = remove_additional_none_val
class DatasetActorSchema(MA.SQLAlchemyAutoSchema): class Meta: model = CorDatasetActor load_instance = True include_fk = True role = MA.Nested(UserSchema, dump_only=True) nomenclature_actor_role = MA.Nested(NomenclatureSchema, dump_only=True) organism = MA.Nested(OrganismeSchema, dump_only=True) @pre_load def make_dataset_actor(self, data, **kwargs): if data.get("id_cda") is None: data.pop("id_cda", None) return data
class AcquisitionFrameworkActorSchema(MA.SQLAlchemyAutoSchema): class Meta: model = CorAcquisitionFrameworkActor load_instance = True include_fk = True role = MA.Nested(UserSchema, dump_only=True) nomenclature_actor_role = MA.Nested(NomenclatureSchema, dump_only=True) organism = MA.Nested(OrganismeSchema, dump_only=True) cor_volets_sinp = MA.Nested(OrganismeSchema, dump_only=True) @pre_load def make_af_actor(self, data, **kwargs): if data.get("id_cafa") is None: data.pop("id_cafa", None) return data
class AcquisitionFrameworkSchema(MetadataSchema): class Meta: model = TAcquisitionFramework load_instance = True include_fk = True meta_create_date = fields.DateTime(dump_only=True) meta_update_date = fields.DateTime(dump_only=True) t_datasets = MA.Nested( DatasetSchema( exclude=( "acquisition_framework", "modules", "nomenclature_dataset_objectif", "nomenclature_collecting_method", "nomenclature_data_origin", "nomenclature_source_status", "nomenclature_resource_type", ), many=True, ), many=True ) bibliographical_references = MA.Nested( BibliographicReferenceSchema( exclude=( "acquisition_framework", ), many=True, ) , many=True, ) cor_af_actor = MA.Nested( AcquisitionFrameworkActorSchema, many=True ) cor_volets_sinp = MA.Nested( NomenclatureSchema, many=True, ) cor_objectifs = MA.Nested( NomenclatureSchema, many=True ) cor_territories = MA.Nested( NomenclatureSchema, many=True ) nomenclature_territorial_level = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_financing_type = MA.Nested(NomenclatureSchema, dump_only=True) creator = MA.Nested(UserSchema, dump_only=True)
class CountingSchema(MA.SQLAlchemyAutoSchema): class Meta: model = CorCountingOccurrence load_instance = True medias = MA.Nested(MediaSchema, many=True) @pre_load def make_counting(self, data, **kwargs): if data.get("id_counting_occtax") is None: data.pop("id_counting_occtax", None) return data
class BibliographicReferenceSchema(MetadataSchema): class Meta: model = TBibliographicReference load_instance = True include_fk = True acquisition_framework = MA.Nested("AcquisitionFrameworkSchema", exclude=("bibliographical_references",), dump_only=True) @pre_load def make_biblio_ref(self, data, **kwargs): print(data) if data.get("id_bibliographic_reference") is None: data.pop("id_bibliographic_reference", None) return data
class BibliographicReferenceSchema(CruvedSchemaMixin, SmartRelationshipsMixin, MA.SQLAlchemyAutoSchema): class Meta: model = TBibliographicReference load_instance = True include_fk = True acquisition_framework = MA.Nested("AcquisitionFrameworkSchema", dump_only=True) @pre_load def make_biblio_ref(self, data, **kwargs): if data.get("id_bibliographic_reference") is None: data.pop("id_bibliographic_reference", None) return data
class AcquisitionFrameworkSchema(CruvedSchemaMixin, SmartRelationshipsMixin, MA.SQLAlchemyAutoSchema): class Meta: model = TAcquisitionFramework load_instance = True include_fk = True meta_create_date = fields.DateTime(dump_only=True) meta_update_date = fields.DateTime(dump_only=True) t_datasets = MA.Nested(DatasetSchema, many=True) bibliographical_references = MA.Nested(BibliographicReferenceSchema, many=True) cor_af_actor = MA.Nested(AcquisitionFrameworkActorSchema, many=True, unknown=EXCLUDE) cor_volets_sinp = MA.Nested(NomenclatureSchema, many=True, unknown=EXCLUDE) cor_objectifs = MA.Nested(NomenclatureSchema, many=True, unknown=EXCLUDE) cor_territories = MA.Nested(NomenclatureSchema, many=True, unknown=EXCLUDE) nomenclature_territorial_level = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_financing_type = MA.Nested(NomenclatureSchema, dump_only=True) creator = MA.Nested(UserSchema, dump_only=True)
class Meta: model = TValidations load_instance = True include_fk = True validation_label = fields.Nested(NomenclatureSchema, dump_only=True) validator_role = MA.Nested(UserSchema, dump_only=True)
class DatasetSchema(MetadataSchema): class Meta: model = TDatasets load_instance = True include_fk = True meta_create_date = fields.DateTime(dump_only=True) meta_update_date = fields.DateTime(dump_only=True) cor_dataset_actor = MA.Nested( DatasetActorSchema, many=True ) modules = MA.Nested( ModuleSchema, many=True, exclude=("meta_create_date", "meta_update_date") ) creator = MA.Nested(UserSchema, dump_only=True) nomenclature_data_type = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_dataset_objectif = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_collecting_method = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_data_origin = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_source_status = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_resource_type = MA.Nested(NomenclatureSchema, dump_only=True) cor_territories = MA.Nested( NomenclatureSchema, many=True ) acquisition_framework = MA.Nested("AcquisitionFrameworkSchema", exclude=("t_datasets",), dump_only=True)
class DatasetSchema(CruvedSchemaMixin, SmartRelationshipsMixin, MA.SQLAlchemyAutoSchema): class Meta: model = TDatasets load_instance = True include_fk = True meta_create_date = fields.DateTime(dump_only=True) meta_update_date = fields.DateTime(dump_only=True) cor_dataset_actor = MA.Nested(DatasetActorSchema, many=True, unknown=EXCLUDE) modules = MA.Nested(ModuleSchema, many=True, exclude=("meta_create_date", "meta_update_date"), unknown=EXCLUDE) creator = MA.Nested(UserSchema, dump_only=True) nomenclature_data_type = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_dataset_objectif = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_collecting_method = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_data_origin = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_source_status = MA.Nested(NomenclatureSchema, dump_only=True) nomenclature_resource_type = MA.Nested(NomenclatureSchema, dump_only=True) cor_territories = MA.Nested(NomenclatureSchema, many=True, unknown=EXCLUDE) acquisition_framework = MA.Nested("AcquisitionFrameworkSchema", dump_only=True)