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 speciesSheet: custom TaxHub attributes for infos bloc #414

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
5 changes: 1 addition & 4 deletions atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ def ficheEspece(cd_nom):
taxonDescription = vmCorTaxonAttribut.getAttributesTaxon(
connection,
cd_ref,
current_app.config["ATTR_DESC"],
current_app.config["ATTR_COMMENTAIRE"],
current_app.config["ATTR_MILIEU"],
current_app.config["ATTR_CHOROLOGIE"],
current_app.config["DISPLAYED_ATTR"],
)
observers = vmObservationsRepository.getObservers(connection, cd_ref)

Expand Down
11 changes: 6 additions & 5 deletions atlas/configuration/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ REDIMENSIONNEMENT_IMAGE = False
# si REDIMENSIONNEMENT_IMAGE = True, indiquer l'URL de TaxHub
TAXHUB_URL = "http://mondomaine.fr/taxhub"

#### ID DES ATTRIBUTS DESCRIPTIFS DES TAXONS DE LA TABLE vm_cor_taxon_attribut
ATTR_DESC = 100
ATTR_COMMENTAIRE = 101
ATTR_MILIEU = 102
ATTR_CHOROLOGIE = 103
#### LISTE DES CODES DES ATTRIBUTS DESCRIPTIFS DES TAXONS DE LA TABLE vm_taxon_attribute
# Un onglet sera affiché dans le bloc "Informations espèces" de la fiche espèce
# pour chaque code d'attribut indiqué dans la liste ci-dessous.
# L'onglet n'est affiché que s'il possède du contenu.
# L'ordre des onglets correspond à l'ordre des codes dans la liste.
DISPLAYED_ATTR=["atlas_description", "atlas_commentaire", "atlas_milieu", "atlas_chorologie"]

#### ID DES TYPES DE MEDIAS DE LA TABLE vm_medias
ATTR_MAIN_PHOTO = 1
Expand Down
13 changes: 9 additions & 4 deletions atlas/configuration/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,15 @@ class Meta:
REMOTE_MEDIAS_PATH = fields.String(load_default="static/medias/")
REDIMENSIONNEMENT_IMAGE = fields.Boolean(load_default=False)
TAXHUB_URL = fields.String(required=False, load_default=None)
ATTR_DESC = fields.Integer(load_default=100)
ATTR_COMMENTAIRE = fields.Integer(load_default=101)
ATTR_MILIEU = fields.Integer(load_default=102)
ATTR_CHOROLOGIE = fields.Integer(load_default=103)
DISPLAYED_ATTR = fields.List(
fields.String(),
load_default=[
"atlas_description",
"atlas_commentaire",
"atlas_milieu",
"atlas_chorologie",
],
)
ATTR_MAIN_PHOTO = fields.Integer(load_default=1)
ATTR_OTHER_PHOTO = fields.Integer(load_default=2)
ATTR_LIEN = fields.Integer(load_default=3)
Expand Down
13 changes: 6 additions & 7 deletions atlas/configuration/settings.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ owner_atlas_pass=monpassachanger
geonature_source=true

# L'atlas est-il en lien avec le référentiel géographique de GeoNature (ref_geo) ?
# ATTENTION : Doit être égal à true si geonature_source=true,
# ATTENTION : Doit être égal à true si geonature_source=true,
# ATTENTION : Doit être égal à false si geonature_source=false
use_ref_geo_gn2=true

# Souhaitez-vous installer le schéma taxonomie de TaxHub dans la BDD de GeoNature-atlas ?
# Souhaitez-vous installer le schéma taxonomie de TaxHub dans la BDD de GeoNature-atlas ?
# false si vous souhaitez utiliser celui de GeoNature en FDW
# ATTENTION : Doit être true si geonature_source=false
install_taxonomie=false
Expand Down Expand Up @@ -122,12 +122,11 @@ altitudes=(0 500 1000 1500 2000 2500 3000 3500 4000)
# Numéro de version conseillée et testée : 1.8.1
taxhub_release=1.8.1

#### ID DES TYPES DES ATTRIBUTS DECRIVANT LES TAXONS DANS atlas.vm_cor_taxon_attribut --
#### LISTE DES CODES DES TYPES DES ATTRIBUTS DÉCRIVANT LES TAXONS DANS atlas.vm_taxon_attribute
## !! si changement: modifier également dans main/configuration/config.py
attr_desc=100
attr_commentaire=101
attr_milieu=102
attr_chorologie=103
# Les codes correspondent aux valeurs du champs `taxonomie.bib_attributs.nom_attribut`.
# Les codes doivent être séparé par des virgules et placé entre guillemets simples.
displayed_attr="'atlas_description', 'atlas_commentaire', 'atlas_milieu', 'atlas_chorologie'"

# Paramètre pour la vue atlas.vm_taxons_plus_observes
# Especes les plus observées sur la periode 'moins X jour, plus X jours par rapport à la date du jour, toutes années confondues'
Expand Down
32 changes: 9 additions & 23 deletions atlas/modeles/repositories/vmCorTaxonAttribut.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,16 @@
from sqlalchemy.sql import text


def getAttributesTaxon(connection, cd_ref, attrDesc, attrComment, attrMilieu, attrChoro):
def getAttributesTaxon(connection, cd_ref, displayed_attr):
sql = """
SELECT *
FROM atlas.vm_cor_taxon_attribut
WHERE id_attribut IN (:thisattrDesc, :thisattrComment, :thisattrMilieu, :thisattrChoro)
AND cd_ref = :thiscdref
FROM atlas.vm_taxon_attribute
WHERE code = ANY(:displayedAttr)
AND cd_ref = :cdRef
"""
req = connection.execute(
text(sql),
thiscdref=cd_ref,
thisattrDesc=attrDesc,
thisattrComment=attrComment,
thisattrMilieu=attrMilieu,
thisattrChoro=attrChoro,
)
results = connection.execute(text(sql), displayedAttr=displayed_attr, cdRef=cd_ref)

descTaxon = {"description": None, "commentaire": None, "milieu": None, "chorologie": None}
for r in req:
if r.id_attribut == attrDesc:
descTaxon["description"] = r.valeur_attribut
elif r.id_attribut == attrComment:
descTaxon["commentaire"] = r.valeur_attribut
elif r.id_attribut == attrMilieu:
descTaxon["milieu"] = r.valeur_attribut.replace("&", " | ")
elif r.id_attribut == attrChoro:
descTaxon["chorologie"] = r.valeur_attribut
return descTaxon
desc_taxon = []
for row in results:
desc_taxon.append({"code": row.code, "title": row.title, "value": row.value})
return desc_taxon
119 changes: 58 additions & 61 deletions atlas/templates/speciesSheet/blocInfos.html
Original file line number Diff line number Diff line change
@@ -1,67 +1,64 @@
{% block blocInfos %}
{% if configuration.GLOSSAIRE %}
<!-- Jquery Glossarizer -->
<script src="{{url_for('static', filename='node_modules/glossarizer/tooltip/tooltip.js') }}"></script>
<script src="{{url_for('static', filename='node_modules/glossarizer/jquery.glossarize.js') }}"></script>
<link rel="stylesheet" href="{{url_for('static', filename='node_modules/glossarizer/tooltip/tooltip.css') }}">
{% endif %}
{% if configuration.GLOSSAIRE %}
<!-- Jquery Glossarizer -->
<script src="{{url_for('static', filename='node_modules/glossarizer/tooltip/tooltip.js') }}"></script>
<script src="{{url_for('static', filename='node_modules/glossarizer/jquery.glossarize.js') }}"></script>
<link rel="stylesheet" href="{{url_for('static', filename='node_modules/glossarizer/tooltip/tooltip.css') }}" />
{% endif %}

<div class="card mt-4" id="blocInfos">
<h4 class="title-bar center">
<strong>{{ _('species.infos') }}</strong>
</h4>
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#description">{{ _('description') }}</a>
</li>
{% if taxonDescription.commentaire != None %}
<li><a class="nav-link" data-toggle="tab" href="#commentaire">{{ _('read.more') }}</a></li>
{% endif %}
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#milieu">{{ _('environment') }}</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#chorologie">{{ _('repartition') }}</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#synonymes">{{ _('synonyms') }}</a></li>
</ul>
<div class="card mt-4" id="blocInfos">
<h4 class="title-bar center">
<strong>{{ _('species.infos') }}</strong>
</h4>
<ul class="nav nav-tabs">
{% for desc in taxonDescription %}
<li class="nav-item">
<a
class="nav-link {% if loop.index == 1 %}active{% endif %}"
data-toggle="tab"
href="#{{desc.code}}"
>
{{ _(desc.title) }}
</a>
</li>
{% endfor %}
<li class="nav-item">
<a class="nav-link {% if taxonDescription|length == 0 %}active{% endif %}" data-toggle="tab" href="#synonymes">
{{ _('synonyms') }}
</a>
</li>
</ul>

<div class="tab-content">
<div id="description" class="tab-pane fade show active">
{% if taxonDescription.description == None %}
{{ _('not.resigned.for.the.moment') }}
{% else %}
{{ taxonDescription.description | safe }}
{% endif %}
</div>
{% if taxonDescription.commentaire != None %}
<div id="commentaire" class="tab-pane fade">
{{ taxonDescription.commentaire | safe }}
</div>
{% endif %}
<div id="milieu" class="tab-pane fade">
{% if taxonDescription.milieu == None %}
{{ _('not.resigned.for.the.moment') }}
{% else %}
{{ taxonDescription.milieu }}
{% endif %}
</div>
<div id="chorologie" class="tab-pane fade">
{% if taxonDescription.chorologie == None %}
{{ _('not.resigned.for.the.moment') }}
{% else %}
{{ taxonDescription.chorologie }}
{% endif %}
</div>
<div id="synonymes" class="tab-pane fade">
{% if synonyme | length == 1 %}
{{ _('no.synonym.for.this.taxon') }}
{% else %}
{% for syn in synonyme %}
{% if not syn.lb_nom == taxon.taxonSearch.lb_nom %}
{{ syn.nom_complet_html | safe }}
{% endif %}
{% if ( (not loop.last) and (not syn.lb_nom == taxon.taxonSearch.lb_nom) ) %}
|
{% endif %}
<div class="tab-content">
{% for desc in taxonDescription %}
<div
id="{{desc.code}}"
class="tab-pane fade {% if loop.index == 1 %}show active{% endif %}"
>
{% if desc.value == None %}
{{ _('not.resigned.for.the.moment') }}
{% else %}
{{ desc.value | safe }}
{% endif %}
</div>
{% endfor %}
{% endif %}
<div
id="synonymes"
class="tab-pane fade {% if taxonDescription|length == 0 %}show active{% endif %}"
>
{% if synonyme | length == 1 %}
{{ _('no.synonym.for.this.taxon') }}
{% else %}
{% for syn in synonyme %}
{% if not syn.lb_nom == taxon.taxonSearch.lb_nom %}
{{ syn.nom_complet_html | safe }}
{% endif %}
{% if ( (not loop.last) and (not syn.lb_nom == taxon.taxonSearch.lb_nom) ) %}
|
{% endif %}
{% endfor %}
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion data/atlas/14.grant.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GRANT USAGE ON SCHEMA atlas TO my_reader_user;
GRANT SELECT ON TABLE atlas.vm_altitudes TO my_reader_user;
GRANT SELECT ON TABLE atlas.vm_communes TO my_reader_user;
GRANT SELECT ON TABLE atlas.vm_observations TO my_reader_user;
GRANT SELECT ON TABLE atlas.vm_cor_taxon_attribut TO my_reader_user;
GRANT SELECT ON TABLE atlas.vm_taxon_attribute TO my_reader_user;
GRANT SELECT ON TABLE atlas.vm_medias TO my_reader_user;
GRANT SELECT ON TABLE atlas.vm_observations TO my_reader_user;
GRANT SELECT ON TABLE atlas.vm_observations_mailles TO my_reader_user;
Expand Down
8 changes: 0 additions & 8 deletions data/atlas/9.atlas.vm_cor_taxon_attribut.sql

This file was deleted.

18 changes: 18 additions & 0 deletions data/atlas/9.atlas.vm_taxon_attribute.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Attributs TaxHub de chaque taxon
CREATE MATERIALIZED VIEW atlas.vm_taxon_attribute AS
SELECT cta.cd_ref,
ba.nom_attribut AS code,
ba.label_attribut AS title,
CASE
WHEN ba.type_attribut = 'text' AND ba.type_widget = 'select'
THEN REPLACE(cta.valeur_attribut, '&', '|')
ELSE cta.valeur_attribut
END AS "value"
FROM taxonomie.cor_taxon_attribut AS cta
JOIN taxonomie.bib_attributs AS ba
ON cta.id_attribut = ba.id_attribut
WHERE ba.nom_attribut IN ('atlas_description', 'atlas_commentaire', 'atlas_milieu', 'atlas_chorologie')
AND cta.valeur_attribut IS NOT NULL
AND cta.valeur_attribut != '' ;

CREATE UNIQUE INDEX ON atlas.vm_taxon_attribute (cd_ref, code);
2 changes: 1 addition & 1 deletion data/atlas/atlas.refresh_materialized_view_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BEGIN
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_altitudes;

REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_taxons;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_cor_taxon_attribut;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_taxon_attribute;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_search_taxon;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_medias;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_taxons_plus_observes;
Expand Down
5 changes: 4 additions & 1 deletion data/gn2/atlas_ref_taxonomie.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
CREATE SCHEMA IF NOT EXISTS taxonomie;

IMPORT FOREIGN SCHEMA taxonomie
LIMIT TO (taxonomie.taxref, taxonomie.cor_taxon_attribut, taxonomie.t_medias)
LIMIT TO (taxonomie.taxref, taxonomie.bib_attributs, taxonomie.cor_taxon_attribut, taxonomie.t_medias)
FROM SERVER geonaturedbserver INTO taxonomie ;

ALTER TABLE taxonomie.taxref OWNER TO myuser;
GRANT ALL ON TABLE taxonomie.taxref TO myuser;

ALTER TABLE taxonomie.bib_attributs OWNER TO myuser;
GRANT ALL ON TABLE taxonomie.bib_attributs TO myuser;

ALTER TABLE taxonomie.cor_taxon_attribut OWNER TO myuser;
GRANT ALL ON TABLE taxonomie.cor_taxon_attribut TO myuser;

Expand Down
63 changes: 63 additions & 0 deletions data/update/update_attribute.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
BEGIN;

DROP MATERIALIZED VIEW IF EXISTS atlas.vm_taxon_attribute ;

DROP FOREIGN TABLE IF EXISTS taxonomie.bib_attributs ;

DROP MATERIALIZED VIEW IF EXISTS atlas.vm_cor_taxon_attribut ;

IMPORT FOREIGN SCHEMA taxonomie
LIMIT TO (taxonomie.bib_attributs)
FROM SERVER geonaturedbserver INTO taxonomie ;

ALTER TABLE taxonomie.bib_attributs OWNER TO geonatatlas;
GRANT ALL ON TABLE taxonomie.bib_attributs TO geonatatlas;

CREATE MATERIALIZED VIEW atlas.vm_taxon_attribute AS
SELECT cta.cd_ref,
ba.nom_attribut AS code,
ba.label_attribut AS title,
CASE
WHEN ba.type_attribut = 'text' AND ba.type_widget = 'select'
THEN REPLACE(cta.valeur_attribut, '&', '|')
ELSE cta.valeur_attribut
END AS "value"
FROM taxonomie.cor_taxon_attribut AS cta
JOIN taxonomie.bib_attributs AS ba
ON cta.id_attribut = ba.id_attribut
WHERE ba.nom_attribut IN ('atlas_description', 'atlas_commentaire', 'atlas_milieu', 'atlas_chorologie')
AND cta.valeur_attribut IS NOT NULL
AND cta.valeur_attribut != '' ;

CREATE UNIQUE INDEX ON atlas.vm_taxon_attribute (cd_ref, code);


ALTER MATERIALIZED VIEW atlas.vm_taxon_attribute OWNER TO geonatatlas;
GRANT SELECT ON TABLE atlas.vm_taxon_attribute TO geonatatlas;


CREATE OR REPLACE FUNCTION atlas.refresh_materialized_view_data()
RETURNS VOID AS $$
BEGIN

REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_observations;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_observations_mailles;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_mois;

REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_altitudes;

REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_taxons;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_taxon_attribute;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_search_taxon;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_medias;
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_taxons_plus_observes;

END
$$ LANGUAGE plpgsql;


-- TODO: adapt taxonomie.bib_attributs owner if it's not default "geonatatlas"
-- TOOD: adapt if necessary "ba.nom_attribut IN ('atlas_description', 'atlas_commentaire', 'atlas_milieu', 'atlas_chorologie')"


COMMIT;
4 changes: 2 additions & 2 deletions docs/vues_materialisees_maj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Les champs de cette table sont ``cd_nom``, ``id_statut``, ``id_habitat``, ``id_r

- ``atlas.vm_medias`` qui renvoie tous les médias des taxons, sur la base du schéma ``taxonomie`` de TaxHub

- ``atlas.vm_cor_taxon_attribut`` qui renvoie les 4 descriptions des taxons (description, commentaire, milieux, chorologie, sur la base du schéma ``taxonomie`` de TaxHub
- ``atlas.vm_taxon_attribute`` qui renvoie les attributs TaxHub des taxons. Par défaut : description, commentaire, milieux, chorologie, sur la base du schéma ``taxonomie`` de TaxHub.

- ``atlas.vm_observations_mailles`` qui renvoie la liste de toute les observations agrégées par maille.

Expand Down Expand Up @@ -159,6 +159,6 @@ Ajouter la ligne suivante en prenant soin de mettre à jour les paramètres de c

Pour enregistrer et sortir : ``Ctrl + O``, ENTER puis ``Ctrl + X``

Cette fonction rafraichit toutes les vues materialisées présentes dans le schéma ``atlas`` et ne tient pas compte de l'ordre du rafraichissement. Cette opération peut-être assez longue dans le cas où le réferentiel géographique est volumineux alors que celui-ci est relativement stable (peu de MAJ des communes ou du territoire).
Cette fonction rafraichit toutes les vues materialisées présentes dans le schéma ``atlas`` et ne tient pas compte de l'ordre du rafraichissement. Cette opération peut-être assez longue dans le cas où le réferentiel géographique est volumineux alors que celui-ci est relativement stable (peu de MAJ des communes ou du territoire).

Dans ce cas, préferez un rafraichisement automatique uniquement des données : fonction ``atlas.refresh_materialized_view_data()``. Pour rafraichir les données géographiques, lancer ponctuellement la fonction ``atlas.refresh_materialized_view_ref_geo()``.
Loading