Skip to content

Commit

Permalink
Merge + ergo
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed Aug 5, 2020
2 parents e93d6f3 + 1a1217a commit b3461e8
Show file tree
Hide file tree
Showing 244 changed files with 12,660 additions and 5,213 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,13 @@ ENV/
.mypy_cache/

*.pid
package-lock.json
*.orig


install_all/install_all.log

# Pycharm
.idea/

backend/static/images/taxa.png
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ Modules et projets liés
* GeoNature module Import : https://github.com/PnX-SI/gn_module_import
* GeoNature module Dashboard : https://github.com/PnX-SI/gn_module_dashboard
* GeoNature module Validation : https://github.com/PnX-SI/gn_module_validation
* GeoNature module Flore prioritaire : https://github.com/PnX-SI/gn_module_flore_prioritaire
* GeoNature module Suivi des habitats : https://github.com/PnX-SI/gn_module_suivi_habitat_territoire
* GeoNature module Suivi des stations d'habitat : https://github.com/PnX-SI/gn_module_suivi_habitat_station
* GeoNature module Suivi de la flore territoire : https://github.com/PnX-SI/gn_module_suivi_flore_territoire
* API Flask d'interrogation du référentiel Habref : https://github.com/PnX-SI/Habref-api-module
* Suivi-Flore-Territoire-mobile : https://github.com/PnX-SI/gn_mobile_sft
* API Flask d'interrogation du référentiel Habref : https://github.com/PnX-SI/Habref-api-module
* GeoNature module générique de suivis : https://github.com/PnX-SI/gn_module_monitoring
* GeoNature module Suivi chiroptères : https://github.com/PnCevennes/gn_module_suivi_chiro
* Protocoles de suivi (frontend) : https://github.com/PnCevennes/projet_suivis_frontend
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.2
2.4.2.dev0
47 changes: 0 additions & 47 deletions backend/Pipfile

This file was deleted.

2 changes: 2 additions & 0 deletions backend/geonature/core/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def loginCas():
"nom_role": info_user["nom"],
"prenom_role": info_user["prenom"],
"id_organisme": organism_id,
"email": info_user["email"],
"active": True,
}
try:
resp = users.insert_role(user)
Expand Down
26 changes: 23 additions & 3 deletions backend/geonature/core/command/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
import os
import sys
from pathlib import Path

from geonature.core.command.main import main
import geonature.core.command.create_gn_module


# Load modules commands
from geonature.utils.env import ROOT_DIR


def import_cmd(dirname):
try:
print("Import module {}".format(dirname))

module_cms = __import__(
"{}.backend.commands.geonature_cmd".format(dirname)
)

print(" ... Module imported".format(dirname))
except FileNotFoundError as e:
# Si l'erreur est liée à un fichier inexistant
# création du fichier et réimport de la commande
print(" ... FileNotFoundError", e.filename)
Path(os.path.dirname(e.filename)).mkdir(
parents=True, exist_ok=True
)
import_cmd(dirname)

plugin_folder = os.path.join(str(ROOT_DIR), 'external_modules')
sys.path.insert(0, os.path.join(plugin_folder))

Expand All @@ -20,6 +41,5 @@
)

if (os.path.isfile(cmd_file)):
module_cms = __import__(
"{}.backend.commands.geonature_cmd".format(dirname)
)
import_cmd(dirname)

11 changes: 0 additions & 11 deletions backend/geonature/core/command/create_gn_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,3 @@ def update_module_configuration(module_code, build, prod):
create_module_config(app, module_code.lower(), build=build)


@main.command()
@click.argument('module_path')
def test(module_path):
import json
with open(module_path) as f:
package_json = json.load(f)
dependencies = package_json['dependencies']
print(dependencies)
for lib, version in dependencies.items():
print(lib)
print(version)
8 changes: 4 additions & 4 deletions backend/geonature/core/gn_commons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ class TMedias(DB.Model):
# ForeignKey('ref_nomenclatures.t_nomenclatures.id_nomenclature')
)
id_table_location = DB.Column(
DB.Integer, ForeignKey(
"gn_commons.bib_tables_location.id_table_location")
DB.Integer, ForeignKey("gn_commons.bib_tables_location.id_table_location")
)
unique_id_media = DB.Column(
UUID(as_uuid=True), default=select([func.uuid_generate_v4()])
Expand Down Expand Up @@ -129,8 +128,7 @@ class TValidations(DB.Model):
validation_auto = DB.Column(DB.Boolean)
validation_label = DB.relationship(
TNomenclatures,
primaryjoin=(TNomenclatures.id_nomenclature ==
id_nomenclature_valid_status),
primaryjoin=(TNomenclatures.id_nomenclature == id_nomenclature_valid_status),
foreign_keys=[id_nomenclature_valid_status],
)
validator_role = DB.relationship(
Expand Down Expand Up @@ -188,3 +186,5 @@ class TMobileApps(DB.Model):
app_code = DB.Column(DB.Unicode)
relative_path_apk = DB.Column(DB.Unicode)
url_apk = DB.Column(DB.Unicode)
package = DB.Column(DB.Unicode)
version_code = DB.Column(DB.Unicode)
3 changes: 2 additions & 1 deletion backend/geonature/core/gn_commons/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ def create_or_update_media(self):
self.data['isFile'] = True
self.media_data['media_path'] = self.upload_file()
self.media_data['media_url'] = None
elif self.data['media_path'] != '':
elif self.data.get('media_path') not in ['', None]:
self.data['isFile'] = True
self.media_data['media_url'] = None
else:
self.data['isFile'] = False
self.media_data['media_path'] = None
self.media_data['media_url'] = self.data['media_url']

# Si le média avait un fichier associé
# et qu'il a été remplacé par une url
Expand Down
64 changes: 55 additions & 9 deletions backend/geonature/core/gn_commons/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
Route permettant de manipuler les fichiers
contenus dans gn_media
"""
import json

from flask import Blueprint, request, current_app
import requests

from geonature.core.gn_commons.repositories import TMediaRepository
from geonature.core.gn_commons.models import TModules, TParameters, TMobileApps
from geonature.utils.env import DB
from geonature.utils.env import DB, BACKEND_DIR
from geonature.utils.errors import GeonatureApiError
from utils_flask_sqla.response import json_resp
from geonature.core.gn_permissions import decorators as permissions
from geonature.core.gn_permissions.tools import cruved_scope_for_user_in_module
Expand Down Expand Up @@ -50,8 +53,7 @@ def get_modules(info_role):
@routes.route("/module/<module_code>", methods=["GET"])
@json_resp
def get_module(module_code):
module = DB.session.query(TModules).filter_by(
module_code=module_code).one()
module = DB.session.query(TModules).filter_by(module_code=module_code).one()
return module.as_dict()


Expand Down Expand Up @@ -87,10 +89,15 @@ def insert_or_update_media(id_media=None):
formData = dict(request.form)
for key in formData:
data[key] = formData[key]
if data[key] == 'true':
if isinstance(data[key], list):
data[key] = data[key][0]
if key in ['id_table_location', 'id_nomenclature_media_type', 'id_media']:
data[key] = int(data[key])
if data[key] == "true":
data[key] = True
if data[key] == 'false':
if data[key] == "false":
data[key] = False

else:
data = request.get_json(silent=True)

Expand Down Expand Up @@ -155,7 +162,46 @@ def get_t_mobile_apps():
"""
params = request.args
q = DB.session.query(TMobileApps)
if 'app_code' in request.args:
q = q.filter(TMobileApps.app_code == params['app_code'])

return [d.as_dict() for d in q.all()]
if "app_code" in request.args:
q = q.filter(TMobileApps.app_code.ilike(params["app_code"]))
mobile_apps = []
for d in q.all():
one_app = d.as_dict()
one_app["settings"] = {}
#  if local
if one_app["url_apk"] is None or len(one_app["url_apk"]) == 0:
try:
url_apk = "{}/{}".format(
current_app.config["API_ENDPOINT"], one_app["relative_path_apk"]
)
one_app["url_apk"] = url_apk
dir_app = "/".join(
str(BACKEND_DIR / one_app["relative_path_apk"]).split("/")[:-1]
)
settings_file = "{}/settings.json".format(dir_app)
with open(settings_file) as f:
one_app["settings"] = json.load(f)
except Exception as e:
raise e

else:
#  get config
dir_app = "/".join(one_app["url_apk"].split("/")[:-1])
settings_path = "{}/settings.json".format(dir_app)
resp = requests.get(
"https://docs.google.com/uc?export=download&id=1hIvdYeBd9NinV7CNcFjWXnBPpImKmYf3"
)
try:
assert resp.status_code == 200
except AssertionError:
raise GeonatureApiError(
"Impossible to get the settings file at {}".format(settings_path)
)
one_app["settings"] = json.loads(resp.content)
one_app.pop("relative_path_apk")
mobile_apps.append(one_app)

# mobile_apps.append(app)
if len(mobile_apps) == 1:
return mobile_apps[0]
return mobile_apps
Loading

0 comments on commit b3461e8

Please sign in to comment.