Skip to content

Commit

Permalink
Feat speciesSheet: custom attributes for infos bloc
Browse files Browse the repository at this point in the history
Close #412.
  • Loading branch information
jpm-cbna committed Apr 26, 2022
1 parent d2962b5 commit 2c35e81
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 148 deletions.
5 changes: 1 addition & 4 deletions atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,7 @@ def ficheEspece(cd_ref):
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 @@ -202,11 +202,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
21 changes: 7 additions & 14 deletions atlas/configuration/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@ class Meta:
modeDebug = fields.Boolean(load_default=False)
SECRET_KEY = fields.String(required=True)


class MapConfig(Schema):
LAT_LONG = fields.List(fields.Float(), load_default=[44.7952, 6.2287])
MIN_ZOOM = fields.Integer(load_default=1)
MAX_BOUNDS = fields.List(
fields.List(fields.Float()), load_default=[[-180, -90], [180, 90]]
)
MAX_BOUNDS = fields.List(fields.List(fields.Float()), load_default=[[-180, -90], [180, 90]])
FIRST_MAP = fields.Dict(load_default=MAP_1)
SECOND_MAP = fields.Dict(load_default=MAP_2)
ZOOM = fields.Integer(load_default=10)
Expand Down Expand Up @@ -154,10 +151,10 @@ 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 Expand Up @@ -196,9 +193,7 @@ class Meta:
LIMIT_CLUSTER_POINT = fields.Integer(load_default=1000)
NB_DAY_LAST_OBS = fields.String(load_default="7")
NB_LAST_OBS = fields.Integer(load_default=100)
TEXT_LAST_OBS = fields.String(
load_default="Les observations des agents ces 7 derniers jours |"
)
TEXT_LAST_OBS = fields.String(load_default="Les observations des agents ces 7 derniers jours |")
ANONYMIZE = fields.Boolean(load_default=False)
MAP = fields.Nested(MapConfig, load_default=dict())
# coupe le nom_vernaculaire à la 1ere virgule sur les fiches espèces
Expand All @@ -213,7 +208,5 @@ def validate_url_taxhub(self, data, **kwargs):
"""
if data["REDIMENSIONNEMENT_IMAGE"] and data["TAXHUB_URL"] is None:
raise ValidationError(
{
"Le champ TAXHUB_URL doit être rempli si REDIMENSIONNEMENT_IMAGE = True"
}
{"Le champ TAXHUB_URL doit être rempli si REDIMENSIONNEMENT_IMAGE = True"}
)
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
39 changes: 9 additions & 30 deletions atlas/modeles/repositories/vmCorTaxonAttribut.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +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 @@ -30,7 +30,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
4 changes: 2 additions & 2 deletions data/atlas/atlas.vm_refresh.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ 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;

END
$$ LANGUAGE plpgsql;
$$ LANGUAGE plpgsql;
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
Loading

0 comments on commit 2c35e81

Please sign in to comment.