Skip to content

Commit

Permalink
Merge branch 'develop' into fix/js-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jpm-cbna authored May 20, 2024
2 parents 4beebfe + d13d535 commit 41c04cc
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 116 deletions.
12 changes: 6 additions & 6 deletions atlas/atlasAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def getObservationsMailleAndPointAPI(cd_ref):


@api.route("/observationsMaille/<int:cd_ref>", methods=["GET"])
def getObservationsMailleAPI(cd_ref, year_min=None, year_max=None):
def getObservationsMailleAPI(cd_ref):
"""
Retourne les observations d'un taxon par maille (et le nombre d'observation par maille)
Expand Down Expand Up @@ -94,17 +94,17 @@ def getObservationsGenericApi(cd_ref: int):
[type]: [description]
"""
session = db.session
observations = (
vmObservationsMaillesRepository.getObservationsMaillesChilds(
if current_app.config["AFFICHAGE_MAILLE"]:
observations = vmObservationsMaillesRepository.getObservationsMaillesChilds(
session,
cd_ref,
year_min=request.args.get("year_min"),
year_max=request.args.get("year_max"),
)
if current_app.config["AFFICHAGE_MAILLE"]
else vmObservationsRepository.searchObservationsChilds(session, cd_ref)
)
else:
observations = vmObservationsRepository.searchObservationsChilds(session, cd_ref)
session.close()

return jsonify(observations)


Expand Down
22 changes: 22 additions & 0 deletions atlas/modeles/entities/tMaillesTerritoire.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# coding: utf-8
from geoalchemy2.types import Geometry
from sqlalchemy import Column, Integer, MetaData, Table, Text
from sqlalchemy.ext.declarative import declarative_base

from atlas.env import db

metadata = MetaData()
Base = declarative_base()


class TMaillesTerritoire(Base):
__table__ = Table(
"t_mailles_territoire",
metadata,
Column("id_maille", Integer, primary_key=True, unique=True),
Column("the_geom", Geometry()),
Column("geojson_maille", Text),
schema="atlas",
autoload=True,
autoload_with=db.engine,
)
9 changes: 4 additions & 5 deletions atlas/modeles/entities/vmObservations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ class VmObservationsMailles(Base):
__table__ = Table(
"vm_observations_mailles",
metadata,
Column("id_observation", Integer, primary_key=True, unique=True),
Column("id_maille", Integer),
Column("the_geom", Geometry),
Column("geojson_maille", Text),
Column("annee", String(1000)),
Column("cd_ref", Integer, primary_key=True, index=True),
Column("annee", String(1000), primary_key=True, index=True),
Column("id_maille", Integer, primary_key=True, index=True),
Column("nbr", Integer),
schema="atlas",
autoload=True,
autoload_with=db.engine,
Expand Down
29 changes: 19 additions & 10 deletions atlas/modeles/repositories/vmObservationsMaillesRepository.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json

from geojson import Feature, FeatureCollection
from sqlalchemy.sql import text, func, or_
from sqlalchemy.sql import text, func, any_

from atlas.modeles.entities.vmObservations import VmObservationsMailles
from atlas.modeles.entities.tMaillesTerritoire import TMaillesTerritoire
from atlas.modeles.utils import deleteAccent, findPath


Expand All @@ -12,17 +13,25 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
Retourne les mailles et le nombre d'observation par maille pour un taxon et ses enfants
sous forme d'un geojson
"""
subquery = session.query(func.atlas.find_all_taxons_childs(cd_ref))
query = func.atlas.find_all_taxons_childs(cd_ref)
taxons_ids = session.scalars(query).all()
taxons_ids.append(cd_ref)

query = (
session.query(
func.count(VmObservationsMailles.id_observation).label("nb_obs"),
func.max(VmObservationsMailles.annee).label("last_observation"),
VmObservationsMailles.id_maille,
VmObservationsMailles.geojson_maille,
TMaillesTerritoire.geojson_maille,
func.max(VmObservationsMailles.annee).label("last_obs_year"),
func.sum(VmObservationsMailles.nbr).label("obs_nbr"),
)
.join(
TMaillesTerritoire,
TMaillesTerritoire.id_maille == VmObservationsMailles.id_maille,
)
.group_by(VmObservationsMailles.id_maille, VmObservationsMailles.geojson_maille)
.filter(
or_(VmObservationsMailles.cd_ref.in_(subquery), VmObservationsMailles.cd_ref == cd_ref)
.filter(VmObservationsMailles.cd_ref == any_(taxons_ids))
.group_by(
VmObservationsMailles.id_maille,
TMaillesTerritoire.geojson_maille,
)
)
if year_min and year_max:
Expand All @@ -35,8 +44,8 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
geometry=json.loads(o.geojson_maille),
properties={
"id_maille": o.id_maille,
"nb_observations": o.nb_obs,
"last_observation": o.last_observation,
"nb_observations": int(o.obs_nbr),
"last_observation": o.last_obs_year,
},
)
for o in query.all()
Expand Down
52 changes: 29 additions & 23 deletions atlas/modeles/repositories/vmTaxrefRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,34 @@ def searchEspece(connection, cd_ref):
"""
recherche l espece corespondant au cd_nom et tout ces fils
"""
sql = """
query = """
WITH limit_obs AS (
SELECT
:thiscdref AS cd_ref, min(yearmin) AS yearmin,
max(yearmax) AS yearmax, SUM(nb_obs) AS nb_obs
:cdRef AS cd_ref,
MIN(yearmin) AS yearmin,
MAX(yearmax) AS yearmax,
SUM(nb_obs) AS nb_obs
FROM atlas.vm_taxons
WHERE
cd_ref IN (SELECT * FROM atlas.find_all_taxons_childs(:thiscdref))
OR cd_ref = :thiscdref
WHERE cd_ref IN (SELECT * FROM atlas.find_all_taxons_childs(:cdRef))
OR cd_ref = :cdRef
)
SELECT taxref.*,
l.cd_ref, l.yearmin, l.yearmax, COALESCE(l.nb_obs, 0) AS nb_obs,
t2.patrimonial, t2.protection_stricte
FROM atlas.vm_taxref taxref
JOIN limit_obs l
ON l.cd_ref = taxref.cd_nom
LEFT JOIN atlas.vm_taxons t2
ON t2.cd_ref = taxref.cd_ref
WHERE taxref.cd_nom = :thiscdref
l.cd_ref,
l.yearmin,
l.yearmax,
COALESCE(l.nb_obs, 0) AS nb_obs,
t2.patrimonial,
t2.protection_stricte
FROM atlas.vm_taxref AS taxref
JOIN limit_obs AS l
ON l.cd_ref = taxref.cd_nom
LEFT JOIN atlas.vm_taxons AS t2
ON t2.cd_ref = taxref.cd_ref
WHERE taxref.cd_nom = :cdRef
"""
req = connection.execute(text(sql), thiscdref=cd_ref)
results = connection.execute(text(query), cdRef=cd_ref)
taxonSearch = dict()
for r in req:
for r in results:
nom_vern = None
if r.nom_vern:
nom_vern = (
Expand All @@ -54,7 +59,7 @@ def searchEspece(connection, cd_ref):
"protection": r.protection_stricte,
}

sql = """
query = """
SELECT
tax.lb_nom,
tax.nom_vern,
Expand All @@ -64,16 +69,17 @@ def searchEspece(connection, cd_ref):
tax.patrimonial,
tax.protection_stricte,
tax.nb_obs
FROM atlas.vm_taxons tax
JOIN atlas.bib_taxref_rangs br
ON br.id_rang = tax.id_rang
FROM atlas.vm_taxons AS tax
JOIN atlas.bib_taxref_rangs AS br
ON br.id_rang = tax.id_rang
WHERE tax.cd_ref IN (
SELECT * FROM atlas.find_all_taxons_childs(:thiscdref)
SELECT * FROM atlas.find_all_taxons_childs(:cdRef)
)
ORDER BY tax.lb_nom ASC, tax.nb_obs DESC
"""
req = connection.execute(text(sql), thiscdref=cd_ref)
results = connection.execute(text(query), cdRef=cd_ref)
listTaxonsChild = list()
for r in req:
for r in results:
temp = {
"lb_nom": r.lb_nom,
"nom_vern": r.nom_vern,
Expand Down
5 changes: 0 additions & 5 deletions atlas/static/mapAreas.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ function displayObsTaxonMaille(areaCode, cd_ref) {
dataType: "json",
beforeSend: function () {
$("#loaderSpinner").show();
// $("#loadingGif").show();
// $("#loadingGif").attr(
// "src",
// configuration.URL_APPLICATION + "/static/images/loading.svg"
// );
}
}).done(function (observations) {
$("#loaderSpinner").hide();
Expand Down
4 changes: 3 additions & 1 deletion atlas/static/mapGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ function displayGridLayerArea(observations) {
style: styleMaille,
});
currentLayer.addTo(map);
map.fitBounds(currentLayer.getBounds());
if (currentLayer.getBounds().isValid()) {
map.fitBounds(currentLayer.getBounds());
}

// ajout de la légende
generateLegendMaille();
Expand Down
22 changes: 16 additions & 6 deletions atlas/templates/core/sideBar.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
</a>
{% for page_key, page_values in configuration.STATIC_PAGES.items()|sort(attribute='1.order') %}
{% if 'url' in page_values %}
<a href="{{ page_values.url }}" target="_blank" data-toggle="tooltip"
data-original-title="{{ page_values.title }}" data-placement="right">
<li class="sidebar-brand"><span class="fas {{ page_values.picto }}"></span></li>
<a href="{{ page_values.url }}" target="_blank" data-toggle="tooltip" data-original-title="{{ page_values.title }}" data-placement="right">
<li class="sidebar-brand">
{% if 'customized_picto' in page_values %}
<span><img src="/static/custom/images/{{ page_values.customized_picto }}" height="{{ page_values.picto_height}}"></img></span>
{% else %}
<span class="fas {{ page_values.picto }}"></span>
{% endif %}
</li>
</a>
{% else %}
<a href="{{ url_for('main.get_staticpages', page=page_key) }}" data-toggle="tooltip"
data-original-title="{{ page_values.title }}" data-placement="right">
<li class="sidebar-brand"><span class="fas {{ page_values.picto }}"></span></li>
<a href="{{ url_for('main.get_staticpages', page=page_key) }}" data-toggle="tooltip" data-original-title="{{ page_values.title }}" data-placement="right">
<li class="sidebar-brand">
{% if 'customized_picto' in page_values %}
<span><img src="/static/custom/images/{{ page_values.customized_picto }}" height="{{ page_values.picto_height}}"></img></span>
{% else %}
<span class="fas {{ page_values.picto }}"></span>
{% endif %}
</li>
</a>
{% endif %}
{% endfor %}
Expand Down
72 changes: 37 additions & 35 deletions atlas/templates/speciesSheet/identityCard.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,19 @@ <h4 class="strong"><i>{{ taxon.taxonSearch.nom_complet_html|safe }} </i></h4>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="myModalLabel">
Taxon(s) agrégé(s) sur cette fiche
</h3>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h3 class="modal-title" id="myModalLabel">Taxon(s) agrégé(s) sur cette
fiche</h3>
aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<table class="table table-hover">
<table class="table table-hover table-responsive">
<thead>
<tr>
<th> {{ _('common.name') }}</th>
Expand All @@ -136,29 +138,31 @@ <h3 class="modal-title" id="myModalLabel">Taxon(s) agrégé(s) sur cette
</thead>
<tbody>
{% for child in taxon.listTaxonsChild %}
<a href="{{ url_for('main.ficheEspece', cd_nom=child.cd_ref) }}">
<tr>
<td>
{% if child.nom_vern != None %}
{{ child.nom_vern }}
{% else %}
-
</td>
{% endif %}
<td><i>{{ child.lb_nom }}</i></td>
<tr>
<td>
{% if child.nom_vern != None %}
{{ child.nom_vern }}
{% else %}
-
{% endif %}
</td>
<td> {{ child.lb_nom }} </td>
{% if configuration.PROTECTION %}
<td>
{% if child.protection != None %}
<a href="https://inpn.mnhn.fr/espece/cd_nom/{{ taxon.taxonSearch.cd_ref }}/tab/statut"
target="_blank">
target="_blank">
<img class="caractEspece" width="130px"
src="{{ url_for('static', filename='images/logo_protection.png') }}"
data-toggle="tooltip"
data-original-title="{{ _('this.taxon.has.a.protected.status') }}"
data-placement="right"></a>
src="{{ url_for('static', filename='images/logo_protection.png') }}"
data-toggle="tooltip"
data-original-title="{{ _('this.taxon.has.a.protected.status') }}"
data-placement="right"></a>
{% endif %}
</td>
{% endif %}
{% if config.DISPLAY_PATRIMONIALITE %}
<td>
{% if config.DISPLAY_PATRIMONIALITE and child.patrimonial in configuration.PATRIMONIALITE.config %}
{% if child.patrimonial in configuration.PATRIMONIALITE.config %}
<img
class="caractEspece" width="130px"
src="{{ url_for('static', filename=configuration.PATRIMONIALITE.config[child.patrimonial].icon) }}"
Expand All @@ -168,24 +172,22 @@ <h3 class="modal-title" id="myModalLabel">Taxon(s) agrégé(s) sur cette
>
{% endif %}
</td>
<td> {{ child.nb_obs | pretty }} </td>
<td>
<a href="{{ url_for('main.ficheEspece', cd_nom=child.cd_ref) }}">
<span id="ficheGlyficon" data-toggle="tooltip"
data-original-title="{{ _('check.species.sheet')}}"
data-placement="right"
class="fas fa-list"></span>
</a>
</td>

</tr>
</a>
{% endif %}
<td> {{ child.nb_obs | pretty }} </td>
<td>
<a href="{{ url_for('main.ficheEspece', cd_nom=child.cd_ref) }}">
<span id="ficheGlyficon" data-toggle="tooltip"
data-original-title="{{ _('check.species.sheet')}}"
data-placement="right"
class="fas fa-list"></span>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>

</div>
</div>

Expand Down
Loading

0 comments on commit 41c04cc

Please sign in to comment.