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

wrong query to generate the species list #86

Merged
merged 1 commit into from
Mar 25, 2019
Merged
Changes from all commits
Commits
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
45 changes: 28 additions & 17 deletions backend/gncitizen/core/taxonomy/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
from gncitizen.utils.env import db
from gncitizen.utils.sqlalchemy import json_resp
from gncitizen.core.taxonomy.models import (
BibNoms, BibListes, CorNomListe, TMedias, Taxref)
BibNoms,
BibListes,
CorNomListe,
TMedias,
Taxref,
)

routes = Blueprint('taxonomy', __name__)
routes = Blueprint("taxonomy", __name__)


@routes.route('/taxonomy/lists', methods=['GET'])
@routes.route("/taxonomy/lists", methods=["GET"])
@json_resp
def get_lists():
"""Renvoie toutes liste d'espèces
Expand Down Expand Up @@ -48,10 +53,10 @@ def get_lists():
# current_app.logger.debug([l.as_dict() for l in data])
return [l.as_dict() for l in data]
except Exception as e:
return {'error_message': str(e)}, 400
return {"error_message": str(e)}, 400


@routes.route('/taxonomy/lists/<int:id>/species', methods=['GET'])
@routes.route("/taxonomy/lists/<int:id>/species", methods=["GET"])
@json_resp
def get_list(id):
"""Renvoie une liste d'espèces spécifiée par son id
Expand Down Expand Up @@ -86,22 +91,27 @@ def get_list(id):
# else:
# return jsonify('Erreur de chargement de l \'API', r.status_code)
try:
data = db.session.query(BibNoms, Taxref, TMedias)\
.distinct(BibNoms.cd_ref)\
.join(CorNomListe, CorNomListe.id_liste == id)\
.join(Taxref, Taxref.cd_ref == BibNoms.cd_ref)\
.outerjoin(TMedias, TMedias.cd_ref == BibNoms.cd_ref)\
.all()
data = (
db.session.query(BibNoms, Taxref, TMedias)
.distinct(BibNoms.cd_ref)
.join(CorNomListe, CorNomListe.id_nom == BibNoms.id_nom)
.join(Taxref, Taxref.cd_ref == BibNoms.cd_ref)
.outerjoin(TMedias, TMedias.cd_ref == BibNoms.cd_ref)
.filter(CorNomListe.id_liste == id)
.all()
)
# current_app.logger.debug(
# [{'nom': d[0], 'taxref': d[1]} for d in data])
return [
{
'nom': d[0].as_dict(),
'taxref': d[1].as_dict(),
'medias': d[2].as_dict() if d[2] else None
} for d in data]
"nom": d[0].as_dict(),
"taxref": d[1].as_dict(),
"medias": d[2].as_dict() if d[2] else None,
}
for d in data
]
except Exception as e:
return {'error_message': str(e)}, 400
return {"error_message": str(e)}, 400


# @routes.route('/taxonomy/lists/full', methods=['GET'])
Expand Down Expand Up @@ -175,7 +185,8 @@ def get_list(id):
# except:
# return jsonify('Erreur de chargement de l \'API', rtaxa.status_code)

@routes.route('/taxonomy/taxon/<int:cd_nom>', methods=['GET'])

@routes.route("/taxonomy/taxon/<int:cd_nom>", methods=["GET"])
@json_resp
def get_taxon_from_cd_nom(cd_nom):
"""Get taxon TaxRef data from cd_nom
Expand Down