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/ajout statuts fiche espece #594

Draft
wants to merge 40 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
40177b5
Update atlasRoutes.py
pbarille Jun 14, 2024
ec105d3
Update config_schema.py
pbarille Jun 14, 2024
f9beaa7
Create vmStatutBdc.py
pbarille Jun 14, 2024
ee2aed2
Create vmStatutBdcRepository.py
pbarille Jun 14, 2024
3e35587
Update ficheEspece.css
pbarille Jun 14, 2024
8ac8788
Update identityCard.html
pbarille Jun 14, 2024
d2b1567
Create 15.atlas.vm_statut_bdc
pbarille Jun 14, 2024
e36db2e
Update install_db.sh
pbarille Jun 14, 2024
c623668
Update 15.atlas.vm_statut_bdc
pbarille Jun 17, 2024
100ad54
Update install_db.sh
pbarille Jun 17, 2024
c5211b8
Update config.py.sample
pbarille Jun 17, 2024
abb952a
Update config.py.example
pbarille Jun 17, 2024
1a1659c
Update 15.atlas.vm_statut_bdc
pbarille Jun 17, 2024
63421ad
Update install_db.sh
pbarille Jun 17, 2024
7ce8da4
Update config.py.example
pbarille Jun 17, 2024
2b9464f
Update config.py.sample
pbarille Jun 17, 2024
1a38330
Renomme vm_statut_bdc => vm_bdc_statut
marcantoinedupre Jan 9, 2025
1e4a001
Refactor vm_bdc_statut
marcantoinedupre Jan 9, 2025
bbd92b2
Corrige procédure installation vm_bdc_statut
marcantoinedupre Jan 9, 2025
38296c8
Renomme paramètres d'installation
marcantoinedupre Jan 9, 2025
b4ee0a7
Retire GROUP BY inutile
marcantoinedupre Jan 9, 2025
613bad9
Refactor vm_bdc_statut create
marcantoinedupre Jan 9, 2025
36995c7
Move BDC Statuts foreign tables definitions to foreign schema
marcantoinedupre Jan 9, 2025
2e54cb0
Ajout vm_bdc_statut à atlas.refresh_materialized_view_data()
marcantoinedupre Jan 9, 2025
63393f8
Ajout index sur cd_ref à vm_bdc_statut
marcantoinedupre Jan 9, 2025
a7f7853
Renomme STATUS_BDC_ENABLE => AFFICHAGE_STATUTS
marcantoinedupre Jan 9, 2025
3da1579
Move statuts HTML code to a custom template
marcantoinedupre Jan 9, 2025
ffc95f1
Ajoute données statuts à fiche espèce
marcantoinedupre Jan 9, 2025
96bc902
Refonte HTML pour récupérer marge droite accidentelle
marcantoinedupre Jan 9, 2025
f1cb6b0
Déplace section statuts au-dessus de l'arbre taxonomique
marcantoinedupre Jan 9, 2025
2d00555
Auto-format vmStatutBdcRepository.py
marcantoinedupre Jan 9, 2025
2527199
Refactor vmStatutBdcRepository.py
marcantoinedupre Jan 9, 2025
39dcf33
Ajout champs rq_statut et cd_sig
marcantoinedupre Jan 9, 2025
b4da9dc
Ajout groupes de statuts et refonte affichage
marcantoinedupre Jan 9, 2025
067e34f
Ajout modale détails des statuts
marcantoinedupre Jan 9, 2025
6d103b9
Remove unneeded sort on statuts repository result
marcantoinedupre Jan 9, 2025
8e4c21c
Remove unused model VmStatutBdc
marcantoinedupre Jan 9, 2025
9b7bf2a
Ajustements CSS modale
marcantoinedupre Jan 10, 2025
19ad4ee
Code formatting fixes with black
marcantoinedupre Jan 10, 2025
cb0c38e
Fix atlas routes on prod env
marcantoinedupre Jan 10, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ atlas/static/custom/templates/credits.html
atlas/static/custom/templates/mentions-legales.html
atlas/static/custom/templates/personal-data.html
atlas/static/custom/templates/navbar.html
atlas/static/custom/templates/statuts.html

data/ref/emprise_territoire.*
data/ref/communes.dbf
Expand Down
40 changes: 40 additions & 0 deletions atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
vmMedias,
vmCorTaxonAttribut,
vmTaxonsMostView,
vmStatutBdcRepository,
)


Expand Down Expand Up @@ -263,6 +264,9 @@ def ficheEspece(cd_nom):

organisms = vmOrganismsRepository.getListOrganism(connection, cd_ref)

statuts = vmStatutBdcRepository.get_taxons_statut_bdc(connection, cd_ref)
groupes_statuts = _make_groupes_statuts(statuts)

connection.close()
db_session.close()

Expand All @@ -284,9 +288,45 @@ def ficheEspece(cd_nom):
taxonDescription=taxonDescription,
observers=observers,
organisms=organisms,
groupesStatuts=groupes_statuts,
)


def _make_groupes_statuts(statuts):
"""Groupe les statuts de la BDC suivant la configuration GROUPES_STATUTS.

Retourne une liste de groupes. Un groupe est de la forme :

{
"label": "Monde",
"statuts": [
{
"cd_type_statut": "LRM",
"lb_type_statut": "Liste Rouge Mondiale",
"cd_sig": "WORLD",
"code_statut": "LC",
"label_statut": "Préoccupation mineure",
"rq_statut": ""
}
]
}
"""

def is_statut_in_groupe(statut, groupe):
group_types = {origin["cd_type_statut"] for origin in groupe["origins"]}
group_sigs = {origin["cd_sig"] for origin in groupe["origins"]}
return statut["cd_type_statut"] in group_types and statut["cd_sig"] in group_sigs

groupes_statuts = []
for config_groupe in current_app.config["GROUPES_STATUTS"]:
groupe = {"label": config_groupe.get("label", ""), "statuts": []}
groupes_statuts.append(groupe)
for statut in statuts:
if is_statut_in_groupe(statut, config_groupe):
groupe["statuts"].append(statut)
return groupes_statuts


@main.route("/commune/<insee>", methods=["GET", "POST"])
def ficheCommune(insee):
session = db.session
Expand Down
39 changes: 39 additions & 0 deletions atlas/configuration/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,45 @@ AFFICHAGE_GRAPH_ALTITUDES = True
# Afficher le graphique de la phénologie. Affichage True/False
AFFICHAGE_GRAPH_PHENOLOGIE = True

# Afficher les statuts de protection. Affichage True/False
AFFICHAGE_STATUTS = True

# Configure quels statuts de protection sont affichés et dans quel ordre.
# - il est possible de définir plusieurs origines pour un groupe (pour grouper les listes rouges et les marqueurs znieff d'une même zone par exemple).
# - 'label' du groupe sera affiché devant l'ensemble des statuts provenant des origines spécifiées. 'label' est optionnel.
# - les valeurs des propriétés `cd_type_statut` et `cd_sig` correspondent aux valeurs présentes dans la BDD `atlas.vm_bdc_statut`.
GROUPES_STATUTS = [
{
"label": "Monde",
"origins": [
{"cd_type_statut": "LRM", "cd_sig": "WORLD"}
]
},
{
"label": "Europe",
"origins": [
{"cd_type_statut": "LRE", "cd_sig": "EUROPE"}
]
},
{
"label": "France métropolitaine",
"origins": [
{"cd_type_statut": "LRN", "cd_sig": "TERFXFR"}
]
},
{
"label": "Région",
"origins": [
{"cd_type_statut": "LRR", "cd_sig": <votre code région>} # par exemple "INSEER52"
]
},
{
"origins": [
{"cd_type_statut": "ZDET", "cd_sig": <votre code département>} # par exemple "INSEED44"
]
}
]

# Rang taxonomique qui fixe jusqu'à quel taxon remonte la filiation taxonomique (hierarchie dans la fiche d'identite : Famille, Ordre etc... )
LIMIT_RANG_TAXONOMIQUE_HIERARCHIE = 13

Expand Down
13 changes: 13 additions & 0 deletions atlas/configuration/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ class Meta:
AFFICHAGE_RECHERCHE_AVANCEE = fields.Boolean(load_default=False)
AFFICHAGE_GRAPH_ALTITUDES = fields.Boolean(load_default=True)
AFFICHAGE_GRAPH_PHENOLOGIE = fields.Boolean(load_default=True)
AFFICHAGE_STATUTS = fields.Boolean(load_default=True)
GROUPES_STATUTS = fields.List(
fields.Dict,
load_default=[
{"label": "Monde", "origins": [{"cd_type_statut": "LRM", "cd_sig": "WORLD"}]},
{"label": "Europe", "origins": [{"cd_type_statut": "LRE", "cd_sig": "EUROPE"}]},
{
"label": "France métropolitaine",
"origins": [{"cd_type_statut": "LRN", "cd_sig": "TERFXFR"}],
},
],
)

RANG_STAT = fields.List(
fields.Dict,
Expand Down Expand Up @@ -207,6 +219,7 @@ class Meta:
SPLIT_NOM_VERN = fields.Boolean(load_default=True)
INTERACTIVE_MAP_LIST = fields.Boolean(load_default=True)
AVAILABLE_LANGUAGES = fields.Dict(load_default=LANGUAGES)
AFFICHAGE_STATUTS = fields.Boolean(load_default=True)
# Flask parameter enabling auto reload of templates
# (no need to restart the atlas service when updating templates)
# Defaults to False to have the best performance in production
Expand Down
13 changes: 13 additions & 0 deletions atlas/configuration/settings.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ attr_chorologie=103
# 15 jours par défaut
time=15

# Les paramètres `bdc_statuts_types` et `bdc_statuts_sigs` permettent de réduire les données de la BDC Statuts aux statuts qui
# seront effectivement utilisés. Permet un gain d'espace non négligeable et un léger gain de performance.

# La liste des types de statuts à importer pour l'affichage des statuts de protection des espèces. Les valeurs attendues
# permettent de filtrer la colonne `cd_type_statut` de la VM générée à partir de `taxonomie.bdc_statut`.
bdc_statuts_types = ['LRM', 'LRE', 'LRN', 'LRR', 'ZDET']

# La liste des zones géographiques à importer pour l'affichage des statuts de protection des espèces. Les valeurs attendues
# permettent de filtrer la colonne `cd_sig` de la VM générée à partir de `taxonomie.bdc_statut`.
# Ajustez la valeur donnée en exemple avec vos codes régions et départements, par exemple :
# bdc_statuts_sigs = ['WORLD', 'EUROPE', 'TERFXFR', 'INSEER52', 'INSEED44']
bdc_statuts_sigs = ['WORLD', 'EUROPE', 'TERFXFR']

##################################################
########## Paramatre administrateur avancé #######
##################################################
Expand Down
19 changes: 19 additions & 0 deletions atlas/modeles/repositories/vmStatutBdcRepository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from sqlalchemy.sql import text


def get_taxons_statut_bdc(connection, cd_ref):
sql = "SELECT * FROM atlas.vm_bdc_statut WHERE cd_ref = :thiscdref"
result = connection.execute(text(sql), thiscdref=cd_ref)
statuts = list()
for row in result:
statut = {
"rq_statut": row.rq_statut,
"code_statut": row.code_statut,
"label_statut": row.label_statut,
"cd_type_statut": row.cd_type_statut,
"lb_type_statut": row.lb_type_statut,
"lb_adm_tr": row.lb_adm_tr,
"cd_sig": row.cd_sig,
}
statuts.append(statut)
return statuts
132 changes: 124 additions & 8 deletions atlas/static/css/ficheEspece.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,9 @@ p.imgDescription.main {

/* */

#groupLogoCol {
padding-left: 0px;
position: absolute;
right: 2%;
top: 4%;
}

#taxonName {
max-width: 85%;
display: flex;
justify-content: space-between;
}

#taxonomy {
Expand Down Expand Up @@ -284,3 +278,125 @@ text {
.carousel-indicators {
bottom: 0px;
}

div#statut-bdc {
margin-top: 15px;
padding-top : 10px;
padding-bottom : 10px;
}

div#statut-bdc h5 a {
text-decoration: none;
color: black;
}

div#statut-bdc h5 a:hover {
color: var(--second-color);
}

div#statut-bdc span.NT {
color: white;
background-color: #cce226 ;
}

div#statut-bdc span.LC {
color: white;
background-color: #60c659 ;
}

div#statut-bdc span.EN {
color: white;
background-color: #fc7f3f ;
}

div#statut-bdc span.VU {
background-color: #f9e814 ;
}

div#statut-bdc span.CR {
color: white;
background-color: #d81e05 ;
}

div#statut-bdc span.RE {
color: white;
background-color: #5b1064 ;
}

div#statut-bdc span.NA {
color: white;
background-color: #929392 ;
}

div#statut-bdc span.NE {
background-color: white ;
}

div#statut-bdc span.DD {
background-color: #d1d1c6 ;
}

div#statut-bdc span.DHFF {
color: white;
background-color: #afdde9 ;
}

div#statut-bdc span.PN {
color: white;
background-color: #ffccaa ;
}

div#statut-bdc span.bloc-statut-bdc {
border: solid 2px grey;
padding-left: 5px;
padding-right: 5px;
border-radius: 5px;
}

div#statut-bdc .groupes-statuts-container {
display: grid;
grid-template-columns: minmax(min-content, 40%) 1fr;
gap: 0.5em 1em;
}

div#statut-bdc .groupe-label {
text-align: end;
}

div#statut-bdc ul {
display: inline-block;
padding: 0;
margin: 0;
}

div#statut-bdc li {
display: inline-block;
}

div#statut-bdc .modale-statuts-container {
display: grid;
grid-template-columns: minmax(30%, max-content) 1fr;
align-items: center;
gap: 0.8rem 1rem;
}

div#statut-bdc .modale-statuts-container .statut-origine {
text-align: right;
}

div#statut-bdc .modale-statuts-container ul {
display: flex;
flex-direction: column;
gap: 0.2rem 0.5rem;
}

div#statut-bdc .modale-statuts-container li {
display: flex;
align-content: center;
flex-wrap: wrap;
gap: 0.5rem;
}

div#statut-bdc .modale-statuts-container p {
margin: 0;
}
Loading
Loading