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 25, 2022
1 parent d2962b5 commit ee72c77
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 129 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"}
)
9 changes: 4 additions & 5 deletions atlas/configuration/settings.ini.sample
Original file line number Diff line number Diff line change
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 DESCRIVANT 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
116 changes: 55 additions & 61 deletions atlas/templates/speciesSheet/blocInfos.html
Original file line number Diff line number Diff line change
@@ -1,67 +1,61 @@
{% 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" 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 show {% if loop.index == 1 %}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 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 %}
26 changes: 18 additions & 8 deletions data/atlas/9.atlas.vm_cor_taxon_attribut.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
-- Attributs de chaque taxon (description, commentaire, milieu et chorologie)
CREATE MATERIALIZED VIEW atlas.vm_cor_taxon_attribut AS
SELECT id_attribut,
valeur_attribut,
cd_ref
FROM taxonomie.cor_taxon_attribut
WHERE id_attribut IN (100, 101, 102, 103);
CREATE UNIQUE INDEX ON atlas.vm_cor_taxon_attribut (cd_ref,id_attribut);
-- 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);
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
37 changes: 37 additions & 0 deletions data/update/update_attribute.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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);

-- 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;
2 changes: 1 addition & 1 deletion install_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ if ! database_exists $db_name

echo "[$(date +'%H:%M:%S')] Creating atlas.vm_cor_taxon_attribut..."
time_temp=$SECONDS
sudo sed -i "s/WHERE id_attribut IN (100, 101, 102, 103);$/WHERE id_attribut IN ($attr_desc, $attr_commentaire, $attr_milieu, $attr_chorologie);/" /tmp/atlas/9.atlas.vm_cor_taxon_attribut.sql
sudo sed -i "s/WHERE id_attribut IN ('atlas_description', 'atlas_commentaire', 'atlas_milieu', 'atlas_chorologie')$/WHERE id_attribut IN ($displayed_attr);/" /tmp/atlas/9.atlas.vm_cor_taxon_attribut.sql
export PGPASSWORD=$owner_atlas_pass;psql -d $db_name -U $owner_atlas -h $db_host -f /tmp/atlas/9.atlas.vm_cor_taxon_attribut.sql &>> log/install_db.log
echo "[$(date +'%H:%M:%S')] Passed - Duration : $((($SECONDS-$time_temp)/60))m$((($SECONDS-$time_temp)%60))s"

Expand Down

0 comments on commit ee72c77

Please sign in to comment.