Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/gn_module_monitoring/config/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def get_config(module_code=None, force=False,customSpecConfig=None):
get_config_objects(module_code, config,customSpecConfig=customSpecConfig)

# customize config
# TODO: Adapter lorsqu'on entre par site (où est lié les liste des observateurs au moment on on propose lla lsite des observateurs ?
# , où est ce qu'on associe les organismes ? Bref tout ce qui est dans t_module_complements)
if module:
custom = {}
config['custom'] = {}
Expand Down
2 changes: 2 additions & 0 deletions backend/gn_module_monitoring/monitoring/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class MonitoringSite(MonitoringObjectGeom):
def preprocess_data(self, data):
if len(data["types_site"]) > 0 and all(isinstance(x, int) for x in data["types_site"]):
data["id_nomenclature_type_site"] = data["types_site"][0]
elif "data" in data and data["data"]["id_nomenclature_type_site"]:
data["id_nomenclature_type_site"] = data["data"]["id_nomenclature_type_site"]
else:
data["id_nomenclature_type_site"] = data["types_site"][0]["id_nomenclature_type_site"]
# TODO: A enlever une fois qu'on aura enelever le champ "id_nomenclature_type_site" du model et de la bdd
2 changes: 2 additions & 0 deletions backend/gn_module_monitoring/monitoring/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ class Meta:
class MonitoringSitesSchema(MA.SQLAlchemyAutoSchema):
class Meta:
model = TMonitoringSites
include_fk = True
exclude = ("geom_geojson", "geom")

geometry = fields.Method("serialize_geojson", dump_only=True)
pk = fields.Method("set_pk",dump_only=True)
types_site = MA.Nested(BibTypeSiteSchema, many=True)
medias = MA.Nested(MediaSchema,many=True)

def serialize_geojson(self, obj):
if obj.geom is not None:
Expand Down
29 changes: 29 additions & 0 deletions backend/gn_module_monitoring/routes/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,35 @@ def create_or_update_object_api_sites_sites_group(module_code, object_type, id=N
)


def get_config_object(module_code, object_type, id):
'''
renvoie un object, à partir de type de l'object et de son id

:param module_code: reference le module concerne
:param object_type: le type d'object (site, visit, obervation)
:param id : l'identifiant de l'object (de id_base_site pour site)
:type module_code: str
:type object_type: str
:type id: int

:return: renvoie l'object requis
:rtype: dict
'''

# field_name = param.get('field_name')
# value = module_code if object_type == 'module'
get_config(module_code, force=True)

depth = to_int(request.args.get('depth', 1))

return (
monitoring_definitions
.monitoring_object_instance(module_code, object_type, id)
.get(depth=depth)
# .get(value=value, field_name = field_name)
.serialize(depth)
)

# update object
@blueprint.route('object/<string:module_code>/<object_type>/<int:id>', methods=['PATCH'])
@blueprint.route(
Expand Down
10 changes: 9 additions & 1 deletion backend/gn_module_monitoring/routes/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
TNomenclatures,
)
from gn_module_monitoring.monitoring.schemas import BibTypeSiteSchema, MonitoringSitesSchema
from gn_module_monitoring.routes.monitoring import create_or_update_object_api_sites_sites_group
from gn_module_monitoring.routes.monitoring import create_or_update_object_api_sites_sites_group, get_config_object
from gn_module_monitoring.utils.routes import (
filter_params,
geojson_query,
Expand All @@ -25,6 +25,14 @@
)


@blueprint.route("/sites/config",
defaults={'id': None, 'object_type': "site",'module_code':'generic'},
methods=["GET"])
def get_config_sites(module_code, object_type, id):
obj = get_config_object(module_code, object_type, id)
return obj['properties']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plutôt obj.get('properties', {}) ? Ou on veut que ça plante si l'obj n'a pas de properties ? Ou alors properties est initialisé à {}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En l'écrivant je n'avais pas pensé au retour d'erreur possible. Effectivement ça peut être une possibilité de renvoyer une erreur , c'est plus un choix d'expérience utilisateur. Est ce que si l'utilisateur renseigne mal ses fichiers de config json , on renvoie une erreur où est ce qu'on veut que ça passe avec des properties vide .

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui je suis d'accord... A voir si cette route n'est pas appelée autre part où il n'y aurait pas obj['properties']. Je ne crois pas mais à vérifier quand même

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cette route est appelée uniquement dans le component monitorin-form.component-.ts pour charger la config , du coup on laisse le obj[properties] ?
Le cas où "properties" est vide était un cas qui pouvait déjà arrivrer avant. Si une erreur survient elle surviendra pas à ce niveau là du code . Elle surviendra avant dans le fichier qui était déjà présent avant serializer.py :

https://github.com/NaturalSolutions/gn_module_monitoring/blob/d73b7ae9f2a9686cad11671e21cef3b7a6811777/backend/gn_module_monitoring/monitoring/serializer.py#L150-L156



@blueprint.route("/sites/types", methods=["GET"])
def get_types_site():
params = MultiDict(request.args)
Expand Down
10 changes: 9 additions & 1 deletion backend/gn_module_monitoring/routes/sites_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@
paginate,
sort,
)
from gn_module_monitoring.routes.monitoring import create_or_update_object_api_sites_sites_group
from gn_module_monitoring.routes.monitoring import create_or_update_object_api_sites_sites_group, get_config_object
from gn_module_monitoring.utils.utils import to_int


@blueprint.route("/sites_groups/config",
defaults={'id': None, 'object_type': "sites_group",'module_code':'generic'},
methods=["GET"])
def get_config_sites_groups(module_code, object_type, id):
obj = get_config_object(module_code, object_type, id)
return obj['properties']


@blueprint.route("/sites_groups", methods=["GET"])
def get_sites_groups():
params = MultiDict(request.args)
Expand Down
7 changes: 4 additions & 3 deletions backend/gn_module_monitoring/tests/fixtures/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def site_to_post_with_types(users, types_site, site_group_without_sites):
specific_dic = {"owner_name": "Propriétaire", "threat": "Menaces", "owner_tel": "0609090909"}
schema_type_site = BibTypeSiteSchema()
mock_db_type_site = [schema_type_site.dump(type) for type in types_site.values()]
mock_model_type_site = [type for type in types_site.values()]

for type in mock_db_type_site:
list_nomenclature_id.append(type["id_nomenclature_type_site"])
for type in mock_model_type_site:
list_nomenclature_id.append(type.id_nomenclature_type_site)

site_to_post_with_types = TMonitoringSites(
id_inventor=user.id_role,
Expand All @@ -65,7 +66,7 @@ def site_to_post_with_types(users, types_site, site_group_without_sites):
base_site_code=f"New Code",
geom=geom_4326,
id_nomenclature_type_site=list_nomenclature_id[0],
types_site=list_nomenclature_id,
types_site=mock_model_type_site,
id_sites_group=site_group_without_sites.id_sites_group,
)

Expand Down
19 changes: 17 additions & 2 deletions backend/gn_module_monitoring/tests/test_routes/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_get_types_site_by_label(self, types_site):
"page": 1,
"sort_label": "label_fr",
"sort_dir": "asc",
"label_fr": string_contains
"label_fr": string_contains,
}
r = self.client.get(
url_for("monitorings.get_types_site_by_label"), query_string=query_string
Expand All @@ -176,7 +176,7 @@ def test_post_sites(self, site_to_post_with_types, types_site, site_group_withou
res.as_dict()["base_site_name"]
== site_to_post_with_types["properties"]["base_site_name"]
)

def test_delete_site(self, sites):
site = list(sites.values())[0]
id_base_site = site.id_base_site
Expand All @@ -190,3 +190,18 @@ def test_delete_site(self, sites):
with pytest.raises(Exception) as e:
TMonitoringSites.query.get_or_404(id_base_site)
assert "404 Not Found" in str(e.value)

def test_get_config_sites(self, sites):
schema = MonitoringSitesSchema()

r = self.client.get(url_for("monitorings.get_config_sites"))
list_sites = [schema.dump(site).keys() for site in sites.values()]
attr_post_added = "id_parent"
assert all(
[
attr in site
for site in list_sites
for attr in r.json.keys()
if attr != attr_post_added
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ <h2>Attention</h2>
</pnx-modal-msg>

<div>
<div id="properties-form" class="cadre" *ngIf="!hideForm">
<div id="properties-form" class="cadre" *ngIf="!hideForm && obj.bIsInitialized && objFormsDefinition">
<!-- TODO: voir pour intiialisation si nécessaire à remettre dans la div du dessus -->
<!-- *ngIf="obj.bIsInitialized && objFormsDefinition" -->

<!-- TODO: Voir pour l'enchainement des saisies -->
<!-- <span
<span
*ngIf="!obj.id && obj.config['chained']"
id="toggle-btn"
class="float-right"
Expand All @@ -37,7 +37,7 @@ <h2>Attention</h2>
(change)="bChainInputChanged($event)"
>
</mat-slide-toggle>
</span> -->
</span>

<form [formGroup]="objForm">
<!-- TODO: Gérer la saisie de géometrie -->
Expand Down Expand Up @@ -94,14 +94,15 @@ <h2>Attention</h2>
aria-hidden="true"
></span>

<!-- <span *ngIf="bChainInput && !obj.id"
<span *ngIf="bChainInput && !obj.id"
>Valider et enchainer les saisies</span
> -->
<!-- <span *ngIf="!bChainInput || obj.id">Valider</span>
</button> -->
<span>Valider</span>
>
<span *ngIf="!bChainInput || obj.id">Valider</span>
</button>

<!-- <span>Valider</span>
</button> -->

<button class="btn btn-primary float-left" (click)="onCancelEdit()">Annuler</button>
<button class="btn btn-danger float-left" (click)="bDeleteModal = true" *ngIf="obj.id">
Supprimer
Expand Down
Loading