Skip to content

Commit

Permalink
SYNTHESE : add customizable fields to the list - close #2946
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed Mar 11, 2024
1 parent b90b8ba commit aba9e85
Show file tree
Hide file tree
Showing 7 changed files with 3,242 additions and 3,217 deletions.
5 changes: 4 additions & 1 deletion backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from werkzeug.exceptions import Forbidden, NotFound, BadRequest, Conflict
from werkzeug.datastructures import MultiDict
from sqlalchemy import distinct, func, desc, asc, select, case
from sqlalchemy.orm import joinedload, lazyload, selectinload, contains_eager
from geojson import FeatureCollection, Feature
import sqlalchemy as sa
from sqlalchemy.orm import load_only, aliased, Load, with_expression
Expand Down Expand Up @@ -148,7 +149,9 @@ def get_observations_for_web(permissions):

# Get Column Frontend parameter to return only the needed columns
param_column_list = {
col["prop"] for col in current_app.config["SYNTHESE"]["LIST_COLUMNS_FRONTEND"]
col["prop"]
for col in current_app.config["SYNTHESE"]["LIST_COLUMNS_FRONTEND"]
+ current_app.config["SYNTHESE"]["ADDITIONAL_COLUMNS_FRONTEND"]
}
# Init with compulsory columns
columns = []
Expand Down
13 changes: 10 additions & 3 deletions backend/geonature/tests/test_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ class CustomRequiredConverter(GeoModelConverter):

def _add_column_kwargs(self, kwargs, column):
super()._add_column_kwargs(kwargs, column)
default_cols = map(lambda col: col["prop"], config["SYNTHESE"]["LIST_COLUMNS_FRONTEND"])
default_cols = map(
lambda col: col["prop"],
config["SYNTHESE"]["LIST_COLUMNS_FRONTEND"]
+ config["SYNTHESE"]["ADDITIONAL_COLUMNS_FRONTEND"],
)
required_cols = list(default_cols) + MANDATORY_COLUMNS
kwargs["required"] = column.name in required_cols

Expand All @@ -131,8 +135,6 @@ class VSyntheseForWebAppSchema(GeoAlchemyAutoSchema):

class Meta:
model = VSyntheseForWebApp
feature_geometry = "the_geom_4326"
sqla_session = db.session
model_converter = CustomRequiredConverter


Expand Down Expand Up @@ -172,6 +174,10 @@ def test_required_fields_and_format(self, app, users):
{"prop": "count_min_max", "name": "Dénombrement"},
{"prop": "nom_vern_or_lb_nom", "name": "Taxon"},
]

app.config["SYNTHESE"]["ADDITIONAL_COLUMNS_FRONTEND"] += [
{"prop": "lb_nom", "name": "Nom scientifique"}
]
url_ungrouped = url_for("gn_synthese.get_observations_for_web")
set_logged_user(self.client, users["admin_user"])
resp = self.client.get(url_ungrouped)
Expand Down Expand Up @@ -226,6 +232,7 @@ def test_get_observations_for_web(self, app, users, synthese_data, taxon_attribu
"name": "Cdnom",
}
]
# schema["properties"]["observations"]["items"]["required"] =
# test on synonymy and taxref attrs
filters = {
"cd_ref": [taxon_attribut.bib_nom.cd_ref],
Expand Down
10 changes: 3 additions & 7 deletions backend/geonature/utils/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,11 @@ class Synthese(Schema):

# --------------------------------------------------------------------
# SYNTHESE - OBSERVATIONS LIST
# Listes des champs renvoyés par l'API synthese '/synthese'
# Si on veut afficher des champs personnalisés dans le frontend (paramètre LIST_COLUMNS_FRONTEND) il faut
# d'abbord s'assurer que ces champs sont bien renvoyé par l'API !
# Colonnes affichées par défaut sur la liste des résultats de la synthese
# Champs disponibles: tous ceux de la vue 'v_synthese_for_web_app
COLUMNS_API_SYNTHESE_WEB_APP = fields.List(
fields.String, load_default=DEFAULT_COLUMNS_API_SYNTHESE
)
# Colonnes affichées sur la liste des résultats de la sytnthese
LIST_COLUMNS_FRONTEND = fields.List(fields.Dict, load_default=DEFAULT_LIST_COLUMN)
# Colonnes affichables sur la liste des résultats de la synthese via la modale de selection des colonnes
ADDITIONAL_COLUMNS_FRONTEND = fields.List(fields.Dict, load_default=[])

# --------------------------------------------------------------------
# SYNTHESE - DOWNLOADS (AKA EXPORTS)
Expand Down
10 changes: 9 additions & 1 deletion config/default_config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,23 @@ MEDIA_CLEAN_CRONTAB = "0 1 * * *"

# Colonne à afficher par défaut sur la liste des résultats de la synthese
# Choisir le champ 'prop' parmis les colonnes suivantes :
# id (=id_synthese), date_min, cd_nom, lb_nom, nom_vern_or_lb_nom,
# id_synthese, date_min, cd_nom, lb_nom, nom_vern_or_lb_nom,
# observers, dataset_name, url_source, count_min_max
# La liste des colonnes affichables est celle de la vue `gn_synthese.v_synthese_for_export`+ `nom_vern_or_lb_nom` et `count_min_max`
LIST_COLUMNS_FRONTEND = [
{ prop = "nom_vern_or_lb_nom", name = "Taxon" },
{ prop = "date_min", name = "Date début" },
{ prop = "observers", name = "Observateurs" },
{ prop = "dataset_name", name = "Jeu de données" }
]

# Colonnes affichables dans la liste des résulats, mais masquées par default
# Possibilité de les ajouter en cliquant sur la route crantée en haut de la liste
# La liste des colonnes affichables est celle de la vue `gn_synthese.v_synthese_for_export`
ADDITIONAL_COLUMNS_FRONTEND = [
{ prop = "lb_nom", name = "Nom scientifique" },
]

# Nombre de résultats à afficher pour la recherche autocompletée de taxon
TAXON_RESULT_NUMBER = 20

Expand Down
Loading

0 comments on commit aba9e85

Please sign in to comment.