Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/synthese search group3 inpn #2621

Merged
Merged
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
13 changes: 7 additions & 6 deletions backend/geonature/core/gn_synthese/utils/query_select_sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:]
Expand Down
45 changes: 21 additions & 24 deletions backend/geonature/tests/test_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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"',
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/GN2CommonModule/form/data-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ export class DataFormService {
return this._http.get<any>(`${this.config.API_TAXHUB}/taxref/regnewithgroupe2`);
}

getGroup3Inpn() {
return this._http.get<any>(`${this.config.API_TAXHUB}/taxref/groupe3_inpn`);
}

getTaxhubBibAttributes() {
return this._http.get<any>(`${this.config.API_TAXHUB}/bibattributs/`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class TaxonAdvancedStoreService {
public formBuilded: boolean;
public taxonomyHab: Array<any>;
public taxonomyGroup2Inpn: Array<any>;
public taxonomyGroup3Inpn: Array<any>;
public redListsValues: any = {};

constructor(
Expand Down Expand Up @@ -88,5 +89,9 @@ export class TaxonAdvancedStoreService {
}
this.taxonomyGroup2Inpn = all_groups;
});

this._dataService.getGroup3Inpn().subscribe((data) => {
this.taxonomyGroup3Inpn = data.map((item) => ({ value: item }));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ <h5>Attributs TaxRef</h5>
>
</pnx-multiselect>
</div>
<div class="form-group">
<pnx-multiselect
[values]="storeService.taxonomyGroup3Inpn"
[parentFormControl]="formService.searchForm.controls.taxonomy_group3_inpn"
keyLabel="value"
keyValue="value"
label="Groupe 3 INPN"
(onChange)="onTaxRefAttributsSelected($event.value)"
(onDelete)="onTaxRefAttributsDeleted($event.value.value)"
>
</pnx-multiselect>
</div>
</div>

<div *ngIf="storeService.formBuilded && storeService.taxhubAttributes.length > 0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
Loading