diff --git a/backend/geonature/core/gn_synthese/utils/query_select_sqla.py b/backend/geonature/core/gn_synthese/utils/query_select_sqla.py index 7ecf1f5267..7f970845a2 100644 --- a/backend/geonature/core/gn_synthese/utils/query_select_sqla.py +++ b/backend/geonature/core/gn_synthese/utils/query_select_sqla.py @@ -255,12 +255,6 @@ def filter_taxonomy(self): if len(cd_ref_childs) > 0: self.add_join(Taxref, Taxref.cd_nom, self.model.cd_nom) self.query = self.query.where(Taxref.cd_ref.in_(cd_ref_childs)) - if "taxonomy_group2_inpn" in self.filters: - self.add_join(Taxref, Taxref.cd_nom, self.model.cd_nom) - self.query = self.query.where( - Taxref.group2_inpn.in_(self.filters.pop("taxonomy_group2_inpn")) - ) - if "taxonomy_id_hab" in self.filters: self.add_join(Taxref, Taxref.cd_nom, self.model.cd_nom) self.query = self.query.where( @@ -272,6 +266,13 @@ def filter_taxonomy(self): red_list_filters = {} for colname, value in self.filters.items(): + if colname.startswith("taxonomy_group"): + # colname = group type (group2 or group3 inpn) + # value = list of group values + colname = colname.split("taxonomy_")[-1] + self.add_join(Taxref, Taxref.cd_nom, self.model.cd_nom) + self.query = self.query.where(getattr(Taxref, colname).in_(value)) + if colname.startswith("taxhub_attribut"): self.add_join(Taxref, Taxref.cd_nom, self.model.cd_nom) taxhub_id_attr = colname[16:] diff --git a/backend/geonature/tests/test_synthese.py b/backend/geonature/tests/test_synthese.py index a0e0607e98..0e052a23d1 100644 --- a/backend/geonature/tests/test_synthese.py +++ b/backend/geonature/tests/test_synthese.py @@ -484,33 +484,29 @@ def test_filter_cor_observers(self, users, synthese_data): assert response.status_code == 200 @pytest.mark.parametrize( - "additionnal_column", - [("altitude_min"), ("count_min_max"), ("nom_vern_or_lb_nom")], + "group_inpn", + [ + ("group2_inpn"), + ("group3_inpn"), + ], ) - def test_get_observations_for_web_param_column_frontend( - self, app, users, synthese_data, additionnal_column - ): - """ - Test de renseigner le paramètre LIST_COLUMNS_FRONTEND pour renvoyer uniquement - les colonnes souhaitées - """ - app.config["SYNTHESE"]["LIST_COLUMNS_FRONTEND"] = [ - { - "prop": additionnal_column, - "name": "My label", - } - ] + def test_get_observations_for_web_filter_group_inpn(self, users, synthese_data, group_inpn): + obs = synthese_data["obs1"] + taxref_from_cd_nom = Taxref.query.filter_by(cd_nom=obs.cd_nom).one() + group_from_taxref = getattr(taxref_from_cd_nom, group_inpn) + filter_name = "taxonomie_" + group_inpn set_logged_user(self.client, users["self_user"]) - - response = self.client.get(url_for("gn_synthese.get_observations_for_web")) - data = response.get_json() - - expected_columns = {"id", "url_source", additionnal_column} - - assert all( - set(feature["properties"].keys()) == expected_columns for feature in data["features"] + response = self.client.get( + url_for("gn_synthese.get_observations_for_web"), + json={ + filter_name: [group_from_taxref], + }, ) + response_json = response.json + assert obs.id_synthese in { + synthese["properties"]["id"] for synthese in response_json["features"] + } def test_export(self, users): set_logged_user(self.client, users["self_user"]) @@ -736,6 +732,7 @@ def test_export_taxons(self, users, synthese_data, synthese_sensitive_data): '"nom_vern"', '"group1_inpn"', '"group2_inpn"', + '"group3_inpn"', '"regne"', '"phylum"', '"classe"', @@ -761,7 +758,7 @@ def assert_export_taxons_results(user, set_expected_cd_ref): rows_data_response = response.data.decode("utf-8").split("\r\n")[0:-1] row_header = rows_data_response[0] rows_taxons_data_response = rows_data_response[1:] - + print(row_header.split(";"), expected_columns_exports) assert row_header.split(";") == expected_columns_exports nb_expected_cd_noms = len(set_expected_cd_ref) diff --git a/frontend/src/app/GN2CommonModule/form/data-form.service.ts b/frontend/src/app/GN2CommonModule/form/data-form.service.ts index fc305bccef..b8c269b651 100644 --- a/frontend/src/app/GN2CommonModule/form/data-form.service.ts +++ b/frontend/src/app/GN2CommonModule/form/data-form.service.ts @@ -227,6 +227,10 @@ export class DataFormService { return this._http.get(`${this.config.API_TAXHUB}/taxref/regnewithgroupe2`); } + getGroup3Inpn() { + return this._http.get(`${this.config.API_TAXHUB}/taxref/groupe3_inpn`); + } + getTaxhubBibAttributes() { return this._http.get(`${this.config.API_TAXHUB}/bibattributs/`); } diff --git a/frontend/src/app/GN2CommonModule/form/synthese-form/advanced-form/synthese-advanced-form-store.service.ts b/frontend/src/app/GN2CommonModule/form/synthese-form/advanced-form/synthese-advanced-form-store.service.ts index 5769d2fe81..a5ed63fcdb 100644 --- a/frontend/src/app/GN2CommonModule/form/synthese-form/advanced-form/synthese-advanced-form-store.service.ts +++ b/frontend/src/app/GN2CommonModule/form/synthese-form/advanced-form/synthese-advanced-form-store.service.ts @@ -19,6 +19,7 @@ export class TaxonAdvancedStoreService { public formBuilded: boolean; public taxonomyHab: Array; public taxonomyGroup2Inpn: Array; + public taxonomyGroup3Inpn: Array; public redListsValues: any = {}; constructor( @@ -88,5 +89,9 @@ export class TaxonAdvancedStoreService { } this.taxonomyGroup2Inpn = all_groups; }); + + this._dataService.getGroup3Inpn().subscribe((data) => { + this.taxonomyGroup3Inpn = data.map((item) => ({ value: item })); + }); } } diff --git a/frontend/src/app/GN2CommonModule/form/synthese-form/advanced-form/synthese-advanced-form.component.html b/frontend/src/app/GN2CommonModule/form/synthese-form/advanced-form/synthese-advanced-form.component.html index 857f6ef23e..a32c1d18df 100644 --- a/frontend/src/app/GN2CommonModule/form/synthese-form/advanced-form/synthese-advanced-form.component.html +++ b/frontend/src/app/GN2CommonModule/form/synthese-form/advanced-form/synthese-advanced-form.component.html @@ -164,6 +164,18 @@
Attributs TaxRef
> +
+ + +
diff --git a/frontend/src/app/GN2CommonModule/form/synthese-form/synthese-form.service.ts b/frontend/src/app/GN2CommonModule/form/synthese-form/synthese-form.service.ts index 4c4591341b..4635b6b128 100644 --- a/frontend/src/app/GN2CommonModule/form/synthese-form/synthese-form.service.ts +++ b/frontend/src/app/GN2CommonModule/form/synthese-form/synthese-form.service.ts @@ -88,6 +88,7 @@ export class SyntheseFormService { taxonomy_lr: null, taxonomy_id_hab: null, taxonomy_group2_inpn: null, + taxonomy_group3_inpn: null, taxon_rank: null, });