Skip to content

Commit

Permalink
feat: change 'commune' to 'area' to have different 'geometry' page (P…
Browse files Browse the repository at this point in the history
  • Loading branch information
juggler31 committed Jan 16, 2025
1 parent 83ba84f commit 6b270b2
Show file tree
Hide file tree
Showing 51 changed files with 439 additions and 553 deletions.
24 changes: 12 additions & 12 deletions atlas/atlasAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
vmObservationsRepository,
vmObservationsMaillesRepository,
vmMedias,
vmCommunesRepository,
tAreasRepository,
)
from atlas.env import cache, db

Expand All @@ -25,12 +25,12 @@ def searchTaxonAPI():
return jsonify(results)


@api.route("/searchCommune", methods=["GET"])
def searchCommuneAPI():
@api.route("/searchArea", methods=["GET"])
def searchAreaAPI():
session = db.session
search = request.args.get("search", "")
limit = request.args.get("limit", 50)
results = vmCommunesRepository.searchMunicipalities(session, search, limit)
results = tAreasRepository.searchMunicipalities(session, search, limit)
session.close()
return jsonify(results)

Expand Down Expand Up @@ -110,21 +110,21 @@ def getObservationsGenericApi(cd_ref: int):

if not current_app.config["AFFICHAGE_MAILLE"]:

@api.route("/observations/<insee>/<int(signed=True):cd_ref>", methods=["GET"])
def getObservationsCommuneTaxonAPI(insee, cd_ref):
@api.route("/observations/<id_area>/<int(signed=True):cd_ref>", methods=["GET"])
def getObservationsAreaTaxonAPI(id_area, cd_ref):
connection = db.engine.connect()
observations = vmObservationsRepository.getObservationTaxonCommune(
connection, insee, cd_ref
observations = vmObservationsRepository.getObservationTaxonArea(
connection, id_area, cd_ref
)
connection.close()
return jsonify(observations)


@api.route("/observationsMaille/<insee>/<int(signed=True):cd_ref>", methods=["GET"])
def getObservationsCommuneTaxonMailleAPI(insee, cd_ref):
@api.route("/observationsMaille/<id_area>/<int(signed=True):cd_ref>", methods=["GET"])
def getObservationsAreaTaxonMailleAPI(id_area, cd_ref):
connection = db.engine.connect()
observations = vmObservationsMaillesRepository.getObservationsTaxonCommuneMaille(
connection, insee, cd_ref
observations = vmObservationsMaillesRepository.getObservationsTaxonAreaMaille(
connection, id_area, cd_ref
)
connection.close()
return jsonify(observations)
Expand Down
43 changes: 20 additions & 23 deletions atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

from atlas.env import db
from atlas import utils
from atlas.modeles.entities import vmTaxons, vmCommunes
from atlas.modeles.entities import vmTaxons, vmAreas
from atlas.modeles.repositories import (
vmOrganismsRepository,
vmTaxonsRepository,
vmObservationsRepository,
vmAltitudesRepository,
vmMoisRepository,
vmTaxrefRepository,
vmCommunesRepository,
tAreasRepository,
vmObservationsMaillesRepository,
vmMedias,
vmCorTaxonAttribut,
Expand Down Expand Up @@ -125,9 +125,9 @@ def ficheOrganism(id_organism):


@main.route(
"/commune/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>", methods=["GET", "POST"]
"/area/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>", methods=["GET", "POST"]
)
def communeMedias(image):
def areaMedias(image):
return redirect(
current_app.config["REMOTE_MEDIAS_URL"] + current_app.config["REMOTE_MEDIAS_PATH"] + image
)
Expand Down Expand Up @@ -227,13 +227,12 @@ def ficheEspece(cd_nom):
# Redirect to cd_ref if cd_nom is a synonym. Redirection is better for SEO.
if cd_ref != cd_nom:
return redirect(url_for(request.endpoint, cd_nom=cd_ref))

# Get data to render template
taxon = vmTaxrefRepository.searchEspece(connection, cd_ref)
altitudes = vmAltitudesRepository.getAltitudesChilds(connection, cd_ref)
months = vmMoisRepository.getMonthlyObservationsChilds(connection, cd_ref)
synonyme = vmTaxrefRepository.getSynonymy(connection, cd_ref)
communes = vmCommunesRepository.getCommunesObservationsChilds(connection, cd_ref)
areas = tAreasRepository.getAreasObservationsChilds(connection, cd_ref)
taxonomyHierarchy = vmTaxrefRepository.getAllTaxonomy(db_session, cd_ref)
firstPhoto = vmMedias.getFirstPhoto(connection, cd_ref, current_app.config["ATTR_MAIN_PHOTO"])
photoCarousel = vmMedias.getPhotoCarousel(
Expand Down Expand Up @@ -275,7 +274,7 @@ def ficheEspece(cd_nom):
altitudes=altitudes,
months=months,
synonyme=synonyme,
communes=communes,
areas=areas,
taxonomyHierarchy=taxonomyHierarchy,
firstPhoto=firstPhoto,
photoCarousel=photoCarousel,
Expand All @@ -287,39 +286,39 @@ def ficheEspece(cd_nom):
)


@main.route("/commune/<insee>", methods=["GET", "POST"])
def ficheCommune(insee):
@main.route("/area/<id_area>", methods=["GET", "POST"])
def ficheArea(id_area):
session = db.session
connection = db.engine.connect()

listTaxons = vmTaxonsRepository.getTaxonsCommunes(connection, insee)
commune = vmCommunesRepository.getCommuneFromInsee(connection, insee)
listTaxons = vmTaxonsRepository.getTaxonsAreas(connection, id_area)

area = tAreasRepository.getAreaFromIdArea(connection, id_area)
if current_app.config["AFFICHAGE_MAILLE"]:
observations = vmObservationsMaillesRepository.lastObservationsCommuneMaille(
connection, current_app.config["NB_LAST_OBS"], str(insee)
observations = vmObservationsMaillesRepository.lastObservationsAreaMaille(
connection, current_app.config["NB_LAST_OBS"], str(id_area)
)
else:
observations = vmObservationsRepository.lastObservationsCommune(
connection, current_app.config["NB_LAST_OBS"], insee
observations = vmObservationsRepository.lastObservationsArea(
connection, current_app.config["NB_LAST_OBS"], id_area
)

surroundingAreas = []

observers = vmObservationsRepository.getObserversCommunes(connection, insee)
observers = vmObservationsRepository.getObserversArea(connection, id_area)

session.close()
connection.close()

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


Expand Down Expand Up @@ -419,11 +418,9 @@ def sitemap():
modified_time = ten_days_ago
pages.append([url, modified_time])

municipalities = (
session.query(vmCommunes.VmCommunes).order_by(vmCommunes.VmCommunes.insee).all()
)
municipalities = session.query(vmAreas.VmAreas).order_by(vmAreas.VmAreas.id_area).all()
for municipalitie in municipalities:
url = url_root + url_for("main.ficheCommune", insee=municipalitie.insee)
url = url_root + url_for("main.ficheArea", id_area=municipalitie.id_area)
modified_time = ten_days_ago
pages.append([url, modified_time])

Expand Down
4 changes: 2 additions & 2 deletions atlas/configuration/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ NB_DAY_LAST_OBS = '7'
# Texte à afficher pour décrire la cartographie des 'dernières observations'
TEXT_LAST_OBS = 'Les observations des agents ces 7 derniers jours |'

# Carte de la fiche commune : nombre des 'x' dernières observations affichées
# Carte de la fiche "area" : nombre des 'x' dernières observations affichées
NB_LAST_OBS=100

###########################
Expand Down Expand Up @@ -237,7 +237,7 @@ ATTR_VIMEO = 9
SPLIT_NOM_VERN = True

############################################
#### FICHE COMMUNE ET RANG TAXONOMIQUE #####
#### FICHE "AREA" ET RANG TAXONOMIQUE #####
############################################

# Permet d'afficher ou non les colonnes Protection et/ou Patrimonialité/Enjeux dans les listes de taxons
Expand Down
15 changes: 5 additions & 10 deletions atlas/configuration/settings.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,13 @@ type_territoire="'PEC'"

########### Si ref_geo = False #############

#### COMMUNES ####
#### AREA ####

# Creer la table des communes à partir d'un shapefile ?
# Si false, modifiez la creation de 'atlas.vm_communes' dans data/atlas/atlas.vm_communes.sql
# PARAMETRE OBSOLETE OBLIGATOIRE SI PAS DE REF_GEO
# import_commune_shp=true

# Chemin et nom des colonnes du SHP des communes du territoire. Laisser tel quel (en modifiant uniquement MYUSERLINUX)
# pour utiliser les communes du PnEcrins par défaut
communes_shp=/home/`whoami`/atlas/data/ref/communes.shp
# Chemin et nom des colonnes du SHP des zones du territoire. Laisser tel quel (en modifiant uniquement MYUSERLINUX)
# pour utiliser les zones du PnEcrins par défaut
zones_shp=/home/`whoami`/atlas/data/ref/zones.shp
colonne_insee=insee
colonne_nom_commune=nom_com
colonne_nom_zone=nom_com

#### TERRITOIRE ####

Expand Down
Loading

0 comments on commit 6b270b2

Please sign in to comment.