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/extended-areas #446

Open
wants to merge 30 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
15c6187
fix(model): removed relationships and mapper arg
Oct 11, 2022
6452c21
feat(repo): add functions & improved existing
Oct 11, 2022
22f1e4a
feat(api): add more routes to be used by html
Oct 11, 2022
f342e04
feat(api): add area_sheet route
Oct 11, 2022
b70e0fd
chore(api): removed finally unused route
Oct 11, 2022
fd3f775
fix(config): add ExtendedAreas parameter
Oct 11, 2022
974706c
feat(front): implemented search for extended areas
Oct 11, 2022
f252555
feat(sql): remove call for cor_area_observation
Oct 11, 2022
87fbcc8
feat: add geostats (config, route, html, js)
Oct 11, 2022
d3fb087
style: add translations
Oct 11, 2022
db9f4a3
feat: add area.sample page to display areas
Oct 11, 2022
c32b5af
chore: add area.html to gitignore
Oct 12, 2022
a63eb44
feat: add surrounding area support to areasheet
Oct 12, 2022
ee64457
feat: restrict area codes & taxon list interact
Oct 12, 2022
7a2830f
feat(db): filter out vm_l_areas with intersection
Oct 12, 2022
87b9ff6
feat(install): add call to .sql in install.sh
Oct 12, 2022
302bbcd
chore: docstrings, comment & removed useless code
Oct 12, 2022
fe3c2f9
fix: Sqlalchemy warning by adding another join
Oct 12, 2022
375e855
fix(api): add type_code support for /area/geom
Oct 12, 2022
df5b79a
fix: remove POST possibility for /area
Oct 12, 2022
ab0efb2
feat: add filter on area_code + refact
Oct 12, 2022
2d14276
fix: make picto work
Oct 12, 2022
bcf8894
style: apply black on vmAreasRepository.py
Oct 12, 2022
058469c
fix(sql): mispell & select from observation in mv
Nov 14, 2022
f336ca3
fix(api): forgot id_area in and_ filter
Nov 14, 2022
18c0932
fix(api): really filter by type code in searcharea
Nov 14, 2022
52a8344
style: add id for css and change badge class
Nov 15, 2022
710effa
feat: orderby geometries in query
Nov 15, 2022
ee7192c
feat(sql): move sql scripts to their right place
Nov 17, 2022
a346313
fix: add if for areaCode since it can be none
Nov 28, 2022
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 @@ -39,6 +39,7 @@ atlas/static/custom/templates/footer.html
atlas/static/custom/templates/introduction.html
atlas/static/custom/templates/credits.html
atlas/static/custom/templates/mentions-legales.html
atlas/static/custom/templates/areas.html

data/ref/emprise_territoire.*
data/ref/communes.dbf
Expand Down
64 changes: 51 additions & 13 deletions atlas/atlasAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
vmObservationsMaillesRepository,
vmMedias,
vmCommunesRepository,
vmAreasRepository,
)

api = Blueprint("api", __name__)
Expand All @@ -33,6 +34,41 @@ def searchCommuneAPI():
session.close()
return jsonify(results)


@api.route("/area", methods=["GET"])
def search_area():
"""
Enables to filter areas on their name or code
"""
session = utils.loadSession()
search = request.args.get("search")
type_code = request.args.get("type")
limit = request.args.get("limit", 50)
results = vmAreasRepository.search_area_by_type(session=session,
search=search,
type_code=type_code,
filter_type_codes=current_app.config['AREAS_LIST'],
limit=limit)
session.close()
return jsonify(results)


@api.route("/area/geom", methods=["GET"])
def get_areas_geom():
"""
Returns the geometries of areas
"""
session = utils.loadSession()
limit = request.args.get("limit", 50)
type_code = request.args.get("type")
results = vmAreasRepository.get_areas_geometries(session=session,
type_code=type_code,
filter_type_codes=current_app.config['AREAS_LIST'],
limit=limit)
session.close()
return jsonify(results)


if not current_app.config['AFFICHAGE_MAILLE']:
@api.route("/observationsMailleAndPoint/<int:cd_ref>", methods=["GET"])
def getObservationsMailleAndPointAPI(cd_ref):
Expand Down Expand Up @@ -104,23 +140,25 @@ def getObservationsGenericApi(cd_ref: int):


if not current_app.config['AFFICHAGE_MAILLE']:
@api.route("/observations/<insee>/<int:cd_ref>", methods=["GET"])
def getObservationsCommuneTaxonAPI(insee, cd_ref):
connection = utils.engine.connect()
observations = vmObservationsRepository.getObservationTaxonCommune(
connection, insee, cd_ref
@api.route("/observations/<area_code>/<int:cd_ref>", methods=["GET"])
def getObservationsCommuneTaxonAPI(area_code, cd_ref):
session = utils.loadSession()
# Use generic area function to get every type of area
observations = vmAreasRepository.get_areas_observations_by_cd_ref(
session, area_code, cd_ref
)
connection.close()
session.close()
return jsonify(observations)


@api.route("/observationsMaille/<insee>/<int:cd_ref>", methods=["GET"])
def getObservationsCommuneTaxonMailleAPI(insee, cd_ref):
connection = utils.engine.connect()
observations = vmObservationsMaillesRepository.getObservationsTaxonCommuneMaille(
connection, insee, cd_ref
@api.route("/observationsMaille/<area_code>/<int:cd_ref>", methods=["GET"])
def getObservationsCommuneTaxonMailleAPI(area_code, cd_ref):
session = utils.loadSession()
# Use generic area function to get every type of area
observations = vmAreasRepository.get_areas_grid_observations_by_cd_ref(
session, area_code, cd_ref
)
connection.close()
session.close()
return jsonify(observations)


Expand Down Expand Up @@ -158,4 +196,4 @@ def test():
current_app.config["ATTR_OTHER_PHOTO"],
)
connection.close()
return jsonify(photos)
return jsonify(photos)
46 changes: 45 additions & 1 deletion atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from atlas.env import config
from atlas.modeles.entities import vmTaxons, vmCommunes
from atlas.modeles.repositories import (
vmAreasRepository,
vmOrganismsRepository,
vmTaxonsRepository,
vmObservationsRepository,
Expand Down Expand Up @@ -204,7 +205,11 @@ def index():
if current_app.config["AFFICHAGE_STAT_GLOBALES"]:
stat = vmObservationsRepository.statIndex(connection)
else:
stat = []
stat = {}

if current_app.config["GLOBAL_GEO_STATS"]:
area_types = [geo["TYPE"] for geo in current_app.config["GLOBAL_GEO_STATS"]]
stat['geo'] = vmAreasRepository.stats(session, area_types)

if current_app.config["AFFICHAGE_RANG_STAT"]:
current_app.logger.debug("start customStat")
Expand Down Expand Up @@ -352,6 +357,45 @@ def ficheCommune(insee):
)


@main.route("/area/<id_area>", methods=["GET"])
def area_sheet(id_area):
"""
Generates the AreaSheet html
"""
session = utils.loadSession()

listTaxons = vmAreasRepository.get_area_taxa(session, id_area=id_area)
area = vmAreasRepository.get_area_from_id(session, id_area=id_area)
if current_app.config["AFFICHAGE_MAILLE"]:
observations = vmAreasRepository.last_observations_area_maille(
session, current_app.config["NB_LAST_OBS"], id_area
)
else:
observations = vmAreasRepository.get_areas_observations(
session, current_app.config["NB_LAST_OBS"], id_area
)

surroundingAreas = vmAreasRepository.get_surrounding_areas(session=session,
id_area=id_area,
filter_type_codes=current_app.config['AREAS_LIST'])

observers = vmAreasRepository.get_observers_area(session, id_area=id_area)

session.close()

return render_template(
"templates/areaSheet/_main.html",
sheetType="area",
surroundingAreas=surroundingAreas,
listTaxons=listTaxons,
areaInfos=area,
observations=observations,
observers=observers,
DISPLAY_EYE_ON_LIST=True,
insee=id_area,
)


@main.route("/liste/<cd_ref>", methods=["GET", "POST"])
def ficheRangTaxonomie(cd_ref):
session = utils.loadSession()
Expand Down
10 changes: 10 additions & 0 deletions atlas/configuration/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class MapConfig(Schema):
load_default={"fill": False, "fillColor": "#020202", "fillOpacity": 0.3}
)

class GeoStat(Schema):
NAME = fields.String()
TYPE = fields.String()
PICTO = fields.String()


class AtlasConfig(Schema):
class Meta:
Expand All @@ -131,6 +136,7 @@ class Meta:
AFFICHAGE_LOGOS_HOME = fields.Boolean(load_default=True)
AFFICHAGE_FOOTER = fields.Boolean(load_default=True)
AFFICHAGE_STAT_GLOBALES = fields.Boolean(load_default=True)
GLOBAL_GEO_STATS = fields.List(fields.Nested(GeoStat), load_default=[])
AFFICHAGE_DERNIERES_OBS = fields.Boolean(load_default=True)
AFFICHAGE_EN_CE_MOMENT = fields.Boolean(load_default=True)
AFFICHAGE_RANG_STAT = fields.Boolean(load_default=True)
Expand Down Expand Up @@ -209,6 +215,10 @@ class Meta:
# (no need to restart the atlas service when updating templates)
# Defaults to False to have the best performance in production
TEMPLATES_AUTO_RELOAD = fields.Boolean(load_default=False)
# Enable the search on other areas
EXTENDED_AREAS = fields.Boolean(load_default=False)
# Restricts the search (/area) and the /area/geom API
AREAS_LIST = fields.List(fields.String, load_default=[])

@validates_schema
def validate_url_taxhub(self, data, **kwargs):
Expand Down
34 changes: 21 additions & 13 deletions atlas/messages.pot
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Translations template for PROJECT.
# Copyright (C) 2021 ORGANIZATION
# Copyright (C) 2022 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2021.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2022.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2021-12-02 15:28+0100\n"
"POT-Creation-Date: 2022-10-11 15:29+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -164,10 +164,14 @@ msgstr ""
msgid "check.species.sheet"
msgstr ""

#: templates/core/extended_areas_search.html:13
#: templates/core/extended_areas_search.html:12
msgid "search.other.zones.type"
msgstr ""

#: templates/core/extended_areas_search.html:23
msgid "search"
msgstr ""

#: templates/core/listTaxons.html:14
msgid "filter.species"
msgstr ""
Expand Down Expand Up @@ -201,25 +205,25 @@ msgstr ""
msgid "loading"
msgstr ""

#: templates/core/navbar.html:34 templates/home/globalStats.html:28
#: templates/core/navbar.html:34 templates/home/globalStats.html:30
#: templates/photoGalery/_main.html:76
msgid "search.species"
msgstr ""

#: templates/core/navbar.html:47 templates/home/globalStats.html:47
#: templates/core/navbar.html:47 templates/home/globalStats.html:49
msgid "search.city"
msgstr ""

#: templates/core/sideBar.html:3
msgid "back.to.home"
msgstr ""

#: templates/core/sideBar.html:25 templates/home/globalStats.html:59
#: templates/core/sideBar.html:25 templates/home/globalStats.html:61
#: templates/photoGalery/_main.html:5 templates/photoGalery/_main.html:50
msgid "gallery.title"
msgstr ""

#: templates/core/statHierarchy.html:12 templates/home/globalStats.html:21
#: templates/core/statHierarchy.html:12 templates/home/globalStats.html:23
#: templates/home/taxoRank.html:28 templates/organismSheet/statsInfos.html:21
msgid "species"
msgstr ""
Expand Down Expand Up @@ -268,31 +272,35 @@ msgstr ""
msgid "display.city.infos"
msgstr ""

#: templates/home/geoStats.html:22
msgid "search.for"
msgstr ""

#: templates/home/globalStats.html:4
msgid "home.insomefigures"
msgstr ""

#: templates/home/globalStats.html:13
#: templates/home/globalStats.html:14
msgid "home.seelatestobs"
msgstr ""

#: templates/home/globalStats.html:39 templates/speciesSheet/map.html:20
#: templates/home/globalStats.html:41 templates/speciesSheet/map.html:20
#: templates/speciesSheet/otherInformations.html:10
#: templates/speciesSheet/otherInformations.html:14
msgid "municipalities"
msgstr ""

#: templates/home/globalStats.html:39 templates/speciesSheet/map.html:20
#: templates/home/globalStats.html:41 templates/speciesSheet/map.html:20
#: templates/speciesSheet/otherInformations.html:10
#: templates/speciesSheet/otherInformations.html:14
msgid "municipality"
msgstr ""

#: templates/home/globalStats.html:58
#: templates/home/globalStats.html:60
msgid "photos"
msgstr ""

#: templates/home/globalStats.html:58
#: templates/home/globalStats.html:60
msgid "photo"
msgstr ""

Expand Down
9 changes: 2 additions & 7 deletions atlas/modeles/entities/vmAreas.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,11 @@ class VmCorAreaObservation(Base):
__table__ = Table(
"vm_cor_area_observation",
metadata,
Column("id_observation", Integer()),
Column("id_observation", Integer(), primary_key=True),
Column("id_area", Integer()),
schema="atlas",
autoload=True,
autoload_with=engine,
extend_existing=True,
primary_key=False,
)
__mapper_args__ = {"primary_key": [__table__.c.id_observation, __table__.c.id_area]}
observation = relationship(
"VmObservations", foreign_keys=[__table__.c.id_observation]
)
area = relationship("VmAreas", foreign_keys=[__table__.c.id_area])

Loading