Skip to content

Commit

Permalink
fix: cd_nom missing on post observation
Browse files Browse the repository at this point in the history
Reviewed-by: andriacap
  • Loading branch information
andriacap committed Mar 1, 2024
1 parent b5eb2c4 commit f955ed3
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions backend/gn_module_monitoring/monitoring/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from ..routes.data_utils import id_field_name_dict
from geonature.utils.env import DB
from geonature.core.gn_permissions.tools import get_scopes_by_action
from geonature.core.gn_monitoring.models import (

Check warning on line 12 in backend/gn_module_monitoring/monitoring/serializer.py

View check run for this annotation

Codecov / codecov/patch

backend/gn_module_monitoring/monitoring/serializer.py#L12

Added line #L12 was not covered by tests
TIndividuals,
)


class MonitoringObjectSerializer(MonitoringObjectBase):
Expand Down Expand Up @@ -154,8 +157,24 @@ def serialize(self, depth=1):
return monitoring_object_dict

def preprocess_data(self, data):
# a redefinir dans la classe
pass

# Query TIndividuals to get the cd_nom
if (

Check warning on line 162 in backend/gn_module_monitoring/monitoring/serializer.py

View check run for this annotation

Codecov / codecov/patch

backend/gn_module_monitoring/monitoring/serializer.py#L162

Added line #L162 was not covered by tests
self._object_type == "observation"
and data["cd_nom"] is None
and data["id_individual"] is not None
or (
self._object_type == "observation"
and self._id is not None
and data["id_individual"] is not None
)
):
individual = TIndividuals.query.get(data["id_individual"])
if individual is None:
raise ValueError("TIndividuals with provided id_individual not found")

Check warning on line 174 in backend/gn_module_monitoring/monitoring/serializer.py

View check run for this annotation

Codecov / codecov/patch

backend/gn_module_monitoring/monitoring/serializer.py#L172-L174

Added lines #L172 - L174 were not covered by tests
else:
data["cd_nom"] = individual.cd_nom
return data

Check warning on line 177 in backend/gn_module_monitoring/monitoring/serializer.py

View check run for this annotation

Codecov / codecov/patch

backend/gn_module_monitoring/monitoring/serializer.py#L176-L177

Added lines #L176 - L177 were not covered by tests

def populate(self, post_data):
# pour la partie sur les relationships mettre le from_dict dans utils_flask_sqla ???
Expand Down

0 comments on commit f955ed3

Please sign in to comment.