Skip to content

Commit

Permalink
Merge pull request #496 from PnX-SI/feat/custom
Browse files Browse the repository at this point in the history
Feat/custom
  • Loading branch information
joelclems authored Oct 16, 2023
2 parents 386c4f9 + 230eced commit deb37ae
Show file tree
Hide file tree
Showing 33 changed files with 140 additions and 201 deletions.
3 changes: 2 additions & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# blackify everything!
c8028f48134dbf07b632c589db900bef1ba6109f
c8028f48134dbf07b632c589db900bef1ba6109f
23039577bebb442b4b90ef58184d4962e3c4e73b
4 changes: 1 addition & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ jobs:
with:
fetch-depth: 0
- name: Backend code formatting check (Black)
uses: psf/black@stable
with:
src: "setup.py ./atlas"
uses: psf/black@stable
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ atlas/static/custom/territoire.json
atlas/static/custom/glossaire.json
atlas/static/custom/custom.css
atlas/static/custom/maps-custom.js
atlas/static/custom/images/picto*.png

static/custom/territoire.json
static/custom/glossaire.json
Expand All @@ -39,6 +40,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/navbar.html

data/ref/emprise_territoire.*
data/ref/communes.dbf
Expand Down
35 changes: 17 additions & 18 deletions atlas/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
from flask_sqlalchemy import SQLAlchemy
from flask_babel import Babel, format_date, gettext, ngettext, get_locale
from werkzeug.middleware.proxy_fix import ProxyFix
from werkzeug.middleware.shared_data import SharedDataMiddleware
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from werkzeug.wrappers import Response

from atlas.configuration.config_parser import valid_config_from_dict
from atlas.configuration.config_schema import AtlasConfig, SecretSchemaConf
from atlas.env import (
atlas_static_folder,
atlas_template_folder,
atlas_config_file_path,
db,
cache,
)
from atlas.env import atlas_static_folder, atlas_template_folder, atlas_config_file_path, db, cache

compress = Compress()

Expand All @@ -24,19 +21,13 @@ def create_app():
renvoie une instance de l'app Flask
"""

app = Flask(
__name__,
template_folder=atlas_template_folder,
static_folder=atlas_static_folder,
)
app = Flask(__name__, template_folder=atlas_template_folder, static_folder=atlas_static_folder)
# push the config in app config at 'PUBLIC' key
app.config.from_pyfile(str(atlas_config_file_path))

app.config.from_prefixed_env(prefix="ATLAS")
config_valid = valid_config_from_dict(copy.copy(app.config), AtlasConfig)
config_secret_valid = valid_config_from_dict(
copy.copy(app.config), SecretSchemaConf
)
config_secret_valid = valid_config_from_dict(copy.copy(app.config), SecretSchemaConf)

app.config.update(config_valid)
app.config.update(config_secret_valid)
Expand All @@ -59,9 +50,7 @@ def get_locale():
from atlas.atlasRoutes import main as main_blueprint

if app.config["MULTILINGUAL"]:
app.register_blueprint(
main_blueprint, url_prefix="/<lang_code>", name="multi_lg"
)
app.register_blueprint(main_blueprint, url_prefix="/<lang_code>", name="multi_lg")
app.register_blueprint(main_blueprint)

from atlas.atlasAPI import api
Expand All @@ -72,6 +61,16 @@ def get_locale():
os.environ["SCRIPT_NAME"] = app.config["APPLICATION_ROOT"].rstrip("/")
app.wsgi_app = ProxyFix(app.wsgi_app, x_host=1)

app.wsgi_app = SharedDataMiddleware(
app.wsgi_app, {app.static_url_path: f"{atlas_static_folder}/custom"}
)

if app.config["APPLICATION_ROOT"] != "/":
app.wsgi_app = DispatcherMiddleware(
Response("Not Found", status=404),
{app.config["APPLICATION_ROOT"].rstrip("/"): app.wsgi_app},
)

@app.context_processor
def inject_config():
configuration = copy.copy(app.config)
Expand Down
12 changes: 3 additions & 9 deletions atlas/atlasAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def getObservationsMailleAPI(cd_ref, year_min=None, year_max=None):
@api.route("/observationsPoint/<int:cd_ref>", methods=["GET"])
def getObservationsPointAPI(cd_ref):
session = db.session
observations = vmObservationsRepository.searchObservationsChilds(
session, cd_ref
)
observations = vmObservationsRepository.searchObservationsChilds(session, cd_ref)
session.close()
return jsonify(observations)

Expand Down Expand Up @@ -149,9 +147,7 @@ def getPhotosGroup(group):
def getPhotosGallery():
connection = db.engine.connect()
photos = vmMedias.getPhotosGallery(
connection,
current_app.config["ATTR_MAIN_PHOTO"],
current_app.config["ATTR_OTHER_PHOTO"],
connection, current_app.config["ATTR_MAIN_PHOTO"], current_app.config["ATTR_OTHER_PHOTO"]
)
connection.close()
return jsonify(photos)
Expand All @@ -169,7 +165,5 @@ def main_stat():
def rank_stat():
connection = db.engine.connect()
return jsonify(
vmObservationsRepository.genericStat(
connection, current_app.config["RANG_STAT"]
)
vmObservationsRepository.genericStat(connection, current_app.config["RANG_STAT"])
)
68 changes: 17 additions & 51 deletions atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def add_language_code(endpoint, values):
def pull_lang_code(endpoint, values):
if values is not None:
# If no language code has been set, get the best language from the browser settings
default_lang = request.accept_languages.best_match(
current_app.config["LANGUAGES"]
)
default_lang = request.accept_languages.best_match(current_app.config["LANGUAGES"])
g.lang_code = values.pop("lang_code", default_lang)

@main.before_request
Expand All @@ -73,14 +71,11 @@ def redirect_default_language():


@main.route(
"/espece/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>",
methods=["GET", "POST"],
"/espece/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>", methods=["GET", "POST"]
)
def especeMedias(image):
return redirect(
current_app.config["REMOTE_MEDIAS_URL"]
+ current_app.config["REMOTE_MEDIAS_PATH"]
+ image
current_app.config["REMOTE_MEDIAS_URL"] + current_app.config["REMOTE_MEDIAS_PATH"] + image
)


Expand All @@ -106,9 +101,7 @@ def ficheOrganism(id_organism):
taxon = {**taxon, **taxon_info["taxonSearch"]}
taxon["photo"] = photo
update_most_obs_taxons.append(taxon)
stats_group = vmOrganismsRepository.getTaxonRepartitionOrganism(
connection, id_organism
)
stats_group = vmOrganismsRepository.getTaxonRepartitionOrganism(connection, id_organism)

connection.close()
db_session.close()
Expand All @@ -132,49 +125,36 @@ def ficheOrganism(id_organism):


@main.route(
"/commune/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>",
methods=["GET", "POST"],
"/commune/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>", methods=["GET", "POST"]
)
def communeMedias(image):
return redirect(
current_app.config["REMOTE_MEDIAS_URL"]
+ current_app.config["REMOTE_MEDIAS_PATH"]
+ image
current_app.config["REMOTE_MEDIAS_URL"] + current_app.config["REMOTE_MEDIAS_PATH"] + image
)


@main.route(
"/liste/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>",
methods=["GET", "POST"],
"/liste/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>", methods=["GET", "POST"]
)
def listeMedias(image):
return redirect(
current_app.config["REMOTE_MEDIAS_URL"]
+ current_app.config["REMOTE_MEDIAS_PATH"]
+ image
current_app.config["REMOTE_MEDIAS_URL"] + current_app.config["REMOTE_MEDIAS_PATH"] + image
)


@main.route(
"/groupe/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>",
methods=["GET", "POST"],
"/groupe/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>", methods=["GET", "POST"]
)
def groupeMedias(image):
return redirect(
current_app.config["REMOTE_MEDIAS_URL"]
+ current_app.config["REMOTE_MEDIAS_PATH"]
+ image
current_app.config["REMOTE_MEDIAS_URL"] + current_app.config["REMOTE_MEDIAS_PATH"] + image
)


@main.route(
"/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>", methods=["GET", "POST"]
)
@main.route("/" + current_app.config["REMOTE_MEDIAS_PATH"] + "<image>", methods=["GET", "POST"])
def indexMedias(image):
return redirect(
current_app.config["REMOTE_MEDIAS_URL"]
+ current_app.config["REMOTE_MEDIAS_PATH"]
+ image
current_app.config["REMOTE_MEDIAS_URL"] + current_app.config["REMOTE_MEDIAS_PATH"] + image
)


Expand Down Expand Up @@ -255,9 +235,7 @@ def ficheEspece(cd_nom):
synonyme = vmTaxrefRepository.getSynonymy(connection, cd_ref)
communes = vmCommunesRepository.getCommunesObservationsChilds(connection, cd_ref)
taxonomyHierarchy = vmTaxrefRepository.getAllTaxonomy(db_session, cd_ref)
firstPhoto = vmMedias.getFirstPhoto(
connection, cd_ref, current_app.config["ATTR_MAIN_PHOTO"]
)
firstPhoto = vmMedias.getFirstPhoto(connection, cd_ref, current_app.config["ATTR_MAIN_PHOTO"])
photoCarousel = vmMedias.getPhotoCarousel(
connection, cd_ref, current_app.config["ATTR_OTHER_PHOTO"]
)
Expand All @@ -271,10 +249,7 @@ def ficheEspece(cd_nom):
current_app.config["ATTR_VIMEO"],
)
articles = vmMedias.getLinks_and_articles(
connection,
cd_ref,
current_app.config["ATTR_LIEN"],
current_app.config["ATTR_PDF"],
connection, cd_ref, current_app.config["ATTR_LIEN"], current_app.config["ATTR_PDF"]
)
taxonDescription = vmCorTaxonAttribut.getAttributesTaxon(
connection,
Expand Down Expand Up @@ -409,9 +384,7 @@ def photos():

@main.route("/recherche", methods=["GET"])
def advanced_search():
return render_template(
"templates/core/advanced_search.html",
)
return render_template("templates/core/advanced_search.html")


@main.route("/<page>", methods=["GET", "POST"])
Expand All @@ -436,11 +409,7 @@ def sitemap():
url_root = url_root[:-1]
for rule in current_app.url_map.iter_rules():
# check for a 'GET' request and that the length of arguments is = 0 and if you have an admin area that the rule does not start with '/admin'
if (
"GET" in rule.methods
and len(rule.arguments) == 0
and not rule.rule.startswith("/api")
):
if "GET" in rule.methods and len(rule.arguments) == 0 and not rule.rule.startswith("/api"):
pages.append([url_root + rule.rule, ten_days_ago])

# get dynamic routes for blog
Expand All @@ -459,10 +428,7 @@ def sitemap():
pages.append([url, modified_time])

sitemap_template = render_template(
"templates/sitemap.xml",
pages=pages,
url_root=url_root,
last_modified=ten_days_ago,
"templates/sitemap.xml", pages=pages, url_root=url_root, last_modified=ten_days_ago
)
response = make_response(sitemap_template)
response.headers["Content-Type"] = "application/xml"
Expand Down
4 changes: 1 addition & 3 deletions atlas/configuration/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ def get_config_module(atlas_config_file_path):


def read_config_file(config_module):
return {
var: getattr(config_module, var) for var in remove_reserved_word(config_module)
}
return {var: getattr(config_module, var) for var in remove_reserved_word(config_module)}


def remove_reserved_word(config_module):
Expand Down
8 changes: 2 additions & 6 deletions atlas/configuration/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ class Meta:
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 @@ -218,7 +216,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"}
)
14 changes: 3 additions & 11 deletions atlas/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

babel = Babel()

cache = Cache(
config={
"CACHE_TYPE": "SimpleCache",
}
)
cache = Cache(config={"CACHE_TYPE": "SimpleCache"})

db = SQLAlchemy()

Expand All @@ -20,10 +16,6 @@
default_atlas_template_folder = Path(__file__).parent


atlas_config_file_path = os.environ.get(
"ATLAS_SETTINGS", default_atlas_config_file_path
)
atlas_config_file_path = os.environ.get("ATLAS_SETTINGS", default_atlas_config_file_path)
atlas_static_folder = os.environ.get("ATLAS_STATIC_FOLDER", default_atlas_static_folder)
atlas_template_folder = os.environ.get(
"ATLAS_TEMPLATE_FOLDER", default_atlas_template_folder
)
atlas_template_folder = os.environ.get("ATLAS_TEMPLATE_FOLDER", default_atlas_template_folder)
4 changes: 2 additions & 2 deletions atlas/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ msgstr ""
msgid "loading"
msgstr ""

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

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

Expand Down
6 changes: 1 addition & 5 deletions atlas/modeles/entities/tGrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
# -*- coding: utf-8 -*-

from geoalchemy2.types import Geometry
from sqlalchemy import (
Column,
Integer,
Text,
)
from sqlalchemy import Column, Integer, Text
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
Expand Down
4 changes: 1 addition & 3 deletions atlas/modeles/entities/vmAreas.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,5 @@ class VmCorAreaObservation(Base):
primary_key=False,
)
__mapper_args__ = {"primary_key": [__table__.c.id_observation, __table__.c.id_area]}
observation = relationship(
"VmObservations", foreign_keys=[__table__.c.id_observation]
)
observation = relationship("VmObservations", foreign_keys=[__table__.c.id_observation])
area = relationship("VmAreas", foreign_keys=[__table__.c.id_area])
Loading

0 comments on commit deb37ae

Please sign in to comment.